CVE-2021-43818: Vulnerability in lxml - Crafted and SVG Embedded Scripts Bypass HTML Cleaner

lxml Updated 02 Oct 2025

Summary

13/12/2021
Yes i
Moderate
8.2

CVE-2021-43818: lxml's HTML Cleaner allows crafted and SVG embedded scripts to pass through. Affects lxml versions < 4.6.5. Fixed in 4.6.5. How to fix ↓

Also tracked for

The same CVE-2021-43818 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

lxml is a Python library that provides a powerful and easy-to-use interface for parsing and manipulating XML and HTML documents. It is widely used for web scraping, data extraction, and XML processing tasks. The HTML Cleaner module in lxml is designed to sanitize HTML content by removing potentially malicious or unsafe elements and attributes. However, a vulnerability has been discovered in lxml's HTML Cleaner that allows certain crafted script content and script content in SVG files embedded using data URIs to bypass the cleaning process.

Vulnerability Detail

The vulnerability in lxml's HTML Cleaner allows crafted script content to pass through the cleaning process, potentially leading to cross-site scripting (XSS) attacks. Additionally, script content in SVG files embedded using data URIs can also bypass the cleaning process, further increasing the risk of XSS attacks. This vulnerability can be exploited by an attacker to inject malicious scripts into web pages, compromising the security and integrity of the affected application. The issue has been assigned a CVSS score of 8.2, indicating a high severity level.

How To Fix

Latest published version: 6.1.3 as of 22 Oct 2026

pip install --upgrade "lxml==6.1.3"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4.6.5

This is the first release that contains the fix.

pip install --upgrade "lxml==4.6.5"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

There are no known workarounds for this vulnerability. It is recommended to upgrade to the fixed version of lxml as soon as possible.

Conclusion

The vulnerability in lxml's HTML Cleaner allows crafted and SVG embedded scripts to bypass the cleaning process, potentially leading to cross-site scripting (XSS) attacks. Users should upgrade to lxml version 4.6.5 or later to mitigate this vulnerability. For further assistance or support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for lxml →

Share this vulnerability

FAQ

lxml is a Python library for parsing and manipulating XML and HTML documents. It is commonly used for web scraping and data extraction tasks.

The HTML Cleaner module in lxml is responsible for sanitizing HTML content by removing potentially malicious or unsafe elements and attributes.

This vulnerability allows crafted script content and script content in SVG files embedded using data URIs to bypass the HTML cleaning process, potentially leading to cross-site scripting (XSS) attacks.

To fix this vulnerability, you should upgrade to lxml version 4.6.5 or later. This version includes a fix for the HTML Cleaner module that properly sanitizes script content.

No, there are no known workarounds for this vulnerability. It is recommended to upgrade to the fixed version of lxml.

Related vulnerabilities

Recent vulnerabilities recorded for lxml.

How To Fix

Latest published version: 6.1.3 as of 22 Oct 2026

pip install --upgrade "lxml==6.1.3"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4.6.5

This is the first release that contains the fix.

pip install --upgrade "lxml==4.6.5"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback