Vulnerabilities in pkg:npm/@mattkrick/sanitize-svg
PACKAGECVE-2023-22461 is a HIGH (CVSS 7.6) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting @mattkrick/sanitize svg libraries in the npm ecosystem. The issue involves @mattkrick/sanitize-svg vulnerable to cross-site scripting (xss). Remediation is available by upgrading affected packages to version 0.4.0.
pkg:npm/@mattkrick/sanitize-svg
Vulnerability advisories affecting package pkg:npm/@mattkrick/sanitize-svg. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-h857-2g56-468g | CVE-2023-22461 | HIGH | @mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS) |
CVE-2023-22461 at a Glance
Security Impact
CVSS: 7.6
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N).
How to Fix CVE-2023-22461
To remediate this vulnerability, upgrade all affected @mattkrick/sanitize svg dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install @mattkrick/sanitize-svg@0.4.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls @mattkrick/sanitize-svg
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2023-22461, inspect your project dependencies using npm:
npm ls @mattkrick/sanitize-svg
Analyze the terminal output to locate any version of @mattkrick/sanitize svg in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.4.0), your application is affected.
Note: The npm ls @mattkrick/sanitize-svg command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In @mattkrick/sanitize svg, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2023-22461 Affected @mattkrick/sanitize svg Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
@mattkrick/sanitize-svg
|
npm |
< 0.4.0
|
0.4.0
|
References
Frequently Asked Questions
What is CVE-2023-22461?
Which @mattkrick/sanitize svg versions are affected?
What version fixes CVE-2023-22461?
Is @mattkrick/sanitize-svg affected?
What is the CVSS score of CVE-2023-22461?
What CWE is associated with CVE-2023-22461?
How can I check npm dependencies for CVE-2023-22461?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-h857-2g56-468g",
"modified" : "2023-01-05T12:18:35Z",
"published" : "2023-01-05T12:18:35Z",
"aliases" : [ "CVE-2023-22461" ],
"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 `<script>`-tags and on-event handlers were detected:\n```typescript\n[...]\n const svgEl = div.firstElementChild!\n const attributes = Array.from(svgEl.attributes).map(({ name }) => name)\n const hasScriptAttr = !!attributes.find((attr) => 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<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">\n <a href=\"javascript:alert(document.domain)\">\n <text x=\"50\" y=\"50\" text-anchor=\"middle\">Lauritz</text>\n </a>\n</svg>\n```\n\n**Foreign Object Tag** (no user interaction required):\n```xml\n<svg width=\"500\" height=\"500\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <text x=\"20\" y=\"35\">Lauritz</text>\n <foreignObject width=\"500\" height=\"500\">\n <iframe xmlns=\"http://www.w3.org/1999/xhtml\" src=\"javascript:confirm(document.domain);\" width=\"400\" height=\"250\"/>\n </foreignObject>\n</svg>\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",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "@mattkrick/sanitize-svg"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.4.0"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 0.3.1"
}
} ],
"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"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-79" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2023-01-05T12:18:35Z",
"nvd_published_at" : "2023-01-04T15:15:00Z"
}
}