CVE-2026-141556: CVE-2026-141556: Cross-Site Scripting Bypass via iframe srcdoc and SVG Animation Attributes in lxml-html-clean
CVE-2026-141556: Cross-Site Scripting Bypass via iframe srcdoc and SVG Animation Attributes in lxml-html-clean Vulnerability ID: CVE-2026-141556 CVSS Score: 4.7 Published: 2026-12-03 CVE-2026-141556 (GHSA-5gvf-7wqf-
CVE-2026-141556: Cross-Site Scripting Bypass via iframe srcdoc and SVG Animation Attributes in lxml-html-clean
Vulnerability ID: CVE-2026-141556
CVSS Score: 4.7
Published: 2026-12-03
CVE-2026-141556 (GHSA-5gvf-7wqf-r4cv) is an input sanitization bypass vulnerability resulting in Cross-Site Scripting (XSS) in lxml-html-clean versions through 0.4.6. When the Cleaner class is initialized with safe_attrs_only=False and javascript=True, the link sanitization mechanism relies exclusively on lxml.html.defs.link_attrs via doc.rewrite_links(). Because this attribute list omits the iframe srcdoc attribute and SVG SMIL animation value attributes (to, from, by, values), attackers can inject arbitrary HTML and JavaScript payloads that survive sanitization.
TL;DR
An incomplete attribute allowlist in lxml-html-clean <= 0.4.6 allows attackers to bypass HTML sanitization when safe_attrs_only=False is enabled. By leveraging the iframe srcdoc attribute (when host_whitelist permits iframes) or SVG SMIL animation attributes (when remove_unknown_tags=False permits SVG tags), an attacker can achieve zero-click or one-click Cross-Site Scripting (XSS). Users should upgrade to lxml-html-clean version 0.4.7.
⚠️ Exploit Status: POC
Technical Details
- CVE / Advisory ID: CVE-2026-141556 / GHSA-5gvf-7wqf-r4cv
- Vulnerability Class: CWE-79 (Cross-Site Scripting) / CWE-184 (Incomplete List of Disallowed Inputs)
- Affected Component: lxml-html-clean (<= 0.4.6)
- Patched Version: 0.4.7
- CVSS v3.1 Score: 4.7 Medium (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N)
- Required Configuration: safe_attrs_only=False (paired with host_whitelist or remove_unknown_tags=False)
- Exploit Status: Proof-of-Concept (Unit test payloads in upstream repository)
- CISA KEV Status: Not Listed
Affected Systems
- lxml-html-clean (PyPI package lxml_html_clean) <= 0.4.6
-
lxml-html-clean: <= 0.4.6 (Fixed in:
0.4.7)
Code Analysis
Commit: 883db20
fix: drop srcdoc and SVG animation link values when cleaning javascript
diff --git a/lxml_html_clean/clean.py b/lxml_html_clean/clean.py
index e68e8d7..9293fe8 100644
--- a/lxml_html_clean/clean.py
+++ b/lxml_html_clean/clean.py
@@ -130,6 +130,59 @@ def _comment_breaks_out_of_raw_text_ancestor(el):
parent = parent.getparent()
return False
+
+# SVG animation elements can set another attribute at runtime. When the
+# target is a link attribute, their value attributes carry a URL that
+# rewrite_links() never sees (they are not in defs.link_attrs).
+_svg_animation_tags = frozenset(('set', 'animate', 'animatetransform'))
+_svg_animation_value_attrs = frozenset(('to', 'from', 'by', 'values'))
+
+
+def _local_name(name):
+ """'{ns}href', 'xlink:href', 'q:HREF' -> 'href'."""
+ return name.rsplit('}', 1)[-1].rsplit(':', 1)[-1].lower()
+
+
+def _remove_attrs_that_bypass_link_cleaning(doc):
+ for el in doc.iter(etree.Element):
+ attrib = el.attrib
+ for aname in list(attrib.keys()):
+ if _local_name(aname) == 'srcdoc':
+ del attrib[aname]
+ if _local_name(el.tag) not in _svg_animation_tags:
+ continue
+ animates_href = any(
+ _local_name(attrib[aname].strip()) == 'href'
+ for aname in attrib.keys()
+ if _local_name(aname) == 'attributename')
+ if animates_href:
+ for aname in list(attrib.keys()):
+ if _local_name(aname) in _svg_animation_value_attrs:
+ del attrib[aname]
+
+
@@ -432,6 +475,7 @@ def __call__(self, doc):
del attrib[aname]
doc.rewrite_links(self._remove_javascript_link,
resolve_base_href=False)
+ _remove_attrs_that_bypass_link_cleaning(doc)
# If we're deleting style then we don't have to remove JS links
# from styles, otherwise...
if not self.inline_style:
Commit: 0d4e91e
docs: clarify _remove_attrs_that_bypass_link_cleaning docstring
Exploit Details
- GitHub: Upstream fix commit containing functional unit test cases (PoCs) demonstrating iframe srcdoc and SVG animation XSS bypasses.
Mitigation Strategies
- Upgrade lxml-html-clean to version 0.4.7 or later to enforce removal of srcdoc and SVG animation link value attributes.
- Enforce an allowlist approach for HTML attributes by setting safe_attrs_only=True (the default) and extending safe_attrs explicitly if custom attributes are needed.
- Restrict unknown and SVG animation tags by maintaining remove_unknown_tags=True or adding 'set', 'animate', and 'animatetransform' to remove_tags or kill_tags.
- Implement a strong Content Security Policy (CSP) that disables 'unsafe-inline' scripts to prevent execution of srcdoc scripts and javascript: URIs in the browser.
Remediation Steps:
- Audit application dependencies (requirements.txt, Pipfile.lock, poetry.lock) to identify installations of lxml-html-clean <= 0.4.6.
- Search application source code for Cleaner() instantiations that explicitly set safe_attrs_only=False.
- Upgrade the package via pip: pip install --upgrade 'lxml-html-clean>=0.4.7'.
- Re-sanitize any previously stored untrusted HTML content in the database that was processed using a vulnerable Cleaner configuration (safe_attrs_only=False).
References
- GitHub Security Advisory GHSA-5gvf-7wqf-r4cv
- Fix Commit: drop srcdoc and SVG animation link values when cleaning javascript
- Documentation Commit: clarify _remove_attrs_that_bypass_link_cleaning docstring
- lxml-html-clean 0.4.7 Release Tag
- National Vulnerability Database (NVD) Entry for CVE-2026-141556
- CVE.org Record for CVE-2026-141556
- CVEProject cvelistV5 JSON Record for CVE-2026-141556
Read the full report for CVE-2026-141556 on our website for more details including interactive diagrams and full exploit analysis.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.