GHSA-5gvf-7wqf-r4cv

Suggest an improvement
Source
https://github.com/advisories/GHSA-5gvf-7wqf-r4cv
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/12/GHSA-5gvf-7wqf-r4cv/GHSA-5gvf-7wqf-r4cv.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-5gvf-7wqf-r4cv
Aliases
Published
2026-12-03T02:41:48Z
Modified
2026-12-03T03:00:04Z
Severity
  • 4.7 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N CVSS Calculator
Summary
lxml_html_clean: Cleaner(safe_attrs_only=False) keeps javascript: in iframe srcdoc and SVG animation values
Details

Summary

When safe_attrs_only=False, the Cleaner still tries to remove JavaScript (javascript=True is the default): it deletes on* attributes (lxml_html_clean/clean.py:381-389 in 0.4.6) and blanks javascript: URLs through doc.rewrite_links(self._remove_javascript_link) (clean.py:390). rewrite_links only visits the attributes listed in lxml.html.defs.link_attrs, and two kinds of attributes that can carry script are not on that list:

  1. srcdoc on <iframe>. Its value is a complete HTML document that the browser renders inside the frame. With host_whitelist set, the <iframe> itself is kept, and srcdoc takes priority over src, so the whitelisted src no longer matters.
  2. to, values (and from, by) on the SVG animation elements <set> and <animate>. With attributeName="href" they set the href of the enclosing SVG <a> at runtime, so javascript: ends up on the link even though the Cleaner removed it from href itself. This one also needs remove_unknown_tags=False, otherwise <set>/<animate> are dropped.

This is the same root cause as GHSA-4jhm-jv67-739f (xlink:href with safe_attrs_only=False): an attribute missing from link_attrs (CWE-184). In both configurations below the same Cleaner turns href="javascript:..." into href="" and deletes onclick, so script removal is clearly still meant to apply.

The default Cleaner() is not affected: safe_attrs_only=True removes srcdoc, to and values.

Affected versions

Cleaner output was checked on lxml_html_clean 0.1.0, 0.4.0 and 0.4.6 from PyPI, and on the noscript_comment fix branch (0.4.7, commit 0546dc2), with lxml 6.1.3, libxml2 2.14.6 and Python 3.12. The output is the same in all of them. The browser test below was run on 0.4.6.

Reproduction

from lxml_html_clean import Cleaner

c_ifr = Cleaner(host_whitelist=['www.youtube.com'], safe_attrs_only=False)
c_svg = Cleaner(safe_attrs_only=False, remove_unknown_tags=False)

print(c_ifr.clean_html('<iframe src="https://www.youtube.com/embed/x" srcdoc="&lt;b&gt;MARK&lt;/b&gt;"></iframe>'))
print(c_svg.clean_html('<svg><a><set attributename="href" to="javascript:MARK"></set><text>x</text></a></svg>'))
print(c_svg.clean_html('<svg><a><animate attributename="href" values="javascript:MARK"></animate><text>x</text></a></svg>'))
# controls, same configurations
print(c_svg.clean_html('<svg><a href="javascript:MARK"><text>x</text></a></svg>'))
print(c_svg.clean_html('<svg><a onclick="MARK"><text>x</text></a></svg>'))
print(Cleaner(host_whitelist=['www.youtube.com']).clean_html('<iframe src="https://www.youtube.com/embed/x" srcdoc="&lt;b&gt;MARK&lt;/b&gt;"></iframe>'))
<iframe src="https://www.youtube.com/embed/x" srcdoc="&lt;b&gt;MARK&lt;/b&gt;"></iframe>
<svg><a><set attributename="href" to="javascript:MARK"></set><text>x</text></a></svg>
<svg><a><animate attributename="href" values="javascript:MARK"></animate><text>x</text></a></svg>
<svg><a href=""><text>x</text></a></svg>
<svg><a><text>x</text></a></svg>
<iframe src="https://www.youtube.com/embed/x"></iframe>

Browser check (headless Chromium, no network, 0.4.6): each cleaned output was placed in a static page. The script in srcdoc ran when the page loaded, with no interaction. For <set> and <animate>, the javascript: URL ran when the SVG link was clicked. The click was simulated with dispatchEvent(new MouseEvent("click")), not a real pointer click. The controls (href="javascript:..." and the iframe without srcdoc) did not run anything.

Impact

Stored or reflected XSS in applications that clean user HTML with safe_attrs_only=False and render the result. The srcdoc variant runs without a click when host_whitelist is also set, for example to allow video embeds. The SVG variant needs remove_unknown_tags=False as well, plus one click on the link.

Suggested fix

In the if self.javascript: block of Cleaner.__call__:

  • delete srcdoc from every element;
  • on <set> and <animate>, when attributeName is href or xlink:href, delete to, from, by and values. Dropping them is simpler than scheme-checking them, because values is a ;-separated list and a check on the whole string does not see every item.
Database specific
{
    "cwe_ids":  [
        "CWE-184",
        "CWE-79"
    ],
    "github_reviewed":  true,
    "github_reviewed_at":  "2026-12-03T02:41:48Z",
    "nvd_published_at":  "2026-12-02T21:18:11Z",
    "severity":  "MODERATE"
}
References

Affected packages

PyPI / lxml-html-clean

Package

Name
lxml-html-clean
View open source insights on deps.dev
Purl
pkg:pypi/lxml-html-clean

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0 Unknown introduced version / All previous versions are affected
Fixed
0.4.7

Affected versions

0.*
0.1.0
0.1.1
0.2.0
0.2.1
0.2.2
0.3.0
0.3.1
0.4.0
0.4.1
0.4.2
0.4.3
0.4.4
0.4.5
0.4.6

Database specific

last_known_affected_version_range
"<= 0.4.6"
source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/12/GHSA-5gvf-7wqf-r4cv/GHSA-5gvf-7wqf-r4cv.json"