Closed Bug 2059207 Opened 4 months ago Closed 3 months ago

No-Vary-Search secondary cache lookup ignores the idExtension key dimension, defeating the cross-origin FETCH cache partition and disclosing capability-URL-gated response bodies cross-site

Categories

(Core :: Networking: Cache, defect, P1)

defect

Tracking

()

RESOLVED FIXED
155 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- unaffected
firefox-esr153 --- disabled
firefox153 --- disabled
firefox154 + fixed
firefox155 + fixed

People

(Reporter: tjr, Assigned: kershaw)

References

(Regression)

Details

(4 keywords, Whiteboard: [necko-triaged] [necko-priority-queue])

Attachments

(7 files, 2 external files, 1 obsolete file)

The HTTP cache's canonical entry key has the form A[~B]:C where B is the 'idExtension' (CacheEntry::HashingKey, netwerk/cache2/CacheEntry.cpp:297-324). nsHttpChannel assigns idExtension values to partition special load types within one cache context: POST id, 'TRR', 'HEAD', and — under the default-true pref network.fetch.cache_partition_cross_origin — 'FETCH' for cross-origin third-party fetch()/XHR (netwerk/protocol/http/nsHttpChannel.cpp:5119-5141). The exact-key lookup in CacheStorageService::AddStorageEntry uses HashingKey("", aIdExtension, aURI, ...) (netwerk/cache2/CacheStorageService.cpp:1640), but the No-Vary-Search secondary lookup that runs on an exact-key miss (CacheStorageService.cpp:1693-1735, gated on default-true network.cache.no_vary_search) selects candidates from an index keyed only by URL base path and accepts any candidate passing URLsAreEquivalentModuloVariationConfig (netwerk/base/NoVarySearchUtils.cpp:162-229). It never compares the candidate's idExtension with the incoming aIdExtension, so a lookup in one idExtension partition can be satisfied by an entry cached in a different partition of the same context.

The demonstrated security effect defeats the FETCH partition: a victim iframe primes the cache with an anonymous CORS script load of a capability-URL API response (idExtension "") carrying Cache-Control: max-age, No-Vary-Search: params, and Access-Control-Allow-Origin: *. An attacker iframe — cross-site to the API origin — issues an uncredentialed third-party fetch() to the API's bare base path (no token). Its exact key '~FETCH,:URL' misses, but the NVS lookup matches the victim's entry because 'No-Vary-Search: params' makes all query parameters (including the secret token) irrelevant to equivalence. The attacker reads the token-gated JSON body without knowing the token and without its request reaching the server. A control fetch to an identically-primed endpoint without the NVS header went to the network and returned only public data, showing the attacker could not otherwise obtain the secret. Reproduced on a clean, unpatched ASAN build; the proof string POC-CONFIRMED with the secret appeared in stderr, and the server request log contained no tokenless /secret_api request.

Scope notes recorded for triage: cache contexts (OriginAttributes/partitionKey, anonymous flag) are still respected — the NVS candidate table is per-contextKey — so the leak requires attacker and victim widget to be embedded under the same top-level site and the victim's priming load to be anonymous/uncredentialed. In the PoC the attacker and victim iframes share the host 127.0.0.1 (the harness PAC allows only two hostnames); this does not affect the mechanism because none of the involved key dimensions (partitionKey, foreign-by-ancestor bit, anonymous flag, idExtension) depend on the frames' own hosts, only on their relation to the top-level page and to the API origin. The response as served is CORS-readable (ACAO: *), but its access control is the URL capability token; the bug hands the token-gated body to a party that never presented the token, bypassing the partition Firefox specifically maintains to keep third-party fetches from consuming cache entries created by other load types. The same omission also collapses the POST-id, TRR, and HEAD partitions.

Build Info

Affected Code

File: netwerk/cache2/CacheStorageService.cpp, line 1639-1641

  nsAutoCString entryKey;
  rv = CacheEntry::HashingKey(""_ns, aIdExtension, aURI, entryKey);
  NS_ENSURE_SUCCESS(rv, rv);  // exact lookup key INCLUDES the idExtension ("~FETCH,:URL")

File: netwerk/cache2/CacheStorageService.cpp, line 1693-1731

    if (StaticPrefs::network_cache_no_vary_search() && !entryExists &&
        !(aFlags & nsICacheStorage::OPEN_TRUNCATE)) {
      ...
        auto candidates = entries->mNoVarySearchIndex.Lookup(basePath);
        if (candidates) {
          for (const auto& fullKey : *candidates) {   // fullKey may belong to a DIFFERENT idExtension partition
            RefPtr<CacheEntry> candidate;
            if (!entries->Get(fullKey, getter_AddRefs(candidate))) continue;
            ...
            auto data = ParseNoVarySearchHeader(nvsVal);
            if (URLsAreEquivalentModuloVariationConfig(incomingURI,
                                                       candidateURI, data)) {
              // MATCH: only URL equivalence is checked; aIdExtension is never
              // compared against the candidate key's idExtension component
              entry = candidate;
              entryExists = true;
              break;
            }

File: netwerk/protocol/http/nsHttpChannel.cpp, line 5128-5141

  bool isThirdParty = false;
  if (StaticPrefs::network_fetch_cache_partition_cross_origin() &&
      (NS_FAILED(mLoadInfo->TriggeringPrincipal()->IsThirdPartyChannel(
           this, &isThirdParty)) ||
       isThirdParty) &&
      (mLoadInfo->InternalContentPolicyType() == nsIContentPolicy::TYPE_FETCH ||
       ... TYPE_XMLHTTPREQUEST ...)) {
    mCacheIdExtension.Append("FETCH");  // partition meant to isolate third-party fetch lookups
  }

File: netwerk/cache2/CacheEntry.cpp, line 559-570

  // Populate mNoVarySearchIndex now that mLock is released.
  if (!nvsVal.IsEmpty()) {
    ...
        NS_SUCCEEDED(HashingKey(""_ns, mEnhanceID, mURI, entryKey))) {
      if (auto* svc = CacheStorageService::Self()) {
        svc->NoteNoVarySearchEntry(mStorageID, basePath, entryKey);  // index is keyed by base path only
      }
    }
  }

The exact-key path partitions entries by idExtension, but the No-Vary-Search fallback indexes and matches entries by base path + query-equivalence only, so a '~FETCH' lookup is satisfied by an idExtension-"" entry whose No-Vary-Search rule ('params') declares the secret query parameter irrelevant.

Exploit Chain

  1. A victim widget (cross-site iframe under top-level site T) loads a capability-URL API resource from site S anonymously, e.g. <script crossorigin="anonymous" src="https://S/secret_api?token=SECRET">. The response is cacheable and carries No-Vary-Search: params and Access-Control-Allow-Origin: *. It is cached with idExtension "" under context (partitionKey=T, foreign, anonymous).
  2. The JSON body is not valid JavaScript, so the script load exposes nothing; a third-party fetch() is the only content-readable path to the body, and that path is partitioned into the '~FETCH' idExtension by nsHttpChannel.cpp:5128-5141.
  3. An attacker iframe (cross-site to T and to S) under the same top-level page issues an uncredentialed CORS fetch("https://S/secret_api") with no token. Its exact key '~FETCH,:https://S/secret_api' misses.
  4. The No-Vary-Search secondary lookup (CacheStorageService.cpp:1693-1735) finds the victim's idExtension-"" entry via the base-path index; 'params' equivalence ignores the token parameter; the entry is returned as a cache hit without any idExtension comparison.
  5. The cached ACAO: * passes the attacker's CORS check; the attacker reads the token-gated response body (and headers) without knowing the token and without any request reaching the server.

Steps to Reproduce

  1. Build Firefox ASAN from a clean tree (mozconfig.linux.asan.fuzzing); no source patch is required.
  2. Start the helper HTTP server: python3 external_services/nvs_server.py (serves ports 8952/8953; /secret_api returns the secret JSON only when token=SECRET_TOKEN_77f2, with Cache-Control: max-age=3600, No-Vary-Search: params, Access-Control-Allow-Origin: *; /no_nvs_api is identical minus the No-Vary-Search header; /log returns the request log).
  3. Run testcase.html via browser_evaluator with prefs: browser.cache.disk.enable=true, browser.cache.memory.enable=true (restore stock cache defaults disabled by the fuzzing profile template), network.cache.no_vary_search=true (shipped default, set for documentation), network.http.rcwn.enabled=false (determinism of the server-log contrast), browser.dom.window.dump.enabled=true (logging).
  4. Observe in stderr: the attacker iframe's result containing secretBody {"secret": "USER_SECRET_c9d41e_for_token_holder"} with secretTokenSeen=yes; SERVER-LOG containing no tokenless /secret_api request but containing the tokenless /no_nvs_api control; and the line 'POC-CONFIRMED: USER_SECRET_c9d41e_for_token_holder ...'.

Security Impact

  • Severity: Moderate
  • Attacker capability: A web attacker whose iframe is embedded under the same top-level site as a victim widget can read, via the HTTP cache, the body and exposed headers of a capability-URL-gated cross-site response that the victim context fetched with a secret query-string token, without knowing the token — bypassing the cross-origin FETCH cache partition (network.fetch.cache_partition_cross_origin). The same keying omission collapses the HEAD/GET, cached-POST-id, and TRR idExtension partitions.
  • Preconditions: Target response must be cacheable, carry a No-Vary-Search header whose rule ignores the secret query parameter (e.g. 'params'), and be readable by anonymous CORS (Access-Control-Allow-Origin: *). Attacker and victim contexts must share the top-level cache partition (both embedded under the same top-level site, or both top-level) and the victim's priming load must be anonymous/uncredentialed, since OriginAttributes/anonymous cache contexts are still enforced. Credentialed (cookie-gated) responses are not exposed by this technique. All involved Firefox prefs are at shipped defaults.

ASAN Report

Non-crash information-disclosure finding (crashed: false expected). Proof captured from browser_evaluator logs.stderr on a clean unpatched ASAN build:

[Child 22651: Main Thread]: I/console log: "ATTACKER-IFRAME(http://127.0.0.1:8952): {\"type\":\"attack\",\"origin\":\"http://127.0.0.1:8952\",\"apiBase\":\"http://localhost:8952\",\"secretBody\":\"{\\\"secret\\\": \\\"USER_SECRET_c9d41e_for_token_holder\\\"}\",\"secretServedFor\":\"/secret_api?token=SECRET_TOKEN_77f2&nonce=1\",\"secretTokenSeen\":\"yes\",\"controlBody\":\"{\\\"secret\\\": \\\"PUBLIC_NO_TOKEN\\\"}\",\"controlServedFor\":\"/no_nvs_api\"}"
[Child 22618: Main Thread]: I/console log: "NVS-POC: SERVER-LOG=[\"GET /secret_api?token=SECRET_TOKEN_77f2&nonce=1\",\"GET /no_nvs_api?token=SECRET_TOKEN_77f2&nonce=1\",\"GET /no_nvs_api\"]"
[Child 22618: Main Thread]: I/console log: "POC-CONFIRMED: USER_SECRET_c9d41e_for_token_holder | attacker iframe (http://127.0.0.1:8952, cross-site to the top-level page and to the API, third-party fetch => cache idExtension=FETCH) read the token-gated JSON cached for the victim iframe (http://127.0.0.1:8953, anonymous script load => idExtension=empty) from http://localhost:8952 via the No-Vary-Search secondary lookup, without knowing the token and without its request reaching the server; the no-NVS control fetch hit the network and only obtained PUBLIC_NO_TOKEN"

The server log contains no tokenless /secret_api request: the attacker's fetch was served from the cache entry of a different idExtension partition, while the identically-primed no-NVS control fetch ('GET /no_nvs_api') reached the network and returned only public data.
Attached file crash_stack.txt —
Attached file nvs_server.py —
Attached patch fix.patch — — Splinter Review
Attached file prefs.json —
Attached file testcase.html —
Attached file verifier_verdict-0.md —
Attached file prefs.js —

This bug was filed automatically by an AI-powered security testing tool. The analysis, testcase, and any suggested patches were generated by an AI model and have NOT been verified by a human.

Please review all details carefully before triaging. The issue was confirmed by an independent verifier, but for non-ASAN issues, the verifier has been made less strict. Additionally, the root cause analysis and suggested fix may contain errors.

Group: core-security → network-core-security
Severity: -- → S3
Priority: -- → P1
Whiteboard: [necko-triaged] [necko-priority-queue]
Attached file (secure) (obsolete) —
Assignee: nobody → kershaw
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attached file (secure) —

:kershaw, please update all release status flags to reflect the affected/unaffected/disabled state correctly. Which branches (beta, release, and/or ESR) are affected by this flaw?

Flags: needinfo?(kershaw)
Pushed by valentin.gosu@gmail.com: https://github.com/mozilla-firefox/firefox/commit/1ad2adfbb763 https://hg.mozilla.org/integration/autoland/rev/e4fae9713b21 Honor idExtension partition in the No-Vary-Search cache lookup, r=necko-reviewers,jesup

The incorrect code was added in bug 2038008, and enabled for release in bug 2038013

Group: network-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch

Please add a Beta uplift request to this.

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Requests with No-Vary-Search might mistakenly use a cache entry from a differently partitioned jar.
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: yes
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing: -
  • Risk associated with taking this patch: low
  • Explanation of risk level: Makes sure not to match entries if they have different isolation keys (in this case the idExtension)
  • String changes made/needed?: none
  • Is Android affected?: yes
Attachment #9621982 - Flags: approval-mozilla-beta?
Flags: needinfo?(kershaw)
Attachment #9621982 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
QA Whiteboard: [sec] [uplift] [qa-triage-done-c155/b154]
Duplicate of this bug: 2060103
Duplicate of this bug: 2059656
Attachment #9619829 - Attachment is obsolete: true
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: