-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🦺 [open-formulieren/security-issues#36] Sanitizing HTML in component …
…data Added a simplistic sanitize function that sanitizes component data when saving the component. This function removes most HTML content from the label, tooltip, description and placeholder component data. Only basic semantic tags (`a`, `b`, `em`, `i`, `string`, `u`) are allowed. Also the allowed attributes has been limited to `href` on `a` tags.
- Loading branch information
1 parent
8df0566
commit 5ca577a
Showing
4 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,35 @@ | ||
import DOMPurify from 'dompurify'; | ||
|
||
const ALLOWED_HTML_TAGS = [ | ||
// Basic text tags | ||
'a', | ||
'b', | ||
'br', | ||
'em', | ||
'h1', | ||
'h2', | ||
'h3', | ||
'h4', | ||
'h5', | ||
'h6', | ||
'i', | ||
'p', | ||
's', | ||
'strong', | ||
'sup', | ||
'u', | ||
// Lists | ||
'li', | ||
'ol', | ||
'ul', | ||
]; | ||
|
||
const ALLOWED_HTML_ATTRIBUTES = ['href', 'target', 'rel']; | ||
|
||
export const sanitizeHTML = data => { | ||
return DOMPurify.sanitize(data, { | ||
ALLOWED_TAGS: ALLOWED_HTML_TAGS, | ||
ALLOWED_ATTR: ALLOWED_HTML_ATTRIBUTES, | ||
ALLOW_DATA_ATTR: true, | ||
}); | ||
}; |