Closed Bug 2059217 Opened 4 months ago Closed 4 months ago

Remote Settings content-signature bypass: verifier promise rejection skips the InvalidSignatureError-gated rollback in RemoteSettingsClient._importChanges

Categories

(Firefox :: Remote Settings Client, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 2056571

People

(Reporter: tjr, Unassigned)

Details

(Keywords: ai-involved, sec-moderate, testcase)

Attachments

(6 files)

RemoteSettingsClient._importChanges() (services/settings/RemoteSettingsClient.sys.mjs) writes untrusted server records, metadata, and timestamp into the local database via db.importChanges() before validating the collection content signature. If validateCollectionSignature() then fails, all rollback (db.clear(), restore of previous data or packaged dump) is executed only when the error is an InvalidSignatureError; any other error is rethrown with the imported data left in place (lines 1229-1232). validateCollectionSignature() awaits nsIContentSignatureVerifier.asyncVerifyContentSignature() without converting promise rejections: in security/manager/ssl/ContentSignatureVerifier.cpp, only NS_ERROR_INVALID_SIGNATURE is mapped to resolve(false); other failures (e.g. a non-parseable-PEM x5u chain, which ReadChainIntoCertList maps to NS_ERROR_FAILURE) reject the promise with a plain nsresult exception. Because the attacker controls the signature metadata and the x5u body, a compromised Remote Settings server/CDN or TLS MITM — the attacker content signatures exist to stop — can deliberately choose a rejection-typed failure, so its unsigned records stay live. get() serves stored records without verification by default (the verifySignature option defaults to false), and on subsequent polls maybeSync() sees the attacker-set timestamp equal to the server timestamp and takes the up-to-date path, which re-validates only when local metadata is empty — the attacker-imported metadata is non-empty, so the poisoned state is treated as canonical with no re-verification. Demonstrated end-to-end on Linux with a local malicious server: two unsigned attacker records for main/websites-with-shared-credential-backends were imported, verification rejected with NS_ERROR_FAILURE, no rollback ran, a second poll 30s later did not re-fetch or re-verify the collection, and the parent process served the poisoned records to the password manager's related-realms consumer (attacker-controlled filter_expression sentinel evaluated by the JEXL filter in the parent).

Build Info

Affected Code

File: services/settings/RemoteSettingsClient.sys.mjs, line 1210-1233

    await this.db.importChanges(metadata, remoteTimestamp, remoteRecords, {
      clear: retry,
    });   // <-- untrusted data persisted BEFORE verification
    ...
    if (this.verifySignature) {
      try {
        await this.validateCollectionSignature(
          newRecords,
          remoteTimestamp,
          metadata
        );
      } catch (e) {
        ...
        if (!(e instanceof InvalidSignatureError)) {
          // If it failed for any other kind of error (eg. shutdown)
          // then give up quickly.
          throw e;   // <-- no db.clear(), no restore: imported records stay
        }
        // (db.clear() / dump restore only below, i.e. only for InvalidSignatureError)

File: services/settings/RemoteSettingsClient.sys.mjs, line 1099-1117

      const certChain = await (await lazy.Utils.fetch(x5u)).text();
      ...
      if (
        await this._verifier.asyncVerifyContentSignature(   // <-- bare await; a promise
          serialized,                                        //     rejection propagates as a
          "p384ecdsa=" + signature,                          //     plain nsresult exception,
          certChain,                                         //     NOT InvalidSignatureError
          this.signerName,
          lazy.Utils.CERT_CHAIN_ROOT_IDENTIFIER
        )
      ) {
        return;
      }
      thrownErrors.push(
        new InvalidSignatureError(this.identifier, x5u, this.signerName)
      );

File: security/manager/ssl/ContentSignatureVerifier.cpp, line 111-147, 188-192

nsresult VerifyContentSignatureTask::CalculateResult() {
  ...
  if (NS_FAILED(rv)) {
    ...
    if (rv == NS_ERROR_INVALID_SIGNATURE) {
      return NS_OK;             // -> resolve(false) -> InvalidSignatureError in JS
    }
    return rv;                  // -> promise REJECTED with raw nsresult
  }
  ...
}
void VerifyContentSignatureTask::CallCallback(nsresult rv) {
  if (NS_FAILED(rv)) {
    mPromise->MaybeReject(rv);
  } else {
    mPromise->MaybeResolve(mSignatureVerified);
  }
}
// ReadChainIntoCertList():
  if (inBlock || !certFound) {
    // the PEM data did not end; bad data.
    return NS_ERROR_FAILURE;    // attacker-chosen: non-PEM x5u body
  }

File: services/settings/RemoteSettingsClient.sys.mjs, line 772-801

        if (expectedTimestamp == collectionLastModified) {
          lazy.console.debug(`${this.identifier} local data is up-to-date`);
          ...
          // signature re-validation only if local metadata is EMPTY; the
          // attacker-imported metadata is non-empty, so the tampered state
          // is accepted with no re-verification
          if (this.verifySignature && lazy.ObjectUtils.isEmpty(localMetadata)) {
            ...
          }
          if (!importedFromDump.length) {
            return;
          }

Verify-after-write with an error-type-gated rollback. The attacker controls both the signature metadata and the x5u body served for verification, so the attacker chooses whether verification fails via resolve(false) (InvalidSignatureError, rollback runs) or via promise rejection (raw nsresult, rollback skipped). get() serves stored records with verification defaulting to off (RemoteSettingsClient.sys.mjs:455, :615), and later polls take the up-to-date fast path without re-verifying.

Exploit Chain

  1. Attacker occupies the Remote Settings server position (compromised server/CDN or TLS MITM — the attacker content signatures are designed to stop; simulated here with the services.settings.server override, which non-release builds honor by design, Utils.sys.mjs:54-57).
  2. The periodic Remote Settings poll fetches the monitor/changes changeset; the attacker advertises a new timestamp for a target collection (demonstrated: main/websites-with-shared-credential-backends, whose client is auto-instantiated because a packaged dump exists).
  3. maybeSync() -> _importChanges() fetches the attacker changeset and persists the attacker records, metadata, and timestamp via db.importChanges() (RemoteSettingsClient.sys.mjs:1210) before verification.
  4. validateCollectionSignature() fetches the attacker's x5u URL; the body is deliberately not parseable PEM, so ReadChainIntoCertList() returns NS_ERROR_FAILURE and asyncVerifyContentSignature() rejects its promise instead of resolving false (ContentSignatureVerifier.cpp:128-131, 188-192).
  5. The rejection is not an InvalidSignatureError, so _importChanges rethrows at lines 1229-1232 without db.clear() or restore: the unsigned attacker records remain in the local database. The poll records a sync error but performs no cleanup.
  6. On the next poll, the attacker-set local timestamp equals the advertised server timestamp; maybeSync() takes the up-to-date path (line 772) and does not re-fetch or re-verify because local metadata is non-empty (observed: second poll issued no collection changeset request).
  7. Consumers read the poisoned collection via client.get(), which serves stored records without signature verification by default (verifySignature defaults false, double-gated at line 615). Demonstrated: LoginRelatedRealmsParent.getSharedCredentialsCollection() -> get() served the attacker records in the parent process; the attacker-controlled filter_expression sentinel was evaluated by the parent's JEXL filter (_filterEntries), and the poisoned relatedRealms data fed the password manager's related-logins lookup.

Steps to Reproduce

  1. Build Firefox ASAN from a clean tree (mozconfig.linux.asan.fuzzing).
  2. Start the provided malicious Remote Settings server: python3 external_services/rs_attack_server.py (listens on 127.0.0.1:38251; serves a changeset with 2 unsigned records for main/websites-with-shared-credential-backends, signature metadata pointing at a garbage /chain.pem).
  3. Run testcase.html under browser_evaluator with timeout 100 and prefs: services.settings.server=http://127.0.0.1:38251/v1, services.settings.poll_interval=1, app.update.timerFirstInterval=10000, app.update.timerMinimumDelay=30 (accelerate the poll timer), signon.relatedRealms.enabled=true (enables the demonstration consumer), plus logging prefs (services.settings.loglevel=all, devtools.console.stdout.chrome=true, browser.dom.window.dump.enabled=true, signon.debug=true).
  4. Observe in parent-process stderr: the sync error carrying the attacker changeset entry (no rollback), then ~30s later the sentinel 'CLAUDITOR_PROOF_UNSIGNED_RS_DATA_SERVED((' evaluated by mozjexl for main/websites-with-shared-credential-backends when the login form triggers LoginRelatedRealmsParent -> client.get().
  5. Observe in /tmp/rs_attack/server.log: collection changeset fetched once, /chain.pem fetched once, and the subsequent poll fetching only the monitor changeset (no re-fetch/re-verify of the poisoned collection).

Security Impact

  • Severity: Moderate
  • Attacker capability: An attacker in the Remote Settings server/CDN/TLS-MITM position can defeat the content-signature mitigation for any syncable collection handled by RemoteSettingsClient: unsigned, attacker-controlled records are persisted in the local database, served to parent-process consumers via get() without verification (demonstrated with the password manager's related-realms collection, which influences credential lookup), and treated as up-to-date by subsequent polls, so the poisoning is durable and is not corrected by later syncs.
  • Preconditions: Attacker must control the Remote Settings server, its CDN, or hold a TLS MITM position for the Remote Settings origin (the exact adversary content signatures are designed to stop). The demonstration used the services.settings.server override, which non-release builds honor by design; on release the equivalent position requires infrastructure or TLS compromise. The demonstrated password-manager consumer additionally required signon.relatedRealms.enabled=true (default false); the signature bypass and durable poisoning themselves are independent of that pref, and get() serves unverified data to all consumers by default.

ASAN Report

Non-crash finding (signature bypass); evidence is parent-process stderr from an unmodified build plus the malicious-server request log.

Parent stderr (verified run):
[Parent 5358: Main Thread]: E/console error: ({details:{id:"deadbeef-0000-0000-0000-000000000000", host:"127.0.0.1", last_modified:1719000000000, bucket:"main", collection:"websites-with-shared-credential-backends"}})   <- poll error after verifier promise rejection; no rollback ran
[Parent 5358: Main Thread]: E/console error: (new Error("Token ( (openParen) unexpected in expression: CLAUDITOR_PROOF_UNSIGNED_RS_DATA_SERVED(", "resource://gre/modules/components-utils/mozjexl.sys.mjs", 1)) "Full expression: CLAUDITOR_PROOF_UNSIGNED_RS_DATA_SERVED((" "main/websites-with-shared-credential-backends"   <- persisted unsigned attacker record served by client.get() and evaluated in the parent

Server request log:
21:03:21 GET /v1/buckets/monitor/collections/changes/changeset?_expected=0
21:03:22 GET /v1/buckets/main/collections/websites-with-shared-credential-backends/changeset?_expected=1719000000000   <- attacker records + malformed signature metadata imported
21:03:22 GET /chain.pem   <- garbage PEM: ReadChainIntoCertList -> NS_ERROR_FAILURE -> promise rejected -> rollback skipped
21:03:52 GET /v1/buckets/monitor/collections/changes/changeset?_expected=0   <- second poll: collection changeset NOT re-fetched; up-to-date fast path, no re-verification
Attached file crash_stack.txt —
Attached file rs_attack_server.py —
Attached patch fix.patch — — Splinter Review
Attached file prefs.json —
Attached file testcase.html —
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.

Status: UNCONFIRMED → RESOLVED
Closed: 4 months ago
Duplicate of bug: CVE-2026-74942
Resolution: --- → DUPLICATE
Group: core-security → firefox-core-security
Group: firefox-core-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: