7.6high
sanitize-svg Filter Bypass Allows Cross-Site Scripting (XSS)
- Severity
- 7.6high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.61% (higher than 50% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-h857-2g56-468g
Description
The `sanitize-svg` package, a small SVG sanitizer to prevent cross-site scripting attacks, uses a deny-list-pattern to sanitize SVGs to prevent XSS. In doing so, literal `<script>`-tags and on-event handlers were detected in versions prior to 0.4.0. As a result, downstream software that relies on `sanitize-svg` and expects resulting SVGs to be safe, may be vulnerable to cross-site scripting. This vulnerability was addressed in v0.4.0. There are no known workarounds
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| mattkrick sanitize-svg | < 0.4 | CVE List |
| @mattkrick/sanitize-svg (npm) | before 0.4.0 | GitHub Advisory Database |
| sanitize-svg_project sanitize-svg | before 0.4.0 | NVD |
All scores
| GitHub_M | 7.6high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N |
| GitHub | 7.6high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N |
| NVD | 6.1medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N |
Classification
What each source says
CVE List
The `sanitize-svg` package, a small SVG sanitizer to prevent cross-site scripting attacks, uses a deny-list-pattern to sanitize SVGs to prevent XSS. In doing so, literal `<script>`-tags and on-event handlers were detected in versions prior to 0.4.0. As a result, downstream software that relies on `sanitize-svg` and expects resulting SVGs to be safe, may be vulnerable to cross-site scripting. This vulnerability was addressed in v0.4.0. There are no known workarounds
GitHub Advisory Database
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
NVD (es)
El paquete `sanitize-svg`, un pequeño "sanitizador" de SVG para evitar ataques de cross-site scripting, utiliza un patrón de lista de denegación para desinfectar los SVG y evitar XSS. Al hacerlo, se detectaron etiquetas literales `
References
| https://github.com/mattkrick/sanitize-svg/security/advisories/GHSA-h857-2g56-468g | exploit, third-party-advisory, web | |
| https://github.com/mattkrick/sanitize-svg/commit/b107e453ede7b58adcccae74a3e474c012eec85d | patch, third-party-advisory, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2023-22461 | advisory | |
| https://github.com/mattkrick/sanitize-svg | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2023-22461 changed 2025-03-10 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-h857-2g56-468g changed 2023-11-08 | CC-BY-4.0 |
| NVD | CVE-2023-22461 changed 2026-06-17 | Public domain |