Vulnerabilities in pkg:npm/@mattkrick/sanitize-svg

PACKAGE
Advisory Identifier: GHSA-h857-2g56-468g
Advisory Summary

CVE-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.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/@mattkrick/sanitize-svg

1 Known Advisory Record(s)

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

CVE Identifier CVE-2023-22461
GHSA Identifier GHSA-h857-2g56-468g
Severity HIGH
CVSS v3.1 Base Score 7.6
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product @mattkrick/sanitize svg
Package Ecosystem npm
Published Date
Last Updated

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).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity Low (I:L)
Availability None (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.

@mattkrick/sanitize-svg fixed: 0.4.0
npm install @mattkrick/sanitize-svg@0.4.0
Verify Direct and Transitive Dependencies

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

### 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: ```typescript [...] 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): ```xml <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): ```xml <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

CVE-2023-22461 Affected @mattkrick/sanitize svg Versions

1 component(s)
Fixed Versions:
0.4.0
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?
CVE-2023-22461 is a security vulnerability in @mattkrick/sanitize svg involving @mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS) under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which @mattkrick/sanitize svg versions are affected?
Affected versions include releases prior to 0.4.0 across affected packages: @mattkrick/sanitize-svg.
What version fixes CVE-2023-22461?
Upgrading to 0.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @mattkrick/sanitize-svg affected?
Yes, @mattkrick/sanitize-svg is affected in releases prior to 0.4.0. Upgrade your dependency to 0.4.0 or later.
What is the CVSS score of CVE-2023-22461?
CVE-2023-22461 has a CVSS v3.1 base score of 7.6 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N.
What CWE is associated with CVE-2023-22461?
CVE-2023-22461 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (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.).
How can I check npm dependencies for CVE-2023-22461?
Run the dependency tree command: 'npm ls @mattkrick/sanitize-svg'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}