how to set the Referrer-Policy header correctly
Explains how to set the Referrer-Policy header correctly so browsers stop leaking full URLs to other sites. Use this when a team ships an app or API and needs to control what referrer info browsers send on navigations, fetches, and embeds. Not for changing server-side redirect logic, CORS settings, or fixing mixed-content warnings.
TL;DR
Set the Referrer-Policy response header on every response your app serves. no-referrer is the strictest and safest default, strict-origin-when-cross-origin keeps analytics working without leaking full paths. Set it once at your reverse proxy or edge so every route inherits it, then verify with curl. Most leaks people worry about disappear with one header.
The query
how to set the Referrer-Policy header correctlyUse this when
- You run a web app and full page URLs (query strings, tokens in paths) show up in partner analytics via the referrer
- You need a sane default referrer policy across an app, API, or static site
- You want cross-origin embeds and links to keep working but stop leaking path details
- You are hardening response headers and this one is missing from your baseline
Not for
- Controlling CORS, cookies, or redirect behavior; this header only affects what browsers send as the referrer
- Server-side logging choices; your own logs still see whatever the client sends
- Privacy compliance on its own; pair it with actual data handling practices
- Fixing a leak that already happened; rotate anything that leaked and then set the policy
Steps
- Pick your policy value. Use
no-referrerif you want nothing sent anywhere, orstrict-origin-when-cross-originif first-party analytics and integrations need the origin. Avoidunsafe-urlunless you truly need full URLs everywhere. Expected output: a one-line decision recorded in your hardening doc. - Set the header at your reverse proxy or edge. In nginx add a line like
add_header Referrer-Policy "no-referrer" always;inside the server block, or in your CDN add a custom response header with the same name and value. Expected output: the config reloads cleanly with no syntax errors. - If some pages need a looser policy, add a meta tag on those pages only. A meta tag overrides the header for that page, so use it sparingly and note the exceptions. Expected output: the exception list is documented, not guessed at later.
- Verify with curl. Run
curl -sI https://your-site.example/ | grep -i referrerand confirm the header name and value appear on the root and on an API path. Expected output:Referrer-Policy: no-referrer(or your chosen value) on both. - Check in a real browser. Open devtools, trigger a cross-origin link or fetch, and look at the request headers to confirm the referrer is gone or reduced to the origin. Expected output: cross-origin requests carry no full URL in the referrer.
- Re-scan on deploys. Header regressions sneak in when teams add new proxies or routes, so keep this in your periodic header check. Expected output: your baseline header set stays green across routes.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_iDQP9r73rtxQAQoBtV6VwA
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.