Fetch Metadata for Small Web Applications - Filter Cross-Site Requests Without Calling It Authentication
A server can receive a perfectly valid HTTP request and still know very little about the browser action behind it. Did a user follow a link, did the site's own JavaScript call an API, or did another site quietly load a private endpoint as an image? Cookies and authorization headers may identify a session, but they do not describe that request context.
Fetch Metadata adds a small vocabulary for that missing context. Modern browsers can attach Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest, and sometimes Sec-Fetch-User. A server can use the combination to reject request shapes that its application never expects. This is useful defense in depth, but it is not a new form of authentication and it needs exceptions designed around real routes.
What the browser is telling the server
The W3C Fetch Metadata Working Draft defines four request headers. The document accessed for this article is dated September 21, 2026 and remains a Working Draft, so it should be treated as work in progress rather than a final W3C Recommendation.
Sec-Fetch-Sitedescribes the relationship between the initiator and target:same-origin,same-site,cross-site, ornone.Sec-Fetch-Modedescribes the request mode, such asnavigate,cors,no-cors, orsame-origin.Sec-Fetch-Destdescribes how the response is intended to be used, includingdocument,image,script,iframe, oremptyfor requests without a more specific destination.Sec-Fetch-Useris sent for a navigation with user activation and has the value?1when present.
For example, an image embedded by a different site might produce this context:
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: no-cors
Sec-Fetch-Dest: image
A top-level page opened from the browser's address bar can instead carry Sec-Fetch-Site: none, while a call from the application's own JavaScript may be same-origin with a destination of empty. The value none does not mean that metadata is absent; it describes a request the browser considers directly user-initiated rather than initiated by another site.
Why the Sec- prefix matters, and where it stops
The WHATWG Fetch Standard classifies request-header names beginning with Sec- as forbidden request headers. Ordinary page JavaScript cannot choose those values through fetch() or XMLHttpRequest. That gives a server more useful browser context than a custom field that any calling page can set freely.
This protection has a precise boundary. An arbitrary HTTP client can send a field with the same name, and a proxy can remove or alter fields. Fetch Metadata is therefore evidence about requests made by conforming user agents, not proof of a caller's identity. Authentication and authorization must still make their own decisions.
The specification also adds these headers only for potentially trustworthy URLs. In ordinary deployment that usually means HTTPS, with defined exceptions for trustworthy local contexts. A missing header can therefore mean an older or unusual client, a non-browser integration, an insecure origin, or an intermediary behavior. It must not automatically be translated into “hostile cross-site request.”
Site and origin are not interchangeable
The most tempting policy is “allow same-site, block cross-site.” That may be appropriate, but only after deciding what trust is being granted to sibling subdomains. https://app.example.com and https://uploads.example.com can be same-site while remaining different origins. If an abandoned subdomain, user-content host, or less trusted service can initiate requests, treating every same-site request like same-origin quietly widens the boundary.
MDN's Fetch Metadata guide makes this distinction explicit. A stricter application can allow same-origin by default and require named exceptions for trusted same-site flows. A simpler site whose subdomains share one security boundary may choose to accept both. The header supplies context; the application still has to define policy.
Start with a conservative PHP filter
A useful first policy should answer a narrow question: is this a browser request explicitly marked cross-site, and if so, does it match a request shape the site deliberately accepts? The following example allows requests when Fetch Metadata is absent, allows non-cross-site requests, preserves top-level GET navigation, and lets the application exempt intentional cross-origin routes.
function fetchMetadataAllowsRequest(array $server, bool $crossSiteRoute): bool
{
$site = $server['HTTP_SEC_FETCH_SITE'] ?? null;
// Missing metadata may be an older client or a non-browser integration.
if ($site === null || $site !== 'cross-site') {
return true;
}
if ($crossSiteRoute) {
return true;
}
$method = strtoupper($server['REQUEST_METHOD'] ?? '');
$mode = $server['HTTP_SEC_FETCH_MODE'] ?? '';
$dest = $server['HTTP_SEC_FETCH_DEST'] ?? '';
return $method === 'GET'
&& $mode === 'navigate'
&& $dest === 'document';
}
The handler should evaluate this before expensive work or side effects and return a small 403 Forbidden response when it fails. The $crossSiteRoute value should come from server-side route configuration, not from a query parameter supplied by the caller.
This is a starting point, not a universal middleware package. A site might legitimately accept a cross-site POST to a payment return endpoint, expose images for embedding, serve a public API through CORS, or receive a webhook from another server. Those routes need explicit rules and their own authentication where appropriate. Conversely, an account endpoint may decide that even same-site is too broad.
Read the headers together
No single value captures intent. Sec-Fetch-Site: cross-site can describe both an ordinary link from another website and a hidden subresource request. Allowing top-level safe navigation requires the mode and destination too. Likewise, Sec-Fetch-User: ?1 can help distinguish an activated navigation, but it is not proof that a person understood or approved a consequential operation.
A route inventory makes these combinations easier to reason about:
- Public documents normally need cross-site top-level navigation so external links continue to work.
- Session-authenticated form handlers generally should not need arbitrary cross-site submission.
- Static images, scripts, or fonts may intentionally support cross-site embedding, or may deliberately forbid it.
- CORS API routes need a policy aligned with their exact allowed origins, methods, credentials, and preflight behavior.
- Webhooks and command-line clients may not send browser metadata at all; they need provider signatures, tokens, or another protocol-specific control.
Redirects deserve testing as well. The W3C draft calculates Sec-Fetch-Site across the URL list and keeps a cross-site relationship visible when a redirect chain crossed that boundary. A policy should be tested on the final deployed flow rather than inferred only from its first URL.
Observe before blocking
An application rarely has a complete route inventory on the first attempt. A safer rollout records the decision that the filter would have made without enforcing it. Useful fields include the route name, method, the four Fetch Metadata values, and the proposed allow or deny result. Avoid logging cookies, authorization values, request bodies, or other secrets.
Review legitimate traffic for missing metadata and cross-site integrations. Then build a test matrix that includes:
- Same-origin page loads, forms, and JavaScript requests.
- A link from another site to a public document.
- A cross-site form submission to a protected state-changing route.
- A protected JSON endpoint loaded as an image or script.
- Every documented CORS route and embedded public resource.
- Webhooks, health checks, mobile clients, and command-line integrations with no Fetch Metadata.
- Redirects, authentication handoffs, and error responses.
MDN currently describes Sec-Fetch-Site as widely available and dates broad cross-browser availability from March 2023 in its compatibility reference. That is useful current evidence, not a reason to erase the missing-header path. Client populations and intermediaries differ, and compatibility claims can age.
Remember the cache boundary
If the selected response changes according to Fetch Metadata, a shared cache may need to distinguish those request fields. The W3C draft calls out Vary for this reason, and MDN's sample uses it as well. For example, a response selected by site and mode might include:
Vary: Sec-Fetch-Site, Sec-Fetch-Mode
That is not a line to paste everywhere. Adding fields to Vary can reduce cache reuse, and a filter that rejects a request before normal response generation may be handled differently by the application's cache architecture. The correct choice depends on where the decision runs and which responses are cacheable. Verify behavior at the origin and through any reverse proxy or CDN.
What this filter cannot establish
Fetch Metadata does not answer “Who is this user?” or “May this user edit record 42?” It does not validate a webhook signature, repair an overly broad CORS policy, or neutralize script already running in the application's origin. It also does not turn GET into a safe place for state changes.
For cookie-authenticated actions, keep established CSRF controls such as an appropriate token design and intentional SameSite cookies. Keep authorization checks on every protected object. Validate methods and content types. Fetch Metadata can reject a class of implausible requests earlier, including some requests that are awkward for token-only defenses, but removing independent controls would make one browser signal carry more trust than it was designed to bear.
Use context as a filter, not an identity
The useful promise of Fetch Metadata is modest: a browser can tell the server something about where a request came from and how its response will be used. A small application can turn that context into a resource isolation policy that preserves links and named integrations while refusing unexpected cross-site use.
The difficult part is not reading four headers. It is documenting which routes genuinely need cross-origin access, deciding whether sibling subdomains share a trust boundary, retaining a sensible path for missing metadata, and testing before enforcement. Once those decisions are explicit, Fetch Metadata becomes a clear defense-in-depth filter rather than a security switch whose label promises too much.
References
- W3C: Fetch Metadata Request Headers - Working Draft, September 21, 2026.
- WHATWG: Fetch Standard - Living Standard, last updated November 20, 2026 when accessed.
- MDN Web Docs: Fetch metadata - last modified September 28, 2026 when accessed.
- MDN Web Docs: Sec-Fetch-Site header - last modified September 28, 2026 when accessed.
- web.dev: Protect your resources from web attacks with Fetch Metadata by Lukas Weichselbaum.
