GHSL-2021-1037_GHSL-2021-1038: Improper sanitization of data URLs and style attributes in lxml HTML Sanitizer - CVE-2021-43818
The lxml HTML sanitizer failed to properly sanitize inline style attributes and data URL images, allowing an attacker to inject JavaScript. This could lead to cross-site scripting when a user interacts with a crafted link or element.
Originally disclosed on GitHub Security Lab
The lxml HTML sanitizer fails to properly sanitize data URLs and style attributes
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the sanitizer used regular expressions that could be bypassed: one allowed reintroduction of dangerous CSS expressions after substitution, and another permitted data URLs for images without checking for embedded scripts.
Impact
This issue may lead to Cross-Site Scripting, though the style-based vector has lower priority because such vectors do not normally work on modern browsers.
What the attacker needed
Victim opens a crafted link; sanitizer processes attacker HTML
The fix
The issues were fixed in a later release.
How it was found
- Craft an HTML element with a style attribute containing a bypass for the sanitizer's regex.
- Craft a link with a data URL containing an SVG image with embedded JavaScript.
- Right-click the link and open it in a new tab to trigger the JavaScript.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A sanitizer is a tool that cleans HTML to remove dangerous code. Here, the sanitizer made mistakes: it allowed a style attribute that could contain a script, and it allowed a special image link that could run JavaScript when opened. An attacker could use these to run their own code in a victim's browser.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.