GHSA-H857-2G56-468G
Vulnerability from github – Published: 2023-01-05 12:18 – Updated: 2023-01-05 12:18
VLAI
Summary
@mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS)
Details
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
Severity
7.6 (High)
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 0.3.1"
},
"package": {
"ecosystem": "npm",
"name": "@mattkrick/sanitize-svg"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "0.4.0"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2023-22461"
],
"database_specific": {
"cwe_ids": [
"CWE-79"
],
"github_reviewed": true,
"github_reviewed_at": "2023-01-05T12:18:35Z",
"nvd_published_at": "2023-01-04T15:15:00Z",
"severity": "HIGH"
},
"details": "### Impact\nThe *sanitize-svg* package uses a deny-list-pattern to sanitize SVGs to prevent cross-site scripting (XSS). In doing so, literal `\u003cscript\u003e`-tags and on-event handlers were detected:\n```typescript\n[...]\n const svgEl = div.firstElementChild!\n const attributes = Array.from(svgEl.attributes).map(({ name }) =\u003e name)\n const hasScriptAttr = !!attributes.find((attr) =\u003e attr.startsWith(\u0027on\u0027))\n const scripts = svgEl.getElementsByTagName(\u0027script\u0027)\n return scripts.length === 0 \u0026\u0026 !hasScriptAttr ? svg : null\n[...]\n```\n\nThere are more ways to embed JavaScript in XML files.\n\n**Anchor Tag** (requires user to click link):\n```xml\n\u003csvg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\"\u003e\n \u003ca href=\"javascript:alert(document.domain)\"\u003e\n \u003ctext x=\"50\" y=\"50\" text-anchor=\"middle\"\u003eLauritz\u003c/text\u003e\n \u003c/a\u003e\n\u003c/svg\u003e\n```\n\n**Foreign Object Tag** (no user interaction required):\n```xml\n\u003csvg width=\"500\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\n \u003ctext x=\"20\" y=\"35\"\u003eLauritz\u003c/text\u003e\n \u003cforeignObject width=\"500\" height=\"500\"\u003e\n \u003ciframe xmlns=\"http://www.w3.org/1999/xhtml\" src=\"javascript:confirm(document.domain);\" width=\"400\" height=\"250\"/\u003e\n \u003c/foreignObject\u003e\n\u003c/svg\u003e\n```\n\nAs 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. \n\n### Patches\nThis vulnerability was addressed in v0.4.0.\n\n### Workarounds\nN/A",
"id": "GHSA-h857-2g56-468g",
"modified": "2023-01-05T12:18:35Z",
"published": "2023-01-05T12:18:35Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/mattkrick/sanitize-svg/security/advisories/GHSA-h857-2g56-468g"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2023-22461"
},
{
"type": "WEB",
"url": "https://github.com/mattkrick/sanitize-svg/commit/b107e453ede7b58adcccae74a3e474c012eec85d"
},
{
"type": "PACKAGE",
"url": "https://github.com/mattkrick/sanitize-svg"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N",
"type": "CVSS_V3"
}
],
"summary": "@mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS)"
}
Loading…
Loading…
Experimental. This forecast is provided for visualization only and may change without notice. Do not use it for operational decisions.
Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Loading…
Loading…