Inline Style Exfiltration: leaking data with chained CSS conditionals
The author found that CSS conditional if() statements combined with attr() and image-set() can read an element's attribute value and trigger a background request to an attacker-chosen URL based on that value. This lets an attacker who can inject only into a style attribute exfiltrate data such as user IDs or usernames, one guessed value at a time.
portswigger.net
Published on portswigger.net
Someone asked if you could steal data using inline styles. I initially dismissed the idea but then I was reminded of Slonser's excellent technique of using the attr() and image-set() functions to steal data from the attribute.
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 browser allows CSS if() conditionals to compare a value taken from attr() and then use the result to choose a background image URL, so data in an attribute can drive outbound requests from a style attribute alone.
Impact
An attacker who can inject into a style attribute could exfiltrate short attribute values such as user IDs or usernames, though at the time of writing the technique only worked in Chromium-based browsers.
What the attacker needed
Ability to inject into a style attribute; Chromium-based browser; attacker-controlled server to receive requests
How it was found
- Inject a style attribute that stores an attribute value in a custom property using attr().
- Build a conditional that compares that value against a guess and picks a URL for each outcome.
- Chain further conditionals to cover more candidate values.
- Load the chosen URL through image-set() so the browser makes the background request.
- Read which request arrived on the attacker's server to learn the value.
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.
Normally, to steal data with CSS an attacker needs to inject a whole stylesheet. Here the researcher shows that even a single style attribute is enough. The style reads an attribute on the page (like a username), compares it against guessed values, and loads an image from a different address depending on which guess matched, so the attacker's server learns the value.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.