CVE-2018-5773: markdown2 - Cross-Site Scripting (XSS) Vulnerability
Summary
CVE-2018-5773: An issue was discovered in markdown2 (aka python-markdown2) through 2.3.5. Affects markdown2 versions < 2.3.6. Fixed in 2.3.6. 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
markdown2 is a Python package available on PyPI that provides a fast and complete implementation of the Markdown language. It allows users to convert Markdown text into HTML, providing a convenient way to format and display content on websites. However, versions up to 2.3.5 of markdown2 are vulnerable to a Cross-Site Scripting (XSS) attack.
Vulnerability Detail
The safe_mode feature in markdown2, which is designed to sanitize user input and prevent XSS attacks, is flawed and does not properly escape input. This allows an attacker to craft a payload that can trigger XSS by omitting the final '>' character from an IMG tag. By exploiting this vulnerability, an attacker can inject malicious code into the generated HTML, potentially leading to unauthorized access, data theft, or other malicious activities.
How To Fix
Minimum fixed version
2.3.6
This is the first release that contains the fix.
pip install --upgrade "markdown2==2.3.6"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading to the latest version is not immediately feasible, users can implement a workaround by manually sanitizing user input before passing it to the markdown2 library. This can be done by using a trusted HTML sanitizer library, such as bleach, to sanitize any user-generated HTML content. Here's an example of how to use bleach to sanitize user input:
import bleach
user_input = '<img src=x onerror=alert(1)>' sanitized_input = bleach.clean(user_input)
Pass the sanitized input to markdown2
html_output = markdown2.markdown(sanitized_input)
Conclusion
The CVE-2018-5773 vulnerability in markdown2 exposes websites to Cross-Site Scripting (XSS) attacks. It is crucial to upgrade to version 2.3.6 or later of markdown2 to mitigate this vulnerability. If immediate upgrading is not possible, implementing a manual workaround by sanitizing user input can help prevent XSS attacks. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for markdown2 →
FAQ
markdown2 is a Python package that allows users to convert Markdown text into HTML. It provides a convenient way to format and display content on websites.
Cross-Site Scripting (XSS) is a type of security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users. This can lead to unauthorized access, data theft, and other malicious activities.
The safe_mode feature in markdown2 is designed to sanitize user input and prevent XSS attacks. It escapes potentially dangerous HTML tags and attributes to ensure that user-generated content is displayed safely.
The CVE-2018-5773 vulnerability in markdown2 allows an attacker to execute arbitrary JavaScript code in the context of a user's browser. This can lead to various malicious activities, such as stealing sensitive information, performing actions on behalf of the user, or modifying the appearance and behavior of the affected web page.
You can use Vulert's vulnerability monitoring service to check if your application is affected by the CVE-2018-5773 vulnerability. Vulert analyzes your Pipfile.lock file and provides real-time alerts for open-source vulnerabilities in your software. Visit Vulert's playground at Vulert Scanner to check if your application is affected.
References
Related vulnerabilities
Recent vulnerabilities recorded for markdown2.