-
Notifications
You must be signed in to change notification settings - Fork 10
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 #4371 from serlo/xss-link-href
fix(link-renderer): add guard against injecting javascript in link elements through href
- Loading branch information
Showing
28 changed files
with
235 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.83 KB
.yarn/cache/html-encoding-sniffer-npm-4.0.0-5f6627070d-3339b71dab.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+4.01 KB
.yarn/cache/isomorphic-dompurify-npm-2.19.0-4f6eb49402-42fb8a4d5e.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import DOMPurify from 'isomorphic-dompurify' | ||
|
||
export function sanitizeHref(href: string) { | ||
// Users can add links to content in the editor. So, href can be manipulated by the user and could potentially be abused to inject malicious javascript. We use DOMPurify to validate the href. | ||
// Examples: | ||
// - 'javascript:doSomethingBad()' -> invalid | ||
// - 'https://example.com/' -> valid | ||
const isHrefValid = DOMPurify.isValidAttribute('a', 'href', href) | ||
|
||
return isHrefValid ? href : '' | ||
} |
Oops, something went wrong.