Compromised content process can inject ExtendableMessageEvents with spoofed same-origin source into any origin's ServiceWorker via unvalidated PBackground::PServiceWorker descriptor
Categories
(Core :: IPC, defect)
Tracking
()
People
(Reporter: bugmon, Unassigned)
Details
(5 keywords)
Attachments
(9 files)
PBackground::PServiceWorker is a child-constructed actor whose constructor argument, an IPCServiceWorkerDescriptor, is fully attacker-controlled. The parent (BackgroundParentImpl::RecvPServiceWorkerConstructor -> ServiceWorkerParent::Init -> ServiceWorkerProxy::InitOnMainThread) never validates the descriptor's PrincipalInfo against the sending content process — unlike sibling handlers such as RecvStorageActivity, which call BackgroundParent::ValidatePrincipalInfo. The proxy resolves swm->GetRegistration(descriptor.PrincipalInfo(), descriptor.Scope()) and reg->GetByDescriptor(descriptor), attaching the actor to ANY origin's live service-worker registration. Descriptor matching (ServiceWorkerDescriptor::Matches) requires only the worker id (a small parent-side global counter, brute-forcible), scope, script URL, and principal — all public or guessable facts about a victim site.
Once attached, PServiceWorker::PostMessage lets the compromised process deliver arbitrary structured-clone data together with an attacker-forged PostMessageSource (ClientInfoAndState). The parent forwards it verbatim: ServiceWorkerParent::RecvPostMessage -> ServiceWorkerProxy::PostMessage -> ServiceWorkerInfo::PostMessage, where ServiceWorkerManager::DetermineLifetimeForClient grants lifetime extension based on the forged window client, so the parent even spawns the victim's worker if it is not running. On the worker side, ServiceWorkerOp.cpp derives event.origin and event.source from the forged client info, so the ExtendableMessageEvent is indistinguishable from a message sent by a genuine same-origin, top-level window client of the victim site.
I independently reproduced this on a fresh ASAN build with a completely pristine parent process (the only patch is an XRE_IsContentProcess-guarded simulation of a compromised content process): a content process for site http://localhost:<port> delivered the payload "EVIL_CROSS_ORIGIN_INJECTION_FROM_http://localhost:36609" into the service worker of http://127.0.0.1:8899 (a different site, isolated in a different content process under Fission), with event.origin == "http://127.0.0.1:8899" and a WindowClient source URL of http://127.0.0.1:8899/victim.html. Real-world service workers act on postMessage commands (cache poisoning/writes, SKIP_WAITING, auth-token handoff, offline-page substitution), so this crosses the Fission site-isolation boundary and defeats the purpose of per-site process sandboxing for any origin that has a service worker.
Build Info
- Branch: main
- Revision: 3f0a76a52d496d01003b91cb2350557c1a9870a4
- Timestamp: 2026-07-10T16:32:00+00:00
Affected Code
File: ipc/glue/BackgroundParentImpl.cpp, line 1299-1310
already_AddRefed<PServiceWorkerParent>
BackgroundParentImpl::AllocPServiceWorkerParent(
const IPCServiceWorkerDescriptor&) {
return MakeAndAddRef<ServiceWorkerParent>();
}
IPCResult BackgroundParentImpl::RecvPServiceWorkerConstructor(
PServiceWorkerParent* aActor,
const IPCServiceWorkerDescriptor& aDescriptor) {
// NO BackgroundParent::ValidatePrincipalInfo(this, aDescriptor.principalInfo())
// check, unlike e.g. RecvStorageActivity at line 1282 in this same file.
dom::InitServiceWorkerParent(aActor, aDescriptor);
return IPC_OK();
}
File: dom/serviceworkers/ServiceWorkerProxy.cpp, line 33-52
void ServiceWorkerProxy::InitOnMainThread() {
AssertIsOnMainThread();
auto scopeExit = MakeScopeExit([&] { MaybeShutdownOnMainThread(); });
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
NS_ENSURE_TRUE_VOID(swm);
// mDescriptor is entirely child-supplied: the attacker chooses the
// PrincipalInfo and Scope, attaching to ANY origin's registration.
RefPtr<ServiceWorkerRegistrationInfo> reg =
swm->GetRegistration(mDescriptor.PrincipalInfo(), mDescriptor.Scope());
NS_ENSURE_TRUE_VOID(reg);
RefPtr<ServiceWorkerInfo> info = reg->GetByDescriptor(mDescriptor);
NS_ENSURE_TRUE_VOID(info);
scopeExit.release();
mInfo = new nsMainThreadPtrHolder<ServiceWorkerInfo>(
"ServiceWorkerProxy::mInfo", info);
}
File: dom/serviceworkers/ServiceWorkerDescriptor.cpp, line 133-138
bool ServiceWorkerDescriptor::Matches(
const ServiceWorkerDescriptor& aDescriptor) const {
// id is a small parent-side global counter (brute-forcible); scope,
// scriptURL and principal are public facts about the victim site.
return Id() == aDescriptor.Id() && Scope() == aDescriptor.Scope() &&
ScriptURL() == aDescriptor.ScriptURL() &&
PrincipalInfo() == aDescriptor.PrincipalInfo();
}
File: dom/serviceworkers/ServiceWorkerParent.cpp, line 29-34
IPCResult ServiceWorkerParent::RecvPostMessage(
StructuredCloneData* aData, const PostMessageSource& aSource) {
// aSource (ClientInfoAndState) is attacker-forged and forwarded verbatim.
mProxy->PostMessage(aData, aSource);
return IPC_OK();
}
File: dom/serviceworkers/ServiceWorkerInfo.cpp, line 281-306
void ServiceWorkerInfo::PostMessage(ipc::StructuredCloneData* aData,
const PostMessageSource& aSource) {
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
if (NS_WARN_IF(!swm)) {
return;
}
ServiceWorkerLifetimeExtension lifetime =
ServiceWorkerLifetimeExtension(NoLifetimeExtension{});
switch (aSource.type()) {
case PostMessageSource::TClientInfoAndState:
// Lifetime extension is granted based on the FORGED window client,
// so the parent will even spawn the victim's worker on demand.
lifetime = swm->DetermineLifetimeForClient(
ClientInfo(aSource.get_ClientInfoAndState().info()));
break;
...
}
mServiceWorkerPrivate->SendMessageEvent(aData, lifetime, aSource);
}
File: dom/serviceworkers/ServiceWorkerOp.cpp, line 1144-1186
PostMessageSource& ipcSource = args.source();
nsCString originSource;
switch (ipcSource.type()) {
case PostMessageSource::TClientInfoAndState:
// event.origin and event.source are computed from the FORGED
// client URL, spoofing a same-origin top-level WindowClient.
originSource = ipcSource.get_ClientInfoAndState().info().url();
init.mSource.SetValue().SetAsClient() =
new Client(sgo, ipcSource.get_ClientInfoAndState());
break;
...
nsCOMPtr<nsIPrincipal> principal =
BasePrincipal::CreateContentPrincipal(url, attrs);
...
result = principal->GetOriginNoSuffix(origin);
...
CopyUTF8toUTF16(origin, init.mOrigin);
The parent-side chain that trusts the child-forged descriptor end to end. Note the missing ValidatePrincipalInfo call in the PServiceWorker constructor handler, present in other PBackground handlers in the same file.
Exploit Chain
- Attacker achieves arbitrary code execution in any content process (e.g. via a renderer bug on an attacker-controlled site; simulated here by an XRE_IsContentProcess-guarded patch, with the parent left pristine).
- Attacker picks a victim origin that has a registered service worker (scope and script URL are public facts about the site; the victim's registration is live in the parent's ServiceWorkerManager whenever the victim site is or was recently in use).
- From the compromised content process, send PBackground::PServiceWorkerConstructor with a forged IPCServiceWorkerDescriptor containing the VICTIM's PrincipalInfo, scope, and script URL, brute-forcing the small global worker id counter (a handful of constructors, one per candidate id).
- The parent's BackgroundParentImpl::RecvPServiceWorkerConstructor performs no validation of the descriptor principal against the sending process; ServiceWorkerProxy::InitOnMainThread attaches the actor to the victim origin's live ServiceWorkerInfo.
- Send PServiceWorker::PostMessage with arbitrary structured-clone data and a forged PostMessageSource claiming to be a visible top-level WindowClient of the victim origin.
- ServiceWorkerParent::RecvPostMessage -> ServiceWorkerProxy::PostMessage -> ServiceWorkerInfo::PostMessage forwards the payload; DetermineLifetimeForClient grants lifetime extension for the forged client, so the parent spawns/extends the victim's service worker on demand.
- The victim's service worker (running in the victim origin's own content process) receives a trusted ExtendableMessageEvent whose event.origin is the victim's own origin and whose event.source is a plausible same-origin WindowClient (ServiceWorkerOp.cpp derives both from the forged client info).
- The victim service worker processes the attacker payload as a same-origin command — real-world SWs act on such messages for cache writes (persistent cache poisoning of the victim origin), SKIP_WAITING/update control, and auth/token handoff — crossing the Fission site-isolation boundary.
IPC Path
-
Forged PServiceWorker constructor
- Protocol: PServiceWorker
- Parent process: Main
- Child process: Content
- Message flow: Content -> Main (PBackground background thread): PServiceWorkerConstructor(IPCServiceWorkerDescriptor{victim principal/scope/scriptURL/id})
-
Forged PostMessage with spoofed source
- Protocol: PServiceWorker
- Parent process: Main
- Child process: Content
- Message flow: Content -> Main: PostMessage(ClonedOrErrorMessageData, PostMessageSource{forged victim-origin WindowClient ClientInfoAndState})
Steps to Reproduce
- Ensure a clean tree: git -C /firefox checkout .
- Apply the compromised-content-process simulation patch (content-process-only, XRE_IsContentProcess-guarded; parent code untouched): git -C /firefox apply compromised-child-simulation.patch
- Build with the ASAN fuzzing mozconfig (build_firefox with mozconfig.linux.asan.fuzzing).
- Place victim.html and sw.js in a directory and start the victim-origin server from it: sh serve_victim.sh & (serves http://127.0.0.1:8899, a different origin AND different site than the evaluator's http://localhost:<port>, hence a different content process under Fission).
- Load attack.html via browser_evaluator with prefs {"dom.serviceWorkers.enabled": true, "dom.serviceWorkers.testing.enabled": true} and a timeout of at least ~30-40s (the forge attempts fire at t+6s and t+12s after the victim tab registers its worker).
- Observe in the captured console logs: the victim-origin service worker (victim content process) relays the attacker payload EVIL_CROSS_ORIGIN_INJECTION_FROM_http://localhost:<port> with origin http://127.0.0.1:8899 and source WindowClient http://127.0.0.1:8899/victim.html — attacker data delivered cross-origin with spoofed same-origin provenance.
- Cleanup: git -C /firefox checkout . and kill the python3 http.server on port 8899.
Security Impact
- Severity: High
- Attacker capability: From any single compromised content process, inject arbitrary trusted ExtendableMessageEvents into the service worker of every origin that has a live service-worker registration, with event.origin and event.source spoofed as a same-origin top-level window client. This defeats Fission site isolation for message-driven SW logic: persistent cache poisoning of victim origins (serving attacker content for victim URLs offline/online), triggering privileged SW commands (SKIP_WAITING, cache writes, sync/auth token handoff), and potentially exfiltrating data the SW replies with. The parent also spawns the victim's worker on the attacker's behalf via forged lifetime extension.
- Preconditions: Attacker needs arbitrary code execution in one content process (renderer compromise). The victim origin must have a service-worker registration live in the parent's ServiceWorkerManager, and the attacker must know/guess the victim SW's scope and script URL (public) and brute-force the small global worker-id counter (a few IPC round-trips).
ASAN Report
No sanitizer crash — this is a parent-side logic/privilege vulnerability with no memory corruption; evidence is the observable cross-origin effect, independently reproduced by the verifier on a fresh clean ASAN build (parent process pristine; only the XRE_IsContentProcess-guarded child-side simulation patch applied). Verifier's own browser_evaluator run (attacker content process Child 36455 at http://localhost:36609; victim content process Child 36489 at http://127.0.0.1:8899):
[Child 36455: Main Thread]: I/console log: "ATTACKER: attacker at http://localhost:36609/attack.html"
[Child 36489: Main Thread]: I/console log: "VICTIM: registered scope=http://127.0.0.1:8899/"
[Child 36489: Main Thread]: I/console log: "VICTIM: relay-from-SW: {\"data\":\"legit-hello-from-victim-page\",\"origin\":\"http://127.0.0.1:8899\",\"source\":{\"ctor\":\"WindowClient\",\"url\":\"http://127.0.0.1:8899/victim.html\"}}"
[Child 36455: Main Thread]: I/console log: "ATTACKER: sending forged PServiceWorker IPC from attacker process (origin http://localhost:36609) attempt=t+6s"
[Child 36455: Main Thread]: I/console log: "ATTACKER: forge trigger done (AbortError)"
[Child 36489: Main Thread]: I/console log: "VICTIM: relay-from-SW: {\"data\":\"EVIL_CROSS_ORIGIN_INJECTION_FROM_http://localhost:36609\",\"origin\":\"http://127.0.0.1:8899\",\"source\":{\"ctor\":\"WindowClient\",\"url\":\"http://127.0.0.1:8899/victim.html\"}}"
[Child 36455: Main Thread]: I/console log: "ATTACKER: sending forged PServiceWorker IPC from attacker process (origin http://localhost:36609) attempt=t+12s"
[Child 36489: Main Thread]: I/console log: "VICTIM: relay-from-SW: {\"data\":\"EVIL_CROSS_ORIGIN_INJECTION_FROM_http://localhost:36609\",\"origin\":\"http://127.0.0.1:8899\",\"source\":{\"ctor\":\"WindowClient\",\"url\":\"http://127.0.0.1:8899/victim.html\"}}"
The attacker's payload arrived in the victim origin's service worker (a different site and content process) with event.origin spoofed to the victim's own origin and a forged same-origin top-level WindowClient as event.source.
| Reporter | ||
Comment 1•4 months ago
|
||
| Reporter | ||
Comment 2•4 months ago
|
||
| Reporter | ||
Comment 3•4 months ago
|
||
| Reporter | ||
Comment 4•4 months ago
|
||
| Reporter | ||
Comment 5•4 months ago
|
||
| Reporter | ||
Comment 6•4 months ago
|
||
| Reporter | ||
Comment 7•4 months ago
|
||
| Reporter | ||
Comment 8•4 months ago
|
||
| Reporter | ||
Comment 9•4 months ago
|
||
Updated•4 months ago
|
Comment 11•3 months ago
|
||
I think this is the same bug as bug 2054674, as both are related to insufficient validation in the ServiceWorker constructor.
Updated•2 months ago
|
Updated•13 days ago
|
Description
•