CVE-2026-141555: CVE-2026-141555: Cross-Site Scripting via Raw-Text Comment Breakout in lxml-html-clean
CVE-2026-141555: Cross-Site Scripting via Raw-Text Comment Breakout in lxml-html-clean Vulnerability ID: CVE-2026-141555 CVSS Score: 4.7 Published: 2026-12-03 CVE-2026-141555 (GHSA-vfhw-gfwp-vxfj) is a Cross-Site Sc
CVE-2026-141555: Cross-Site Scripting via Raw-Text Comment Breakout in lxml-html-clean
Vulnerability ID: CVE-2026-141555
CVSS Score: 4.7
Published: 2026-12-03
CVE-2026-141555 (GHSA-vfhw-gfwp-vxfj) is a Cross-Site Scripting (XSS) vulnerability in the Python HTML sanitization library lxml-html-clean prior to version 0.4.7. The vulnerability stems from a parser differential between libxml2 and HTML5 browser parsing engines when handling HTML comments nested within raw-text and escapable raw-text elements (such as , , <title>, and <iframe>). When the cleaner is instantiated with the non-default configuration comments=False, an attacker can embed a closing tag inside an HTML comment to prematurely terminate the raw-text container in the client browser and execute arbitrary JavaScript.</p> <h2> <a name="tldr" href="#tldr" class="anchor"> </a> TL;DR </h2> <p>A parser differential between libxml2 and HTML5 browsers allows attackers to bypass HTML sanitization in lxml-html-clean (< 0.4.7) when configured with comments=False. By nesting a closing tag such as </noscript> inside an HTML comment within a raw-text container, attackers achieve Cross-Site Scripting (XSS) in the victim's browser.</p> <hr> <h3> <a name="exploit-status-poc" href="#exploit-status-poc" class="anchor"> </a> ⚠️ Exploit Status: POC </h3> <h2> <a name="technical-details" href="#technical-details" class="anchor"> </a> Technical Details </h2> <ul> <li><strong>CVE ID</strong>: CVE-2026-141555 (GHSA-vfhw-gfwp-vxfj)</li> <li><strong>Weakness Class</strong>: CWE-79: Cross-Site Scripting (XSS) via Parser Differential</li> <li><strong>CVSS v3.1 Score</strong>: 4.7 Medium (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N)</li> <li><strong>Affected Component</strong>: lxml-html-clean (< 0.4.7) with Cleaner(comments=False)</li> <li><strong>Patched Version</strong>: lxml-html-clean 0.4.7</li> <li><strong>Attack Vector</strong>: Network (Crafted HTML comment nested in raw-text container)</li> <li><strong>Exploit Status</strong>: Proof-of-Concept Available</li> <li><strong>CISA KEV Status</strong>: Not Listed</li> </ul> <h2> <a name="affected-systems" href="#affected-systems" class="anchor"> </a> Affected Systems </h2> <ul> <li>fedora-python/lxml_html_clean</li> <li>lxml-html-clean (PyPI)</li> <li><strong>lxml-html-clean</strong>: >= 0.1.0, < 0.4.7 (Fixed in: <code>0.4.7</code>)</li> </ul> <h2> <a name="code-analysis" href="#code-analysis" class="anchor"> </a> Code Analysis </h2> <h3> <a name="commit-c83f0be" href="#commit-c83f0be" class="anchor"> </a> Commit: <a href="https://github.com/fedora-python/lxml_html_clean/commit/c83f0befb32505782858f56a17ac572fbf979f62">c83f0be</a> </h3> <p>fix: drop breakout comments inside raw-text elements (XSS)<br> </p> <div class="highlight"><pre class="highlight diff"><code><span class="gi">+_breakout_raw_text_elements = frozenset((</span> <span class="gi">+ 'noscript', 'noembed', 'noframes', 'iframe', 'xmp',</span> <span class="gi">+ 'title', 'textarea', 'style', 'script', 'plaintext',</span> <span class="gi">+))</span> <span class="gi">+</span> <span class="gi">+_find_end_tag_names = re.compile(r'</([a-zA-Z][a-zA-Z0-9:_-]*)').findall</span> <span class="gi">+</span> <span class="gi">+</span> <span class="gi">+def _comment_breaks_out_of_raw_text_ancestor(el):</span> <span class="gi">+ text = el.text</span> <span class="gi">+ if not text or '</' not in text:</span> <span class="gi">+ return False</span> <span class="gi">+ end_tags = {name.lower() for name in _find_end_tag_names(text)}</span> <span class="gi">+ if not end_tags:</span> <span class="gi">+ return False</span> <span class="gi">+ parent = el.getparent()</span> <span class="gi">+ while parent is not None:</span> <span class="gi">+ tag = parent.tag</span> <span class="gi">+ if isinstance(tag, str):</span> <span class="gi">+ tag = tag.lower()</span> <span class="gi">+ if tag in _breakout_raw_text_elements and tag in end_tags:</span> <span class="gi">+ return True</span> <span class="gi">+ parent = parent.getparent()</span> <span class="gi">+ return False</span> def kill_conditional_comments(self, doc): self._kill_elements( doc, <span class="gd">- lambda el: _has_conditional_comment(el.text),</span> <span class="gi">+ lambda el: (_has_conditional_comment(el.text)</span> <span class="gi">+ or _comment_breaks_out_of_raw_text_ancestor(el)),</span> etree.Comment) </code></pre></div> <p></p> <h2> <a name="mitigation-strategies" href="#mitigation-strategies" class="anchor"> </a> Mitigation Strategies </h2> <ul> <li>Upgrade lxml-html-clean to version 0.4.7 or later to ensure comments breaking out of raw-text ancestor elements are stripped during sanitization.</li> <li>Configure lxml_html_clean.clean.Cleaner with the default comments=True setting to remove all HTML comments from untrusted markup.</li> <li>Implement a strict Content Security Policy (CSP) that disallows unsafe inline script execution (e.g., avoiding 'unsafe-inline' in script-src) to limit the impact of any HTML sanitizer bypass.</li> <li>Deploy WAF or input validation rules to detect HTML comments containing closing tags for raw-text elements such as </noscript>, , , or .
Remediation Steps:
- Audit project dependency files (requirements.txt, Pipfile.lock, poetry.lock, pyproject.toml) to identify installations of lxml-html-clean prior to 0.4.7.
- Search application source code for custom instantiations of Cleaner(comments=False) or clean_html() calls passing modified Cleaner instances.
- Run 'pip install --upgrade lxml-html-clean>=0.4.7' and rebuild application containers or virtual environments.
- If stored HTML content was previously sanitized with comments=False under versions < 0.4.7, re-run the updated sanitizer over stored database records to strip any persisted breakout comments.
References
- GitHub Security Advisory: GHSA-vfhw-gfwp-vxfj
- Fix Commit: c83f0befb32505782858f56a17ac572fbf979f62
- GitHub Release: lxml-html-clean 0.4.7
- CVE.org Record: CVE-2026-141555
- NVD Detail: CVE-2026-141555
- cvelistV5 Definition: CVE-2026-141555.json
Read the full report for CVE-2026-141555 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.