Closed Bug 2044594 Opened 5 months ago Closed 5 months ago

Web Lock cross-origin disclosure and force-steal from a compromised content process via missing principal validation in RecvPLockManagerConstructor

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 2054671

People

(Reporter: lorenzoauto311, Unassigned)

Details

(Keywords: reporter-external, Whiteboard: [client-bounty-form])

Summary

The Web Locks IPC constructor PLockManager carries a content-supplied nsIPrincipal naming the origin whose locks are being managed. In the parent process, BackgroundParentImpl::RecvPLockManagerConstructor performs exactly one check on that principal: it rejects the system principal when the actor comes from a content process. It never verifies that the supplied content principal could legitimately be loaded by the sending content process. There is no call to ValidatePrincipalCouldPotentiallyBeLoadedBy.

A compromised content process confined to one origin (for example webIsolated=https://evil.example) forges a principal for any other origin (for example https://bank.example), and it is admitted. The parent then keys a process global map (sManagedLocksMap in dom/locks/LockManagerParent.cpp) by that forged principal. The key comparison is BasePrincipal::FastEquals (origin and origin suffix equality), so the forged principal lands in the genuine victim's shared ManagedLocks bucket. From there the attacker reads and seizes the victim origin's Web Locks.

Root cause

ipc/glue/BackgroundParentImpl.cpp:1445 is the only gate, and it checks the wrong thing:

mozilla::ipc::IPCResult BackgroundParentImpl::RecvPLockManagerConstructor(
    PLockManagerParent* aActor, mozilla::NotNull<nsIPrincipal*> aPrincipalInfo,
    const Maybe<nsID>& aClientId) {
  AssertIsInMainProcess();
  AssertIsOnBackgroundThread();
  MOZ_ASSERT(aActor);

  // If the IsOtherProcessActor is true, then we're dealing with some kind of
  // content process, and we do not expect the system principal to send this
  // kind of constructor message.
  if (aPrincipalInfo->IsSystemPrincipal() &&
      BackgroundParent::IsOtherProcessActor(this)) {
    return IPC_FAIL_NO_REASON(this);
  }

  return IPC_OK();
}

The handler rejects only the system principal from a content process. A content process supplying a content principal for an origin it does not own passes unconditionally: IsSystemPrincipal() is false, so the only check is skipped and the result is IPC_OK.

The same file already validates this correctly on a sibling handler

RecvCreateMLSTransaction at ipc/glue/BackgroundParentImpl.cpp:1207 does it right:

RefPtr<ThreadsafeContentParentHandle> parent =
    BackgroundParent::GetContentParentHandle(this);
if (parent && !dom::ValidatePrincipalCouldPotentiallyBeLoadedBy(
                  aPrincipal, parent->GetRemoteType(), {})) {
  dom::ContentParent::LogAndAssertFailedPrincipalValidationInfo(aPrincipal, __func__);
  return IPC_FAIL(this, "Principal validation failed");
}

That validation was added by Bug 2020535 (commit 297025166caa, 2026-05-14, "Enforce principal validation for MLS IPC"). The same fix was added to FetchParent::RecvFetchOp by Bug 2025183 (dom/fetch/FetchParent.cpp:119). The Web Lock constructor takes a content nsIPrincipal for the very same purpose (origin identity for a parent side per origin resource) but is not converted. It is the remaining unvalidated sibling.

The principal is rebuilt from content bytes with no process check

dom/ipc/PermissionMessageUtils.cpp:27:

bool ParamTraits<nsIPrincipal*>::Read(IPC::MessageReader* aReader,
                                      RefPtr<nsIPrincipal>* aResult) {
  mozilla::Maybe<mozilla::ipc::PrincipalInfo> info;
  if (!ReadParam(aReader, &info)) { return false; }
  if (info.isNothing()) { return true; }
  auto principalOrErr = PrincipalInfoToPrincipal(info.ref());   // rebuilds any origin
  if (NS_WARN_IF(principalOrErr.isErr())) { return false; }
  nsCOMPtr<nsIPrincipal> principal = principalOrErr.unwrap();
  *aResult = principal;
  return true;
}

Validating that the rebuilt principal matches the sending process is, by design, the handler's job. RecvPLockManagerConstructor does not do it.

Sink 1: the constructor buckets by the forged principal

dom/locks/LockManagerParent.cpp:18 and :23:

static StaticAutoPtr<nsTHashMap<PrincipalHashKey, WeakPtr<ManagedLocks>>>
    sManagedLocksMap;                                  // process global

LockManagerParent::LockManagerParent(NotNull<nsIPrincipal*> aPrincipal, ...) {
  ...
  mManagedLocks = sManagedLocksMap->Get(aPrincipal);   // join existing bucket
  if (!mManagedLocks) {
    mManagedLocks = new ManagedLocks();
    sManagedLocksMap->LookupOrInsert(aPrincipal, mManagedLocks);
  }
}

The map key is PrincipalHashKey, whose KeyEquals is BasePrincipal::FastEquals (origin equality, caps/PrincipalHashKey.h:34 and caps/BasePrincipal.h). A forged content principal carrying the victim's origin compares equal to the victim's genuine principal, so sManagedLocksMap->Get(aPrincipal) returns the victim's existing ManagedLocks object. The attacker's LockManagerParent now shares the victim's held lock array and per name queues.

Sink 2: RecvQuery discloses the bucket

dom/locks/LockManagerParent.cpp:115:

IPCResult LockManagerParent::RecvQuery(QueryResolver&& aResolver) {
  LockManagerSnapshot snapshot;
  ...
  for (const RefPtr<LockRequestParent>& request : mManagedLocks->mHeldLocks) {
    LockInfo info;
    info.mMode.Construct(request->Data().lockMode());
    info.mName.Construct(request->Data().name());     // victim lock name
    info.mClientId.Construct(
        static_cast<LockManagerParent*>(request->Manager())->mClientId);  // victim clientId
    ...
  }
  aResolver(snapshot);
  return IPC_OK();
}

mManagedLocks is the shared victim bucket, so the attacker receives the victim origin's held and pending lock names, modes, and clientIds.

Sink 3: RecvPLockRequestConstructor with steal force-releases the victim's held lock

dom/locks/LockManagerParent.cpp:150:

IPCResult LockManagerParent::RecvPLockRequestConstructor(
    PLockRequestParent* aActor, const IPCLockRequest& aRequest) {
  ...
  if (aRequest.steal()) {
    mManagedLocks->mHeldLocks.RemoveElementsBy(
        [&aRequest](const RefPtr<LockRequestParent>& aHeld) {
          if (aHeld->Data().name() == aRequest.name()) {
            (void)NS_WARN_IF(!PLockRequestParent::Send__delete__(aHeld, true));  // releases victim
            return true;
          }
          return false;
        });
    queue.InsertElementAt(0, actor);                 // attacker jumps the queue
  }
  ProcessRequestQueue(queue);
  return IPC_OK();
}

steal removes every held lock with the matching name from the shared bucket regardless of which actor holds it, and Send__delete__(aHeld, true) is dispatched against the victim's LockRequestParent. The victim's lock callback resolves as aborted, releasing the lock under the victim mid critical section. The attacker is then granted the lock and never releases it.

Steps to reproduce

From a compromised content process (the standard sandbox escape threat model, the same model under which Bug 2014101 / CVE-2026-2768 was rated sec-high):

  1. The attacker process is confined to webIsolated=https://evil.example. The victim https://bank.example is open in another process and holds an exclusive Web Lock named idb-sync guarding its IndexedDB critical section.
  2. Attacker obtains its PBackgroundChild via BackgroundChild::GetOrCreateForCurrentThread() (the same call the legitimate code uses at dom/locks/LockManager.cpp:64).
  3. Attacker sends PBackground::PLockManager with a forged ContentPrincipalInfo for https://bank.example (origin attributes matching the victim) and any clientId. PLockManager is parent directed and PBackground is ChildProc=anydom, so it is reachable.
  4. Parent ParamTraits<nsIPrincipal*>::Read rebuilds the live bank.example principal. RecvPLockManagerConstructor sees IsSystemPrincipal() is false, so the only gate is skipped and the result is IPC_OK. AllocPLockManagerParent builds a LockManagerParent with the forged principal.
  5. The constructor calls sManagedLocksMap->Get(forgedPrincipal), matches the genuine bank.example entry by FastEquals, and the attacker now shares the victim's ManagedLocks bucket.
  6. Disclosure: attacker sends Query(), which returns the victim origin's held and pending lock names, modes, and clientIds.
  7. Integrity and denial of service: attacker sends PLockRequest with IPCLockRequest { name: "idb-sync", lockMode: Exclusive, ifAvailable: false, steal: true }. The parent force-releases the victim's held idb-sync lock and grants it to the attacker, who holds it indefinitely.

Why a plain web page is not enough: the JS navigator.locks path always sends the caller's own principal (dom/locks/LockManager.cpp:50), so the cross-origin forgery requires crafting the PLockManager IPC directly. This is the same reason the IndexedDB sandbox escape Bug 2014101 (CVE-2026-2768) was demonstrated from a compromised content process rather than a web page.

Proof of concept: a parent process GTest is attached (TestLockManagerCrossOriginForgery.cpp, for dom/locks/test/gtest/). It builds a principal from a forged ContentPrincipalInfo for the victim origin and shows it FastEquals the genuine victim principal, so sManagedLocksMap buckets the attacker with the victim. The state mutating steal assertion is left commented out for safety.

Content reachability (IPDL)

  • ipc/glue/PBackground.ipdl:83 declares the protocol with ChildProc=anydom, so any DOM content process can open PBackground.
  • ipc/glue/PBackground.ipdl:108 manages PLockManager.
  • ipc/glue/PBackground.ipdl:295 in the parent: block declares async PLockManager(nsIPrincipal aPrincipalInfo, nsID? aClientId).
  • dom/locks/PLockManager.ipdl declares parent directed async Query() and async PLockRequest(IPCLockRequest aRequest).

Suggested fix

Mirror the landed MLS fix (Bug 2020535) in RecvPLockManagerConstructor:

mozilla::ipc::IPCResult BackgroundParentImpl::RecvPLockManagerConstructor(
    PLockManagerParent* aActor, mozilla::NotNull<nsIPrincipal*> aPrincipalInfo,
    const Maybe<nsID>& aClientId) {
  AssertIsInMainProcess();
  AssertIsOnBackgroundThread();
  MOZ_ASSERT(aActor);

  if (aPrincipalInfo->IsSystemPrincipal() &&
      BackgroundParent::IsOtherProcessActor(this)) {
    return IPC_FAIL_NO_REASON(this);
  }

  RefPtr<ThreadsafeContentParentHandle> parent =
      BackgroundParent::GetContentParentHandle(this);
  if (parent && !dom::ValidatePrincipalCouldPotentiallyBeLoadedBy(
                    aPrincipalInfo, parent->GetRemoteType(), {})) {
    dom::ContentParent::LogAndAssertFailedPrincipalValidationInfo(aPrincipalInfo, __func__);
    return IPC_FAIL(this, "LockManager principal not allowed for remote type");
  }

  return IPC_OK();
}

GetContentParentHandle(this) returns null for a same process actor, so the existing system principal path for in parent module loading (Bug 1908002) is preserved. Validation is applied only to genuine content actors.

Actual results

The parent admits the forged cross-origin principal and buckets the attacker's LockManager with the victim origin's locks. Query returns the victim origin's lock names, modes, and clientIds. steal releases the victim's genuinely held lock and grants it to the attacker.

Expected results

RecvPLockManagerConstructor should reject a content principal that the sending process could not load, by calling ValidatePrincipalCouldPotentiallyBeLoadedBy and returning IPC_FAIL, exactly as RecvCreateMLSTransaction (Bug 2020535) and FetchParent::RecvFetchOp (Bug 2025183) already do.

Impact

  • Cross-origin disclosure of another origin's held and pending Web Lock names, modes, and clientIds. A same origin policy break in the unsandboxed parent.
  • Cross-origin force-release of another origin's held lock via steal, breaking that origin's mutual exclusion in the middle of a critical section, then denying the lock to the victim indefinitely.
  • Reachable from any content process. Web Locks is enabled by default on desktop and Android.
Flags: sec-bounty?
Group: firefox-core-security → dom-core-security
Component: Security → DOM: Content Processes
Product: Firefox → Core
Status: UNCONFIRMED → RESOLVED
Closed: 5 months ago
Component: DOM: Content Processes → DOM: Core & HTML
Duplicate of bug: 2032370
Resolution: --- → DUPLICATE
Flags: sec-bounty? → sec-bounty-
Duplicate of bug: 2054671
No longer duplicate of bug: 2032370
Group: dom-core-security
You need to log in before you can comment on or make changes to this bug.