Mutation XSS Vulnerability in python-bleach Package

python-bleach Updated 02 Oct 2025

Summary

16/02/2023
N/A
Yes i
Unrated
Not published

DEBIAN-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 versions < 3.2.1-2.1. 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

The python-bleach package is a popular HTML sanitization library used in Python applications to prevent XSS (Cross-Site Scripting) attacks by cleaning up user-submitted content. It allows developers to specify which HTML tags and attributes are safe to use, ensuring that potentially harmful code is removed. However, certain configurations can lead to vulnerabilities, particularly when specific tags are allowed alongside certain parameters.

Vulnerability Detail

A mutation XSS vulnerability exists in the python-bleach package when users call the bleach.clean function with specific configurations. This vulnerability arises when the following conditions are met: the 'svg' or 'math' tags are included in the allowed tags, 'p' or 'br' tags are also allowed, and the keyword argument 'strip_comments' is set to False. This combination can lead to the execution of malicious scripts, posing a significant security risk to applications utilizing this 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, users should avoid allowing 'svg' or 'math' tags in their configurations and ensure that 'strip_comments' is set to True when calling the bleach.clean function. This can be done by modifying the function call as follows: 'bleach.clean(user_input, strip_comments=True)'.

Conclusion

The mutation XSS vulnerability in the python-bleach package poses a serious risk to applications that utilize this library under specific configurations. It is crucial for developers to update to the patched version and implement recommended workarounds to mitigate potential threats.

See every vulnerability recorded for python-bleach →

Share this vulnerability

FAQ

The vulnerability is a mutation XSS that can occur when specific HTML tags are allowed in conjunction with certain parameters.

Versions prior to 3.2.1-2.1 are affected by this vulnerability.

You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.

If an immediate update is not possible, ensure that you do not allow 'svg' or 'math' tags and set 'strip_comments' to True as a temporary measure.

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