-
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.
fix(link-renderer): use
sanitizeHref
whenever a text plugin link is…
… rendered
- Loading branch information
1 parent
12dfa2d
commit cd92a8c
Showing
4 changed files
with
17 additions
and
15 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
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 '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 : '' | ||
} |