-
-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sanitizing localization files #1354
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @berhalak!
|
||
function purify(inputString) { | ||
// This removes any html tags from the string | ||
return DOMPurify.sanitize(inputString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that DOMPurify.sanitize
in fact removes all html tags from a string? Examples at https://github.com/cure53/DOMPurify?tab=readme-ov-file#some-purification-samples-please contract that, e.g.:
DOMPurify.sanitize('<img src=x onerror=alert(1)//>'); // becomes <img src="x">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@berhalak, I'm wondering if it's better to revert this change.
This PR care of the XSS attack vector discussed here, but I think style
elements can still be injected (if strings are not escaped). Furthermore, I don't think we explicitly set innerHTML
to a translation string anywhere in our code, do we? Sanitizing here certainly doesn't hurt, but I don't think it fully replaces the need to escape HTML, and it seems like that's all that #1247 needs.
Context
Sanitizing localization files.
Proposed solution
Added a script that is executed during build time that will sanitize every key in every translations resource file.
Related issues
#1350
Has this been tested?
Tested manually.