Packages / svgo / Security

ModerateVulnerabilityGHSA-4vpr-x523-8j87CVE-2026-84369Published 8 Sep 2026

SVGO: removeScripts incompletely sanitizes executable HTML in SVG foreignObject elements

Your version

Affected releases · svgo

  • 4.x4.0.0 – 4.0.2Fixed in 4.1.0
  • 3.x3.0.0 – 3.3.4Fixed in 3.3.5
  • 2.x2.0.0 – 2.8.3Fixed in 2.8.4
  • 1.x1.0.0 – 1.3.2No fix on this line yet

On 4.x, the newest line:

npm install svgo@4.1.0
Every release on a timeline
4.x
  1. Affected

    4.0.0 – 4.0.2

    3 releases

  2. Fixed

    4.1.0

    1 release, latest

3.x
  1. Affected

    3.0.0 – 3.3.4

    13 releases

  2. Fixed

    3.3.5

    1 release

2.x
  1. Affected

    2.0.0 – 2.8.3

    19 releases

  2. Fixed

    2.8.4

    1 release

1.x
  1. Affected

    1.0.0 – 1.3.2

    14 releases

107 stable releases of svgo, oldest to newest, one row per major.

What happens

Summary

SVGO's opt-in removeScripts plugin did not inspect executable HTML content inside SVG <foreignObject> elements. Applications that used this plugin as their only protection for untrusted SVG input could produce SVGs containing active HTML and expose users to cross-site scripting (XSS).

SVGO is an optimizer rather than a comprehensive sanitization library, but removeScripts is maintained for consumers that already rely on it to remove common script execution paths.

Details

Although the plugin removed SVG and XHTML <script> elements, it left other HTML execution paths inside <foreignObject> unchanged. These included:

  • event-handler attributes such as onload and onbeforetoggle;

  • srcdoc documents, including on <iframe> elements;

  • executable URLs in HTML attributes such as action, data, formaction, href, and src.

An attacker could place one of these payloads in an SVG. If an application optimized the untrusted SVG with removeScripts and then served the result in an active browser context, the payload could execute in the viewer's origin.

Impact

Successful exploitation could allow script execution in the context where the optimized SVG is rendered. Depending on the embedding and origin configuration, this could expose cookies or local storage, modify content, or perform actions as the victim.

The plugin is opt-in, so consumers that do not enable removeScripts are not relying on the affected behavior. Typical local optimization of trusted SVG files is not affected.

Patches

Upgrade to one of the following releases for the maintained release line in use:

Release linePatched versionPlugin
v22.8.4removeScriptElement
v33.3.5removeScriptElement
v44.1.0removeScripts

The fix preserves visual HTML inside SVG <foreignObject> elements while removing event attributes, srcdoc, and executable URL values from active HTML URL attributes.

SVGO v1 is no longer maintained. Users of v1 should upgrade to a supported release line.

Workarounds

For hostile input, use a dedicated SVG sanitization tool before passing the SVG to SVGO. As defense in depth, applications can reject or remove <foreignObject> content and avoid serving user-controlled SVGs in an active same-origin context.

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.