Lucene search

K
githubGitHub Advisory DatabaseGHSA-H857-2G56-468G
HistoryJan 05, 2023 - 12:18 p.m.

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

2023-01-0512:18:35
CWE-79
GitHub Advisory Database
github.com
42
sanitize-svg
cross-site scripting
svg
security implications
vulnerability
deny-list-pattern
xss
downstream software
patches

7.6 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

LOW

User Interaction

REQUIRED

Scope

CHANGED

Confidentiality Impact

HIGH

Integrity Impact

LOW

Availability Impact

NONE

CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N

0.001 Low

EPSS

Percentile

29.0%

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>
    &lt;text x="50" y="50" text-anchor="middle"&gt;Lauritz&lt;/text&gt;
  </a>
&lt;/svg&gt;

Foreign Object Tag (no user interaction required):

&lt;svg width="500" height="500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
        &lt;text x="20" y="35"&gt;Lauritz&lt;/text&gt;
        &lt;foreignObject width="500" height="500"&gt;
                &lt;iframe xmlns="http://www.w3.org/1999/xhtml" src="javascript:confirm(document.domain);" width="400" height="250"/&gt;
        &lt;/foreignObject&gt;
&lt;/svg&gt;

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

Affected configurations

Vulners
Node
mattkricksanitize-svgRange0.3.1
CPENameOperatorVersion
@mattkrick/sanitize-svgle0.3.1

7.6 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

LOW

User Interaction

REQUIRED

Scope

CHANGED

Confidentiality Impact

HIGH

Integrity Impact

LOW

Availability Impact

NONE

CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N

0.001 Low

EPSS

Percentile

29.0%

Related for GHSA-H857-2G56-468G