Re: [whatwg/fetch] Question regarding preflight requests using the original request destination (Issue #1762)

fbuecklers left a comment (whatwg/fetch#1762)

Hi, I like to follow up here,

We measured this in current browsers on real devices, with real user input.

- Report with all headers: 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). It shows the headers the server received.

Two worker variants:

- **Pass-through:** `event.respondWith(fetch(event.request))`
- **Navigation preload:** `event.respondWith(event.preloadResponse)`

Each was tested with four navigations: a typed URL, a link from another site, a same-origin link and the reload button. The table lists only what differs from the same navigation without a worker.

| Browser | Pass-through | Navigation preload |
|---|---|---|
| Chrome 157, Windows 11 | `sec-fetch-dest: empty`, no `sec-fetch-user`. A typed URL sends `sec-fetch-site: cross-site` instead of `none`. | no difference |
| Firefox 160, Windows 11 | `sec-fetch-dest: empty`, `sec-fetch-mode: same-origin`, `sec-fetch-site: same-origin` for every navigation (also cross-site), no `sec-fetch-user`, `priority: u=2` instead of `u=0, i`. `document.referrer` is empty after a link click. | `sec-fetch-site: same-origin` for every navigation, no `sec-fetch-user`, `priority: u=2`. `document.referrer` is empty after a link click. |
| Safari 27, macOS | `sec-fetch-dest: empty`, `sec-fetch-site: same-origin` for every navigation (also cross-site), `priority: u=3, i`. A typed URL sends the worker script URL as `Referer`. | no difference |
| Safari, iOS | same as Safari on macOS | no difference |

Navigation preload also adds `Service-Worker-Navigation-Preload: true`, as specified.

## A pass-through navigation should look like a native navigation

The pass-through request differs from the native navigation in every browser, and in a different way in each:

- Every browser sends `sec-fetch-dest: empty`.
- `sec-fetch-site` is wrong in all three. Firefox and Safari report a cross-site navigation as `same-origin`.
- Firefox changes `sec-fetch-mode` to `same-origin`, although no `init` was passed to `fetch()`.
- Safari sends the worker script URL as `Referer`.

Servers rely on these headers, and the differences break real sites:

- **Bot detection (Akamai Bot Manager):** the headers of the request differ between the moment the signature is built and the moment it is validated, so the validation fails. Visitors with a pass-through worker got 15–19 times more challenge pages than visitors without one.
- **Shopify Markets:** Shopify renders the market of the cart, not the market of the URL, when the request is not a document navigation. A country switch through a worker shows the prices of the old market, and the cart never moves. We work around it by sending the first navigation into another market past the worker.
- **Fetch Metadata policies:** a server cannot tell that a navigation came from another site in Firefox and Safari.

A worker that only passes the request on is the most basic worker there is. Developers expect it to change nothing. Today nothing tells them otherwise, and the breakage shows up far from the worker, in a bot score or a wrong currency.

## Navigation preload shows that it can work

The concern above is that a worker can replay the response anywhere, for example to a `<script>`. Navigation preload has the same exposure: the worker gets the full response in `event.preloadResponse` and can do anything with it. Yet the preload request carries the native navigation headers, and in Chrome and Safari it is identical to the navigation without a worker.

So we see no clear reason why `fetch(event.request)` for a navigation request should not behave the same way. It could send the request with the headers of the navigation it came from, as the preload request does.

## Proposed behaviour

When a worker calls `fetch(event.request)` with the unchanged navigation request, the browser sends the same request it would send without a worker:

- `sec-fetch-dest` keeps the navigation's destination, such as `document` or `iframe`.
- `sec-fetch-mode` stays `navigate`.
- `sec-fetch-site` describes the navigation's initiator, not the worker: `none` for a typed URL or a bookmark, `cross-site` for a link from another site.
- `sec-fetch-user: ?1` is sent when the navigation had user activation.
- `Referer` is the navigation's referrer. The worker script URL is never sent.
- The other headers, such as `priority` and the client hints, are the navigation's own.

The rule covers the request object from `event.request`, passed without an `init`. A new `Request` or any `init` keeps today's behaviour.

## Differences that look like bugs under the current spec

Some of the differences above do not depend on the proposal:

- **Firefox, pass-through:** `sec-fetch-mode: same-origin`. The worker calls `fetch(event.request)` without an `init`. The Request constructor changes `navigate` to `same-origin` only when `init` is not empty, so the mode should stay `navigate`, as in Chrome and Safari.
- **Firefox, navigation preload:** `sec-fetch-site: same-origin` and no `sec-fetch-user`. The preload request should match the navigation request, as it does in Chrome and Safari.
- **Safari, pass-through:** a typed URL sends the worker script URL as `Referer`, although the navigation has no referrer.
- **All browsers, pass-through:** `sec-fetch-site` differs for the same navigation, for example `cross-site` (Chrome), `same-origin` (Firefox, Safari) and `none` (native) for a typed URL.

We are happy to file individual bug reports with each browser vendor once the intended behaviour is clear, and to link them to this issue.


-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1762#issuecomment-6943849988
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/1762/6943849988@github.com>

Received on Tuesday, 17 November 2026 09:17:54 UTC