{"id":"GHSA-h857-2g56-468g","summary":"@mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS)","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('on'))\n  const scripts = svgEl.getElementsByTagName('script')\n  return scripts.length === 0 && !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","aliases":["CVE-2023-22461"],"modified":"2023-11-08T04:11:35.614154Z","published":"2023-01-05T12:18:35Z","database_specific":{"github_reviewed_at":"2023-01-05T12:18:35Z","nvd_published_at":"2023-01-04T15:15:00Z","cwe_ids":["CWE-79"],"severity":"HIGH","github_reviewed":true},"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"}],"affected":[{"package":{"name":"@mattkrick/sanitize-svg","ecosystem":"npm","purl":"pkg:npm/%40mattkrick/sanitize-svg"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"0.4.0"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2023/01/GHSA-h857-2g56-468g/GHSA-h857-2g56-468g.json","last_known_affected_version_range":"\u003c= 0.3.1"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N"}]}