Mutation XSS Vulnerability in Python Bleach Package

python-bleach Updated 02 Oct 2025

Summary

16/02/2023
N/A
Yes i
Medium
6.1

CVE-2021-23980: A mutation XSS affects users calling bleach.clean with all of: svg or math in the allowed tags p or br in allowed tags style, title, noscript, script, textarea, noframes, iframe, or xmp in allowed tags the keyword argume... Affects python-bleach across 2 version ranges.

< 3.2.1-2.1 < 79b7a3c5e56a09d1d323a5006afa59b56162eb13

Fixed in 3.2.1-2.1. How to fix ↓

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 Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

Python Bleach is a popular library used for sanitizing HTML and preventing XSS (Cross-Site Scripting) attacks. It allows developers to safely render user-generated content by removing potentially harmful tags and attributes. However, certain configurations can expose users to vulnerabilities, particularly when specific tags are allowed in conjunction with the strip_comments option.

Vulnerability Detail

The vulnerability, identified as CVE-2021-23980, is a mutation XSS that arises when users call the bleach.clean function with specific configurations. It occurs when the following conditions are met: the allowed tags include 'p' or 'br', and the tags 'svg' or 'math' are also allowed, along with style, title, noscript, script, textarea, noframes, iframe, or xmp. Additionally, the keyword argument strip_comments must be set to False. This combination can lead to the execution of malicious scripts, posing a significant security risk to applications using the library.

How To Fix

Minimum fixed version

3.2.1-2.1

This is the first release that contains the fix.

sudo apt-get install --only-upgrade python-bleach

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

Workaround

As a temporary workaround, avoid using the bleach.clean function with the specified configurations. Instead, sanitize user input by using a more restrictive set of allowed tags, or set strip_comments to True to mitigate the risk of XSS attacks.

Conclusion

The mutation XSS vulnerability in the Python Bleach package poses a significant risk when specific configurations are used. It is crucial for developers to update their packages and follow best practices for sanitizing user input to protect against potential attacks.

See every vulnerability recorded for python-bleach →

Share this vulnerability

FAQ

CVE-2021-23980 is a vulnerability in the Python Bleach package that allows for mutation XSS under specific configurations.

You can check if your application is affected by using the Vulert playground at Vulert Scanner, which analyzes your manifest file for vulnerabilities.

The CVSS score of this vulnerability is 6.1, indicating a moderate severity level.

If an immediate update is not possible, consider implementing the suggested workaround by restricting allowed tags and setting strip_comments to True.

More information about Python Bleach can be found on its official GitHub repository at https://github.com/mozilla/bleach.

Related vulnerabilities

Recent vulnerabilities recorded for python-bleach.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

How To Fix

Minimum fixed version

3.2.1-2.1

This is the first release that contains the fix.

sudo apt-get install --only-upgrade python-bleach

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