Skip to content
XSS Write-up Advanced

CSS:the bomb inside your inbox

Webmail clients render untrusted HTML and CSS in a trusted interface and rely on sanitisers that can be bypassed or mutated, letting an attacker hide content from the victim while showing it to an AI browser, or exfiltrate login tokens via CSS attribute selectors. The author also shows that pasting attacker-controlled HTML into a draft email can trigger a race condition where CSS is briefly applied before sanitisation, allowing token theft and account takeover.

portswigger.net

Published on portswigger.net

Gareth Heyes - [email protected] - @garethheyes

The author, on portswigger.net

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the sanitisers' view of what is safe diverges from what the browser actually parses and renders, and pasted content is styled before sanitisation runs.

Impact

An attacker could steal a victim's email login token and take over their account, and could also hide instructions from the victim while an AI browser reads them, though the token theft depended on the victim pasting copied content into a draft and on browser-specific behaviour.

What the attacker needed

Victim pastes copied content into a draft; attacker knows the victim's email; browser applies pasted CSS (Firefox worked best)

The fix

Webmail clients should sanitise pasted content before it is rendered rather than after, and should not allow label elements or style blocks that can act on the surrounding interface.

How it was found

  1. Copy HTML containing a style block to the clipboard using a tool that places HTML on the clipboard
  2. Paste it into a contenteditable draft in the webmail client
  3. Observe the page text briefly flash red, showing the CSS was applied before sanitisation
  4. Craft CSS attribute selectors that match parts of a token in a link and load a remote image for each match
  5. Recover the full token from the exfiltration requests and use it to log in as the victim

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 write-up has not been written yet. The Original tab links to the source.

Email apps show messages written by strangers inside their own trusted page, so they try to strip out anything dangerous. The researcher found that the filtering can be fooled, and that simply pasting copied content into a draft can briefly apply hidden styling before it is cleaned. That let him steal login codes and trick an AI browser into following instructions hidden in an email.

What is XSS?

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

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.