CVE-2018-19787: Improper Neutralization of Input During Web Page Generation in LXML
Summary
CVE-2018-19787: Improper Neutralization of Input During Web Page Generation in LXML. Affects lxml versions < 4.2.5. Fixed in 4.2.5. How to fix ↓
Also tracked for
- lxml · Debian:11
The same CVE-2018-19787 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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 is a Python library that provides a Pythonic binding for the C libraries libxml2 and libxslt. It allows developers to work with XML and HTML documents in a simple and efficient manner. LXML is widely used in various applications and frameworks for parsing, manipulating, and generating XML and HTML content.
Vulnerability Detail
An issue was discovered in lxml before 4.2.5. The lxml.html.clean module in lxml/html/clean.py does not remove javascript: URLs that use escaping, allowing a remote attacker to conduct XSS attacks. This vulnerability can be exploited by injecting malicious JavaScript code into a web page generated by LXML. When a user visits the compromised page, the injected code will execute in their browser, potentially leading to unauthorized actions, data theft, or other malicious activities. This vulnerability is similar to CVE-2014-3146.
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.2.5
This is the first release that contains the fix.
pip install --upgrade "lxml==4.2.5"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading to the latest version of lxml is not immediately feasible, a temporary workaround is to manually sanitize the generated web pages to remove any javascript: URLs. This can be done by using a custom cleaning function or by using a dedicated HTML sanitizer library that is known to handle XSS vulnerabilities effectively.
Conclusion
The vulnerability in LXML before version 4.2.5 allows for XSS attacks by not properly removing javascript: URLs during web page generation. To mitigate this risk, it is recommended to upgrade to the latest version of lxml or apply a workaround to sanitize the generated web pages. For further assistance and support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for lxml →
FAQ
This vulnerability allows remote attackers to execute arbitrary JavaScript code in the context of a victim's browser, potentially leading to unauthorized actions, data theft, or other malicious activities.
No, only versions before 4.2.5 are affected. It is recommended to upgrade to the latest version to ensure the vulnerability is patched.
There are known exploits for similar vulnerabilities, but no specific exploit for this exact issue has been disclosed at the time of this advisory.
Yes, this vulnerability can be exploited remotely by enticing a user to visit a web page that contains the maliciously crafted content generated by LXML.
Yes, the CVSS score for this vulnerability is 6.1, indicating a moderate severity level.
Related vulnerabilities
Recent vulnerabilities recorded for lxml.