XSS Vulnerability in python-markdown2: A Security Risk for Web Applications
Summary
CVE-2020-11888: python-markdown2 through 2.3.8 allows XSS because element names are mishandled unless a \w+ match succeeds. Affects python-markdown2 across 2 version ranges.
< 2.3.9-1
< 44dde555d9cecbcfa16a3d07f17415719777e5c9
Fixed in 2.3.9-1. 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
python-markdown2 is a popular Python library that converts Markdown text to HTML. It is widely used in web applications for rendering user-generated content. The library provides various features such as support for Markdown extensions and customizable output. However, it has a vulnerability that can lead to Cross-Site Scripting (XSS) attacks, which can compromise the security of applications using this library.
Vulnerability Detail
The vulnerability, identified as CVE-2020-11888, arises from improper handling of element names in python-markdown2 versions prior to 2.3.9. Specifically, the library fails to adequately validate element names, allowing attackers to inject malicious scripts via attributes like 'onclick'. This can lead to unauthorized script execution in the context of a user's browser, potentially exposing sensitive information or allowing unauthorized actions.
How To Fix
Minimum fixed version
2.3.9-1
This is the first release that contains the fix.
sudo apt-get install --only-upgrade python-markdown2
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading is not immediately possible, a temporary workaround is to sanitize user input before processing it with python-markdown2. This can be done by using a library like bleach to remove potentially harmful HTML tags and attributes. Example code:
import bleach
allowed_tags = bleach.sanitizer.ALLOWED_TAGS + ['a']
allowed_attrs = {'a': ['href']}
safe_input = bleach.clean(user_input, tags=allowed_tags, attributes=allowed_attrs)
Conclusion
The CVE-2020-11888 vulnerability in python-markdown2 poses a significant security risk due to its potential for XSS attacks. Users are strongly advised to upgrade to version 2.3.9 or later to mitigate this risk. Additionally, implementing input sanitization can serve as a temporary measure until an upgrade is feasible.
See every vulnerability recorded for python-markdown2 →
FAQ
CVE-2020-11888 is a vulnerability in the python-markdown2 library that allows for Cross-Site Scripting (XSS) attacks due to improper handling of element names.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.
If exploited, this vulnerability can allow attackers to execute malicious scripts in the context of a user's browser, leading to data theft, session hijacking, or other malicious actions.
Yes, you can sanitize user inputs using libraries like bleach to remove harmful HTML tags and attributes before processing them with python-markdown2.
The CVSS score for CVE-2020-11888 is 6.1, indicating a medium severity level.
Related vulnerabilities
Recent vulnerabilities recorded for python-markdown2.