Listen to this Post
Ammonia is an HTML sanitization library. The vulnerability arises from its incorrect handling of embedded SVG and MathML content when specific tags are allowed. During the sanitization process, Ammonia parses input as HTML. However, certain elements, like `<>` or <style>, are treated as raw text elements in HTML but as parsed XML content within SVG/MathML namespaces. The flaw occurs when a tag (e.g., <>) is allowed and placed inside an allowed `
Vulnerability : Mutation XSS
Severity: Low
date: 2025-09-22
Prediction: Patch Available
What Undercode Say:
curl -s "https://crates.io/api/v1/crates/ammonia" | jq -r '.versions[] | select(.num | test("^(3\.3\.1|4\.0\.1|4\.1\.2)$")) | "(.num) (.created_at)"'
// Vulnerable configuration allowing SVG and
let allowed_tags: HashSet<&str> = ["svg", ""].into_iter().collect();
let dirty_html = r"<svg><></><![CDATA[</><script>alert('XSS')</script>]]></svg>";
let clean = ammonia::clean_with_options(dirty_html, &ammonia::Options::default().allowed_tags(allowed_tags));
// The 'clean' output may contain mutated, dangerous content.
How Exploit:
Attacker crafts HTML with nested SVG and CDATA sections. Ammonia’s sanitizer incorrectly handles the context, leaving malicious script code within a `<>` tag. When the sanitized output is rendered by a browser, the XML parser activates for the SVG context, interpreting the content within the `<>` tag as executable, leading to script execution.
Protection from this CVE
Update to patched versions: 3.3.1, 4.0.1, or 4.1.2. If an upgrade is not possible, do not allow the `svg` or `math` tags in the ammonia configuration. Additionally, avoid allowing raw text elements like “, style, script, noscript, iframe, noembed, noframes, and `plaintext` if SVG/MathML are enabled.
Impact:
Limited impact. Requires a non-default configuration where both SVG/MathML tags and specific raw-text HTML tags are explicitly allowed. Successful exploitation leads to Cross-Site Scripting (XSS) within the security context of the page using the vulnerable ammonia sanitizer.
🎯Let’s Practice Exploiting & Learn Patching For Free:
Sources:
Reported By: github.com
Extra Source Hub:
Undercode

