GHSA-h857-2g56-468g

Suggest an improvement
Source
https://github.com/advisories/GHSA-h857-2g56-468g
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2023/01/GHSA-h857-2g56-468g/GHSA-h857-2g56-468g.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-h857-2g56-468g
Aliases
Published
2023-01-05T12:18:35Z
Modified
2023-11-08T04:11:35Z
Severity
  • 7.6 (High) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:L/A:N CVSS Calculator
Summary
@mattkrick/sanitize-svg vulnerable to Cross-Site Scripting (XSS)
Details

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

Database specific
{
    "cwe_ids":  [
        "CWE-79"
    ],
    "github_reviewed":  true,
    "github_reviewed_at":  "2023-01-05T12:18:35Z",
    "nvd_published_at":  "2023-01-04T15:15:00Z",
    "severity":  "HIGH"
}
References

Affected packages

npm / @mattkrick/sanitize-svg

Package

Name
@mattkrick/sanitize-svg
View open source insights on deps.dev
Purl
pkg:npm/%40mattkrick/sanitize-svg

Affected ranges

Type
SEMVER
Events
Introduced
0 Unknown introduced version / All previous versions are affected
Fixed
0.4.0

Database specific

last_known_affected_version_range
"<= 0.3.1"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2023/01/GHSA-h857-2g56-468g/GHSA-h857-2g56-468g.json"