CVE-2026-49825: lxml-html-clean Vulnerability in URL Attribute Sanitization
Summary
CVE-2026-49825: lxml_html_clean.Cleaner does not strip javascript: URLs from namespaced URL attributes. Affects lxml-html-clean versions < 0.4.5. Fixed in 0.4.5. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
lxml-html-clean is a Python package that provides a cleaner for HTML content, allowing developers to sanitize untrusted HTML by removing potentially harmful elements and attributes. It is commonly used in web applications to prevent XSS (Cross-Site Scripting) attacks. The package is designed to filter out unsafe attributes and ensure that the rendered HTML is safe for users. However, a vulnerability exists in the way it handles namespaced URL attributes, specifically xlink:href, which can lead to security risks if not addressed.
Vulnerability Detail
The vulnerability arises from the lxml_html_clean.Cleaner class, which fails to strip javascript: URLs from namespaced URL attributes like xlink:href. This oversight allows malicious payloads to pass through the sanitizer when the safe_attrs_only option is set to False. As a result, an attacker can inject JavaScript code that executes when a user clicks on the rendered link, leading to stored XSS vulnerabilities. The root cause is linked to an incomplete allow-list of attributes that does not include xlink:href, which is necessary for proper sanitization.
How To Fix
Minimum fixed version
0.4.5
This is the first release that contains the fix.
pip install --upgrade "lxml-html-clean==0.4.5"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If you cannot update the package immediately, you can implement a temporary workaround by manually checking and removing any xlink:href attributes containing javascript: URLs in your HTML content. Here's a code snippet to illustrate this workaround:
from lxml import html
def sanitize_xlink_href(tree):
for el in tree.iter():
if 'xlink:href' in el.attrib and el.attrib['xlink:href'].startswith('javascript:'):
del el.attrib['xlink:href']
# Example usage:
html_content = '<svg><a xlink:href="javascript:alert(1)">x</a></svg>'
tree = html.fromstring(html_content)
sanitize_xlink_href(tree)
print(html.tostring(tree).decode())
Conclusion
The CVE-2026-49825 vulnerability in the lxml-html-clean package poses a significant risk due to its failure to properly sanitize namespaced URL attributes. It is crucial for developers to update to the patched version or implement the provided workaround to mitigate the risk of XSS attacks.
See every vulnerability recorded for lxml-html-clean →
FAQ
CVE-2026-49825 is a vulnerability in the lxml-html-clean package that allows javascript: URLs to pass through the sanitizer when using namespaced URL attributes like xlink:href.
The vulnerability can lead to stored XSS attacks, where malicious JavaScript code is executed in the context of the user's browser, potentially compromising user data and application integrity.
You can use Vulert, a tool that monitors and alerts for open-source vulnerabilities in your software. Check your application against this vulnerability using the Vulert playground at Vulert Scanner.
Implement the provided workaround to manually sanitize xlink:href attributes in your HTML content until you can update to the patched version.
The CVSS score for this vulnerability is 8.2, indicating a high severity level.
Related vulnerabilities
Recent vulnerabilities recorded for lxml-html-clean.
Follow Vulert in Google
Get more Vulert vulnerability and dependency-security updates in Google Search and AI results.