-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from bernhard-herzog/safe-links
Avoid rendering JavaScript URLs as clickable links
- Loading branch information
Showing
4 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!-- | ||
This file is Free Software under the MIT License | ||
without warranty, see README.md and LICENSES/MIT.txt for details. | ||
SPDX-License-Identifier: Apache-2.0 | ||
SPDX-FileCopyrightText: 2024 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de> | ||
Software-Engineering: 2024 Intevation GmbH <https://intevation.de> | ||
--> | ||
|
||
<!-- | ||
Component that renders a URL as a clickable if the URL is safe to click. | ||
Safe to click here means that it uses one of the following protocols: | ||
http, https | ||
Other URLs are renders a plain text. | ||
--> | ||
|
||
<script lang="ts"> | ||
export let url = undefined | ||
export let id = undefined | ||
export let target = undefined | ||
// Protocols that are considered safe for URLs that should be | ||
// clickable. | ||
const safeProtocols = ["https:", "http:"] | ||
let protocol = undefined | ||
if (URL.canParse(url)) { | ||
protocol = new URL(url).protocol | ||
} | ||
</script> | ||
|
||
{#if safeProtocols.includes(protocol)} | ||
<a id={id} target={target} href={url}>{url}</a> | ||
{:else} | ||
{url} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters