Fixed an XSS vulnerability when setting SVG icon #7492
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.