Summary
SVGO's script-removal plugin can leave executable script content in optimized SVG files when script elements use namespaces or prefixes, and in some releases when JavaScript URIs use unexpected capitalization. If an application optimizes untrusted SVGs and serves the output, a victim who opens a crafted file may execute attacker-controlled script in the relevant browser context.
Affected context
The issue occurs in applications or processing pipelines that use SVGO's script-removal functionality to sanitize untrusted SVG input and then make the optimized result available to users. Risk is higher when the resulting SVG is served with an active content type, opened in a browser, or hosted within a security context that exposes application data such as cookies or local storage.
Exploit preconditions
- Attack surface: SVG upload, transformation, storage, or content-serving functionality
- Required access: Ability to submit or influence an SVG that is processed by SVGO
- Trigger point: A user opens or renders the optimized SVG in a browser
- Why exploitation is possible: The sanitizer may fail to recognize namespaced, prefixed, or case-variant executable content, allowing script-bearing markup or JavaScript URIs to survive optimization
Why this happens
The underlying bug is incomplete removal of executable SVG content. The filtering logic recognizes only a subset of equivalent element and URI representations, such as unprefixed script elements or case-specific JavaScript URI forms, rather than applying canonicalization and comprehensive validation before output.
This maps primarily to CWE-79: Improper Neutralization of Input During Web Page Generation, because attacker-controlled SVG content can be interpreted as script by a browser. It also relates to CWE-184: Incomplete List of Disallowed Inputs, since the sanitizer's removal rules do not cover all relevant representations of executable content.
Potential impact
- A victim's browser may execute attacker-controlled JavaScript
- Attackers may access data exposed to the SVG's execution context
- Session information, local storage, or cookies may be exposed where browser policies permit
- An attacker could alter the displayed SVG or perform actions using the victim's application context
- The vulnerability could enable phishing or further client-side compromise through a trusted file-hosting domain
General mitigation guidance
Mitigation generally focuses on treating SVG as active content rather than relying on a narrow removal plugin as the sole security boundary.
Common defensive patterns include:
- Use a maintained, security-focused SVG sanitizer that canonicalizes namespaces, element names, attributes, and URI schemes before applying allowlists
- Prefer a strict allowlist of passive SVG elements and attributes, excluding scripts, event handlers, external references, and executable URI schemes
- Avoid serving untrusted SVG with a browser-executable content type when rendering is not required
- Store untrusted files on an isolated origin with no access to sensitive application cookies or local storage
- Apply defense-in-depth browser controls, including an appropriate Content Security Policy
- Validate the final serialized output after optimization rather than trusting only the input-stage checks
- Process uploaded content with least privilege and prevent unintended network or filesystem access
How teams detect issues like this
Organizations can identify this issue through:
- Static analysis and dependency review for SVG sanitization configurations and script-removal plugin usage
- Code review checks for incomplete SVG allowlists, case-sensitive URI comparisons, and assumptions that optimization guarantees safety
- Dynamic tests using namespaced and prefixed script elements, case variants of executable URI schemes, event attributes, and external references
- Repository or CI policies requiring approved sanitizers and preventing untrusted SVG from being served as active browser content
- Security monitoring for unexpected SVG uploads, browser execution from file-hosting origins, and suspicious script-like content in optimized output

