CVE-2021-42576: pybluemonday - Policy Enforcement Failure in SELECT, STYLE, and OPTION Elements
Summary
CVE-2021-42576: The bluemonday sanitizer before 1.0.16 for Go, and before 0.0.8 for Python (in pybluemonday), does not properly enforce policies associated with the SELECT, STYLE, and OPTION elements. Affects pybluemonday versions < 0.0.8. Fixed in 0.0.8. How to fix ↓
Also tracked for
- github.com/microcosm-cc/bluemonday · Go
- github.com/microcosm-cc/bluemonday · Go
- golang-github-microcosm-cc-bluemonday · Debian:11
The same CVE-2021-42576 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
pybluemonday is a Python package available on PyPI that provides a sanitizer for HTML content. It allows developers to enforce policies to prevent malicious or unwanted HTML elements and attributes from being included in the output. The package is commonly used in web applications to sanitize user-generated content and protect against cross-site scripting (XSS) attacks. However, versions prior to 0.0.8 are vulnerable to a policy enforcement failure in the SELECT, STYLE, and OPTION elements.
Vulnerability Detail
The vulnerability (CVE-2021-42576) in pybluemonday arises from a failure to properly enforce policies associated with the SELECT, STYLE, and OPTION elements. This means that the sanitizer may not correctly sanitize or remove certain HTML elements or attributes within these elements, potentially allowing malicious code to be executed. Attackers could exploit this vulnerability to inject arbitrary scripts or manipulate the appearance and behavior of web pages, leading to XSS attacks or other security breaches.
How To Fix
Minimum fixed version
0.0.8
This is the first release that contains the fix.
pip install --upgrade "pybluemonday==0.0.8"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a workaround, developers can manually sanitize and validate the content of the SELECT, STYLE, and OPTION elements before passing them to pybluemonday. This can be done by implementing custom validation and sanitization logic to ensure that only safe and expected values are used in these elements. Here is an example of how this can be achieved in Python:
import pybluemonday
def sanitize_select_content(content):
# Custom validation and sanitization logic
sanitized_content = ...
return sanitized_content
# Usage
content = request.form['select_content']
sanitized_content = sanitize_select_content(content)
sanitized_html = pybluemonday.sanitize(sanitized_content)
Conclusion
In conclusion, pybluemonday versions prior to 0.0.8 are vulnerable to a policy enforcement failure in the SELECT, STYLE, and OPTION elements. This can result in the inclusion of malicious or unwanted HTML elements or attributes, potentially leading to XSS attacks or other security breaches. It is crucial to upgrade to the patched version and ensure that dependencies are updated to mitigate this vulnerability. For further support on vulnerability remediation, you can contact DevNack.com.
See every vulnerability recorded for pybluemonday →
FAQ
pybluemonday is a Python package that provides a sanitizer for HTML content. It allows developers to enforce policies to prevent malicious or unwanted HTML elements and attributes from being included in the output.
This vulnerability in pybluemonday can lead to cross-site scripting (XSS) attacks or other security breaches. Attackers could inject arbitrary scripts or manipulate the appearance and behavior of web pages.
To fix this vulnerability, you should upgrade to pybluemonday version 0.0.8 or later. Make sure to update your dependencies to use the patched version.
Yes, as a workaround, you can manually sanitize and validate the content of the SELECT, STYLE, and OPTION elements before passing them to pybluemonday. Implement custom validation and sanitization logic to ensure only safe values are used.
You can find more information about this vulnerability in the pybluemonday advisory on the PyPI Advisory Database: https://github.com/pypa/advisory-database/blob/main/vulns/pybluemonday/PYSEC-2021-849.yaml