forked from mastodon/mastodon
-
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.
Add client-side sanitization of server-provided HTML
- Loading branch information
1 parent
3bf2a72
commit b5a07a2
Showing
8 changed files
with
101 additions
and
19 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
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,58 @@ | ||
import DOMPurify from 'dompurify'; | ||
|
||
const default_config = { | ||
ALLOWED_TAGS: [ | ||
'p', | ||
'br', | ||
'span', | ||
'a', | ||
'del', | ||
'pre', | ||
'blockquote', | ||
'code', | ||
'b', | ||
'strong', | ||
'u', | ||
'i', | ||
'em', | ||
'ul', | ||
'ol', | ||
'li', | ||
'img', | ||
], | ||
ALLOWED_ATTR: [ | ||
'src', | ||
'alt', | ||
'title', | ||
'draggable', | ||
'href', | ||
'rel', | ||
'class', | ||
'translate', | ||
'start', | ||
'reversed', | ||
'value', | ||
'target', | ||
], | ||
}; | ||
|
||
const oembed_config = { | ||
ALLOWED_TAGS: ['audio', 'embed', 'iframe', 'source', 'video'], | ||
ALLOWED_ATTR: [ | ||
'controls', | ||
'width', | ||
'height', | ||
'src', | ||
'type', | ||
'allowfullscreen', | ||
'frameborder', | ||
'scrolling', | ||
'loop', | ||
'sandbox', | ||
], | ||
}; | ||
|
||
export const sanitize = (src: string) => | ||
DOMPurify.sanitize(src, default_config); | ||
export const sanitize_oembed = (src: string) => | ||
DOMPurify.sanitize(src, oembed_config); |
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