-
Notifications
You must be signed in to change notification settings - Fork 809
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
Fixed an XSS vulnerability when setting SVG icon #7492
base: master
Are you sure you want to change the base?
Conversation
@diwangs We will take a look and comeback. We don't want to add a new library into our package just to call a one function from it. Thank you, |
Hello @diwangs ! Thank you for the contribution!
But if you are a programmer and you have access to a code (can pass some code) that will be executed on a client machine, you can inject any malicious code you want? Please correct me if I'm wrong. |
Thank you for your response @tsv2013 ! In a threat model where the programmer is the attacker, you are correct. The programmer could devise a more straightforward way to attack the victim. However, I would argue that it is not the only threat model that could be applied since you could call
One alternative approach aside from this PR is just to make a clear warning in the docs and let the survey maker sanitize the SVG themselves. However, I think sanitizing it in this library is a better way to prevent it since it is the lowest common denominator. Let me know what you think |
As for the concern for unnecessarily adding library @andrewtelnov, one alternative approach is to build our own lightweight sanitizer (using something like regex) that only handles SVG. |
@diwangs My apologies for a delayed responce.
That's why I'd prefer not to add a new dependency and not to write addional code right now. In the future when we'll support a custom icon pack or allow users to load custom SVG icons your concern will definitely make sence. And we'll need to solve this probles somehow. |
I've discovered a stored XSS vulnerability in
src/svgbundle.ts
:Vulnerability Details:
Severity: [High/Critical – Stored XSS can have a significant impact. Adjust based on your assessment]
The function
SvgIconRegistry.registerIconFromSvg()
is used to register and replace icons within the SVG registry, such as the default checkbox icon. However, the user of the library might inject a malicious SVG into the site, which cause an attacker to be able to execute arbitrary script under the domain (XSS)Steps to Reproduce:
Let's say we have an SVG in this form:
Such SVG could be registered under the registry with this script:
When we display a checkbox in the survey, after the user clicks them, an alert would show up. suggesting that the script has been successfully executed.
Here's a screenshot example if we display the checkbox using the example in the Surveyjs documentation:
Suggested Fix:
Before an SVG got registered into the registry, it is best to sanitize them first, using a library such as
DOMPurify
to prevent script execution. I have implemented a simple patch to fix the vulnerability using this method.