Skip to content
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

fix: use setAttribute instead of innerHTML to prevent XSS #3548

Merged

Conversation

EastSun5566
Copy link
Contributor

Fixed #3546

Hi @hakimel

Following our previous discussion, I have made changes to use setAttribute instead of innerHTML to prevent XSS vulnerabilities.

I have created two small demos for you to try. The first demonstrates an XSS issue caused by using innerHTML:

https://jsfiddle.net/EastSun5566/9cfxeLzv/14/

The second uses setAttribute for attribute assignment:

https://jsfiddle.net/EastSun5566/rbogezv1/8/

You will notice that in the first case, an alert is triggered, while in the second, it is not. Although I believe URLs should be sanitized before setting attributes, I think this solution is good enough now.

Please let me know your thoughts. Thank you!

@hakimel hakimel merged commit 767a67e into hakimel:master Dec 15, 2023
@hakimel
Copy link
Owner

hakimel commented Dec 15, 2023

Tested and seems to be working well, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential XSS vulnerability with data-background-video attribute
2 participants