CVE-2025-52561 Overview
CVE-2025-52561 is a cross-site scripting (XSS) vulnerability in HTMLSanitizer.jl, a whitelist-based HTML sanitizer for the Julia programming language. Versions prior to 0.2.1 incorrectly unescape content inside style tags when the tag is included in the whitelist. Closing tags injected as style content are then interpreted as real HTML, enabling tag injection and JavaScript execution. Any application that sanitizes untrusted HTML with this library may be exposed to XSS. The maintainers released a fix in version 0.2.1 [CWE-79].
Critical Impact
Attackers can inject arbitrary HTML and execute JavaScript in the browsers of users viewing content sanitized by vulnerable HTMLSanitizer.jl instances.
Affected Products
- HTMLSanitizer.jl versions prior to 0.2.1
- Julia applications embedding HTMLSanitizer.jl for user-supplied HTML
- Web services rendering sanitized HTML that includes style elements
Discovery Timeline
- 2025-06-23 - CVE-2025-52561 published to NVD
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2025-52561
Vulnerability Analysis
HTMLSanitizer.jl enforces an allow-list of tags and attributes, then escapes text content that survives filtering. When the style tag is added to the whitelist, the sanitizer treats its children as CDATA-like content and skips proper escaping. An attacker can place literal HTML inside the style element, including closing sequences that break out of the style context. Browsers subsequently parse the injected markup as active HTML, allowing script execution via elements such as <img onerror> or inline event handlers.
Root Cause
The root cause is inconsistent handling of raw-text elements. The sanitizer accepts style into the whitelist but neither strips its contents nor re-escapes reserved characters. Content inside <style> should be treated as opaque and either removed or fully encoded. Because the library did not remove children of math and svg either, similar mXSS (mutation XSS) patterns using foreign-content parsing rules were reachable.
Attack Vector
Exploitation requires an attacker to submit HTML that a downstream application sanitizes and then renders in a browser. No authentication, user interaction, or privileges are required on the sanitizer itself. The attacker supplies markup such as a style element containing a crafted closing tag followed by an image element with an onerror handler. When the victim loads the resulting page, the browser executes the injected JavaScript in the site's origin.
The upstream patch (0c3dc359e4a64c39cac609541945c0518feef040) adds math and svg to the list of elements whose contents are removed:
"summary","details","caption","figure","figcaption","abbr","bdo","cite","dfn","mark",
"small","span","time","wbr","center"
],
- :remove_contents => ["script"],
+ :remove_contents => ["script", "math", "svg"],
:attributes => Dict(
"a" => ["href"],
"img" => ["src", "longdesc"],
Source: GitHub Commit 0c3dc35
Detection Methods for CVE-2025-52561
Indicators of Compromise
- Sanitized HTML output containing <style> elements with embedded </style> sequences followed by additional tags
- Rendered pages including unexpected <script>, <img onerror=...>, or event-handler attributes originating from user input
- Web server logs showing POST bodies with <style>...</style><img src=x onerror= style payloads
Detection Strategies
- Inventory Julia project dependencies (Project.toml, Manifest.toml) and flag any HTMLSanitizer.jl version below 0.2.1.
- Add unit tests that feed known XSS payloads through the sanitizer and assert that script execution primitives do not survive.
- Deploy content security policy (CSP) reporting to capture inline-script violations that indicate successful injection attempts.
Monitoring Recommendations
- Monitor application logs for HTTP requests submitting HTML containing style, math, or svg tags to endpoints that later render user content.
- Alert on CSP script-src violation reports from pages served with sanitized user content.
- Track outbound requests from browser sessions to attacker-controlled domains that could indicate data exfiltration via injected scripts.
How to Mitigate CVE-2025-52561
Immediate Actions Required
- Upgrade HTMLSanitizer.jl to version 0.2.1 or later using Pkg.update("HTMLSanitizer").
- Audit custom whitelist configurations and remove style, math, and svg from allowed tags unless strictly required.
- Re-scan stored user-generated content sanitized by vulnerable versions and re-sanitize with the patched release.
Patch Information
The fix is delivered in HTMLSanitizer.jl 0.2.1 via commit 0c3dc359e4a64c39cac609541945c0518feef040, merged in Pull Request #5. Details are documented in GitHub Security Advisory GHSA-3mj7-qxh9-6q4p. The patch expands :remove_contents to strip children of script, math, and svg elements.
Workarounds
- If upgrading is not immediately possible, manually add math and svg to the :remove_contents list in the sanitizer whitelist.
- Remove style from the allowed tag list to prevent raw-text unescaping in that element.
- Apply a strict CSP that disallows inline scripts and event handlers to reduce impact of any residual injection.
# Update HTMLSanitizer.jl to the patched release
julia -e 'using Pkg; Pkg.update("HTMLSanitizer"); Pkg.status("HTMLSanitizer")'
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

