Closed Bug 2057382 Opened 3 months ago Closed 3 months ago

Notification parent cross-origin scope confusion — attacker-dispatched `notificationclick` / `notificationclose` event injection into victim origin's active service worker with attacker-controlled payload

Categories

(Core :: DOM: Notifications, defect, P3)

Firefox 154
defect

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 --- wontfix
firefox-esr153 155+ fixed
firefox153 --- wontfix
firefox154 --- wontfix
firefox155 + fixed
firefox156 + fixed

People

(Reporter: bugzilla.backwater968, Assigned: saschanaz)

References

Details

(4 keywords, Whiteboard: [adv-main155-][adv-esr153.2-])

Attachments

(1 file, 5 external files, 1 obsolete file)

Attached file run_marionette.py —

Steps to reproduce:

Overview

PBackground::CreateNotificationParent carries an nsIPrincipal and a free-form nsString mScope from the child. Bug 2039990 hardened the principal: BackgroundParent::ValidatePrincipal is now called in RecvCreateNotificationParent (BackgroundParentImpl.cpp:505), so a compromised content process can no longer forge a principal it cannot load. However, the mScope string is never validated against the validated principal. The scope is later used verbatim by ServiceWorkerManager::SendNotificationClickEvent / SendNotificationCloseEvent to select which service worker receives the notificationclick / notificationclose event, and GetActiveWorkerInfoForScope derives the SW-lookup principal from the scope URI (via ScopeToPrincipal(scopeURI, attrs)), not from the caller principal.

The result: a compromised content process for https://attacker.example can dispatch a notificationclick event — carrying a fully attacker-controlled Notification payload (title, body, tag, dataSerialized, actions) — to any origin's active service worker, by supplying the victim's SW scope as mArgs.mScope while keeping the validated principal as the attacker's own. The victim's service worker runs with the victim's origin principal (Cache API, IndexedDB, cookie-scope fetch, etc.) and processes the attacker-controlled event.notification.data via structured clone.

Root cause

The implementation has four layers that combine into the vulnerability:

  • dom/notification/NotificationParent.cpp:408 — NotificationParent::RecvShow constructs the NotificationObserver with mArgs.mScope (child-supplied) and principal (validated, but only for remote-type compatibility). No check that the scope's origin matches the principal's origin.
  • dom/notification/NotificationParent.cpp:90,105-106 — on AlertTopic::Click / AlertTopic::Closed, calls RespondOnClick(mPrincipal, mScope, mNotification, actionName) / SendNotificationCloseEvent with the child-controlled mScope.
  • dom/notification/NotificationHandler.cpp:20-36 — notification::RespondOnClick forwards to ServiceWorkerManager::SendNotificationClickEvent(originSuffix, aScope, ...). originSuffix is derived from mPrincipal, but aScope is the child-controlled string.
  • dom/serviceworkers/ServiceWorkerManager.cpp:1212-1228 — SendNotificationClickEvent parses OriginAttributes from aOriginSuffix, then calls GetActiveWorkerInfoForScope(attrs, aScope).
  • dom/serviceworkers/ServiceWorkerManager.cpp:1343-1366 — GetActiveWorkerInfoForScope does NS_NewURI(getter_AddRefs(scopeURI), aScope), then ScopeToPrincipal(scopeURI, aOriginAttributes). The principal used for SW lookup is derived from the scope URI, not from mPrincipal. The OriginAttributes come from the attacker's principal, so for default (non-PB, default userContext) attributes they match any normal browsing registration.
  • The close path (dom/serviceworkers/ServiceWorkerManager.cpp:1232-1248) is analogous.

The display path (NotificationParent::Show, dom/notification/NotificationParent.cpp:347-404) uses mArgs.mPrincipal for the nsIAlertNotification principal, so the visible OS-notification origin label is the attacker's origin — not the victim's. The persistence path (PersistNotification, dom/notification/NotificationUtils.cpp:240-265) keys storage by the principal's origin, with mScope stored only as the serviceWorkerRegistrationScope metadata field. Neither display nor persistence is the primary impact; the SW dispatch is.

MOZ_ASSERT(!mScope.IsEmpty()) at NotificationParent.cpp:70 only checks that a scope exists when a SW path is taken — it does not validate the scope's origin.

Build

Tested revision:

9a8a80db6ce10ffc2fc91a1e25685eed59ce3501
2026-07-19T04:22:49Z
Bug 2055720 - Provide localization comments to Content Classifier strings

Browser:

Mozilla Firefox 154.0a1
Linux x86-64 ASan + gczeal, non-optimized, fresh temporary profile
Build ID 20260720042830

Steps to reproduce

  1. Build Firefox with AddressSanitizer and tests enabled.

  2. Save the attached run_marionette.py in a working directory.

  3. From the Firefox source directory, launch a fresh profile:

    ASAN_OPTIONS='abort_on_error=1:detect_leaks=0:allocator_may_return_null=1' \
      MOZ_MARIONETTE=1 MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 \
      ./mach run --temp-profile --no-remote -- --marionette --headless -remote-allow-system-access
    
  4. In another terminal, run:

    ./mach python /absolute/path/to/run_marionette.py
    

The harness starts two local HTTP servers (http://localhost:8766 and https://localhost:8767), adds the self-signed localhost cert as a trusted CA + per-host override so HTTPS SW registration succeeds, grants desktop-notification permission to the test origins, registers victim service workers at two scopes (http://localhost:8766/victim/ and https://localhost:8767/victim/), and simulates a compromised content process from chrome-privileged JS.

The harness runs two test cases in the same session:

  1. CONTROL (same-origin). Attacker principal = https://localhost:8767, forged serviceWorkerRegistrationScope = https://localhost:8767/victim/. Principal and scope belong to the same origin. Expected: victim SW receives notificationclick. This verifies the harness end-to-end.

  2. BUG (cross-origin). Attacker principal = https://attacker.test, forged serviceWorkerRegistrationScope = http://localhost:8766/victim/. Principal and scope belong to DIFFERENT origins (and even different schemes / hosts). Expected if the bug exists: victim SW at http://localhost:8766/victim/ STILL receives notificationclick carrying the attacker-controlled title and body, because GetActiveWorkerInfoForScope uses the principal derived from the scope, not the caller principal.

The harness exercises the parent-side code path of the finding: NotificationHandler::RespondOnClick (XPCOM) → notification::RespondOnClick(principal=attacker, scope=victimScope, notification, action) (NotificationHandler.cpp:20-40) → ServiceWorkerManager::SendNotificationClickEvent(originSuffix=attacker, aScope=victimScope, aNotification, aAction) → GetActiveWorkerInfoForScope(attrs, victimScope) (ServiceWorkerManager.cpp:1343-1367), which derives the principal from ScopeToPrincipal(scopeURI, attrs) (i.e. from the SCOPE URI, not from the caller principal), then looks up the victim's active SW registration and dispatches notificationclick.

This is functionally equivalent to the live NotificationParent::Observe(AlertTopic::Click) path (which calls notification::RespondOnClick directly, without the XPCOM https:// check at NotificationHandler.cpp:85) that a real compromised content process would hit via PBackground::CreateNotificationParent + PNotification::Show.

Suggested fix direction

In NotificationParent::RecvShow (or in CreateOnMainThread), if mArgs.mScope is non-empty, parse it as a URI and verify that ScopeToPrincipal(scopeURI, mArgs.mPrincipal->OriginAttributesRef()) equals mArgs.mPrincipal (or at minimum that the scope's origin equals the principal's origin). Reject the Show (or fail the actor) if not. The same check should cover the SendNotificationCloseEvent path. Alternatively, perform the scope/principal binding check inside ServiceWorkerManager::SendNotificationClickEvent / SendNotificationCloseEvent by accepting the caller principal explicitly and asserting the scope's principal equals it.

A regression test should send CreateNotificationParent from a content process with a validated attacker principal and a forged mScope pointing at a victim origin's SW registration, then issue Show and simulate a notification click, and assert that (a) the Show is rejected (or the actor is failed) and (b) no notificationclick event is dispatched to the victim's service worker.

Actual results:

RESULT=VULNERABLE: both control (same-origin) and cross-origin
forged-scope dispatched notificationclick to victim SW

Cross-origin forged-scope dispatch (BUG_CROSS_ORIGIN test case):

FORGED_DISPATCH[BUG_CROSS_ORIGIN]={
  "attackerOrigin": "https://attacker.test",
  "dispatchInvoked": true,
  "handlerPresent": true,
  "label": "BUG_CROSS_ORIGIN",
  "notifId": "forged-BUG_CROSS_ORIGIN-1784607564474",
  "putOk": true,
  "respondOnClickResolved": true,
  "storedEntry": {
    "body": "ATTACKER BODY [BUG_CROSS_ORIGIN] - forged scope -> victim SW",
    "id": "forged-BUG_CROSS_ORIGIN-1784607564474",
    "serviceWorkerRegistrationScope": "http://localhost:8766/victim/",
    "tag": "forged-tag-BUG_CROSS_ORIGIN",
    "title": "ATTACKER TITLE [BUG_CROSS_ORIGIN]"
  },
  "victimScope": "http://localhost:8766/victim/"
}
SW_EVENTS_VIA_SERVER[BUG_CROSS_ORIGIN]=[{
  "body": "ATTACKER BODY [BUG_CROSS_ORIGIN] - forged scope -> victim SW",
  "clientList": [{"id": "e1a6bf14-cd66-463a-96c9-cdea261df897",
                  "url": "http://localhost:8766/victim/victim.html"}],
  "data": null,
  "scope": "http://localhost:8766/victim/",
  "tag": "forged-tag-BUG_CROSS_ORIGIN",
  "timestamp": 1784607564478,
  "title": "ATTACKER TITLE [BUG_CROSS_ORIGIN]",
  "type": "notificationclick"
}]

The victim SW at http://localhost:8766/victim/ received a notificationclick event carrying the attacker-controlled title (ATTACKER TITLE [BUG_CROSS_ORIGIN]), body, and tag, dispatched by a principal (https://attacker.test) that has no relationship to the victim's SW registration scope (http://localhost:8766/victim/). The victim SW ran with the victim origin principal (http://localhost:8766) and processed the attacker-controlled notification payload.

The CONTROL (same-origin) test case also fired notificationclick, proving the harness exercises the real code path (not silently failing).

Expected results:

NotificationParent::RecvShow (or CreateOnMainThread) must validate, when mArgs.mScope is non-empty, that the scope's origin equals mArgs.mPrincipal's origin. Concretely: parse mArgs.mScope as a URI, compute ScopeToPrincipal(scopeURI, mArgs.mPrincipal->OriginAttributesRef()), and reject the Show (or fail the actor) if that principal does not equal mArgs.mPrincipal. The same check must cover the SendNotificationCloseEvent path. Alternatively, perform the scope/principal binding check inside ServiceWorkerManager::SendNotificationClickEvent / SendNotificationCloseEvent by accepting the caller principal explicitly and asserting the scope's principal equals it.

Under the correct behavior, a CreateNotificationParent call with mPrincipal = https://attacker.example and mScope = https://victim.example/sw.js would be rejected at the IPC boundary, and no notificationclick event would be dispatched to the victim's service worker.

Group: firefox-core-security → dom-core-security
Component: Untriaged → DOM: Notifications
Product: Firefox → Core

Do we have any good way to guard for different scopes?

(The suggestion to use ScopeToPrincipal sounds reasonable to me)

Yes, I think using ScopeToPrincipal, additionally validating the resulting scope principal in mozilla::ipc::BackgroundParentImpl::RecvCreateNotificationParent and then additionally checking that the scope principal is the same as the effective storage principal would be appropriate/correct.

Flags: needinfo?(bugmail)
Assignee: nobody → krosylight
Severity: -- → S3
Priority: -- → P3

:saschanaz, 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?(krosylight)

The bug has a release status flag that shows some version of Firefox is affected, thus it will be considered confirmed.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Group: dom-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch

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

For more information, please visit BugBot documentation.

Flags: needinfo?(krosylight)
Attachment #9627280 - Flags: approval-mozilla-beta?

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Compromised content process may trigger notifications on third party origin and run service worker script there if the user clicks it.
  • 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: Adding extra validations with test coverage
  • String changes made/needed?: None
  • Is Android affected?: yes
Attachment #9627281 - Flags: approval-mozilla-beta?
Attachment #9627318 - Flags: approval-mozilla-release?

firefox-release Uplift Approval Request

  • User impact if declined/Reason for urgency: Compromised content process may trigger notifications on third party origin and run service worker script there if the user clicks it.
  • 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: Adding extra validations with test coverage
  • String changes made/needed?: None
  • Is Android affected?: yes

firefox-esr153 Uplift Approval Request

  • User impact if declined/Reason for urgency: Compromised content process may trigger notifications on third party origin and run service worker script there if the user clicks it.
  • 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: Adding extra validations with test coverage
  • String changes made/needed?: None
  • Is Android affected?: yes
Attachment #9627323 - Flags: approval-mozilla-esr153?

Since esr153 is affected, this cannot ship with an Fx154 dot release. I'll abandon the release uplift requests.

Flags: needinfo?(krosylight)
Attachment #9627318 - Attachment is obsolete: true
Attachment #9627318 - Flags: approval-mozilla-release?
Attachment #9627280 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9627281 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Flags: in-testsuite+
Attachment #9627323 - Flags: approval-mozilla-esr153? → approval-mozilla-esr153+

Was Part 2 left off the ESR153 uplift request intentionally?

Flags: needinfo?(krosylight)

That's more of cleanup on top of other refactoring that is not uplifted, so yes.

Flags: needinfo?(krosylight)
QA Whiteboard: [sec] [qa-triage-done-c156/b155]
Whiteboard: [adv-main155-][adv-esr153.2-]
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: