Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS1oODU3LTJnNTYtNDY4Z84AAwwo
@mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS)
Impact
The sanitize-svg package uses a deny-list-pattern to sanitize SVGs to prevent cross-site scripting (XSS). In doing so, literal <script>
-tags and on-event handlers were detected:
[...]
const svgEl = div.firstElementChild!
const attributes = Array.from(svgEl.attributes).map(({ name }) => name)
const hasScriptAttr = !!attributes.find((attr) => attr.startsWith('on'))
const scripts = svgEl.getElementsByTagName('script')
return scripts.length === 0 && !hasScriptAttr ? svg : null
[...]
There are more ways to embed JavaScript in XML files.
Anchor Tag (requires user to click link):
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<a href="javascript:alert(document.domain)">
<text x="50" y="50" text-anchor="middle">Lauritz</text>
</a>
</svg>
Foreign Object Tag (no user interaction required):
<svg width="500" height="500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<text x="20" y="35">Lauritz</text>
<foreignObject width="500" height="500">
<iframe xmlns="http://www.w3.org/1999/xhtml" src="javascript:confirm(document.domain);" width="400" height="250"/>
</foreignObject>
</svg>
As a result, downstream software that relies on sanitize-svg
and expects resulting SVGs to be safe, may be vulnerable to XSS. We are aware of at least one downstream project for which this vulnerability had security implications.
Patches
This vulnerability was addressed in v0.4.0.
Workarounds
N/A
Permalink: https://github.com/advisories/GHSA-h857-2g56-468gJSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1oODU3LTJnNTYtNDY4Z84AAwwo
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: over 1 year ago
Updated: about 1 year ago
CVSS Score: 7.6
CVSS vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N
Identifiers: GHSA-h857-2g56-468g, CVE-2023-22461
References:
- https://github.com/mattkrick/sanitize-svg/security/advisories/GHSA-h857-2g56-468g
- https://nvd.nist.gov/vuln/detail/CVE-2023-22461
- https://github.com/mattkrick/sanitize-svg/commit/b107e453ede7b58adcccae74a3e474c012eec85d
- https://github.com/advisories/GHSA-h857-2g56-468g
Blast Radius: 8.9
Affected Packages
npm:@mattkrick/sanitize-svg
Dependent packages: 1Dependent repositories: 15
Downloads: 5,739 last month
Affected Version Ranges: <= 0.3.1
Fixed in: 0.4.0
All affected versions: 0.1.0, 0.2.0, 0.2.1, 0.3.0, 0.3.1
All unaffected versions: 0.4.0