Articles

Referrer-Policy Header Explained: Values and Best Practice

The Referrer-Policy header controls how much of a page's URL the browser sends in the Referer header. What each value does and which one to choose.

Chisato Chisato · · 4 min read
A red padlock icon over a keyboard

The Referrer-Policy header tells the browser how much information to include in the Referer request header when a user follows a link or a page loads a resource. Without a policy, URLs from your site — sometimes including paths and query strings that contain search terms, internal IDs, or tokens — can be sent to every third-party server your pages touch. Referrer-Policy lets you trim that down to the origin only, or send nothing at all, without breaking the analytics and security checks that rely on it.

What the Referer header is

When a browser navigates to a new page or fetches an image, script, or stylesheet, it can include a Referer header identifying the page that triggered the request. The name is a historical misspelling of “referrer” that ended up in the HTTP specification, which is why the header is Referer while the policy is Referrer-Policy.

A full referrer might look like:

Referer: https://app.example.com/account/settings?user=4821&tab=billing

That’s useful for your own analytics and for some security checks. It’s also a leak: if the settings page embeds a third-party font or links out to a partner site, that full URL can travel with the request.

Why referrer leaks matter

URLs carry more than people assume:

  • Personal data in paths and queries — user IDs, email addresses in search parameters, or filters revealing what someone was looking at.
  • Secrets in URLs — password-reset tokens, magic login links, or signed download URLs. A reset page that loads an external analytics script can hand the token to that script’s server.
  • Internal structure — admin paths, staging hostnames, or unreleased feature names.

Leaks like these compound other bugs. An open redirect on a page whose URL holds a token can forward both the user and the token to an attacker’s site, with the token arriving in the Referer header.

The policy values

Referrer-Policy has eight values. They differ in two dimensions: how much of the URL is sent (full URL, origin only, or nothing), and whether behavior changes for cross-origin requests or downgrades from HTTPS to HTTP.

ValueSame-origin requestCross-origin requestHTTPS → HTTP
no-referrerNothingNothingNothing
no-referrer-when-downgradeFull URLFull URLNothing
originOrigin onlyOrigin onlyOrigin only
origin-when-cross-originFull URLOrigin onlyOrigin only
same-originFull URLNothingNothing
strict-originOrigin onlyOrigin onlyNothing
strict-origin-when-cross-originFull URLOrigin onlyNothing
unsafe-urlFull URLFull URLFull URL

“Origin only” means scheme, host, and port — https://app.example.com/ — with no path or query. “Strict” variants never send anything when moving from a secure page to an insecure one, which matters because a referrer on a plain-HTTP request is visible to anyone on the network path. Our HTTPS explainer covers why that downgrade is dangerous.

The browser default

Modern browsers default to strict-origin-when-cross-origin when a site sets no policy. Same-origin requests get the full URL, which keeps your own analytics and navigation working; cross-origin requests get only the origin; and downgrades get nothing.

That default is reasonable, but setting the header explicitly is still worthwhile. It documents intent, guarantees consistent behavior across clients, and lets you go stricter on sensitive pages.

How to set a policy

There are several ways to apply Referrer-Policy, from site-wide to per-element.

HTTP response header — the most common and the one to start with:

Referrer-Policy: strict-origin-when-cross-origin

HTML meta tag — useful when you can’t control headers, such as on some static hosts:

<meta name="referrer" content="strict-origin-when-cross-origin">

Per-element attribute — <a>, <img>, <script>, <link>, and <iframe> accept a referrerpolicy attribute that overrides the page policy for that request:

<a href="https://partner.example" referrerpolicy="no-referrer">Partner</a>

Link relation — rel="noreferrer" on a link sends no referrer for that navigation and also implies noopener, preventing the opened page from accessing window.opener.

Fetch API — fetch(url, { referrerPolicy: "no-referrer" }) sets the policy for an individual request from JavaScript.

Choosing a policy

For most sites, a sensible approach is:

  • Site-wide: strict-origin-when-cross-origin. It matches the browser default and preserves same-origin analytics while stripping paths from third-party requests.
  • Sensitive pages: no-referrer or same-origin. Password-reset pages, account settings, magic-link landing pages, and anything with tokens in the URL should send nothing cross-origin. Better still, avoid putting secrets in URLs at all.
  • Avoid unsafe-url. It sends full URLs everywhere, including over insecure connections. There are very few legitimate reasons to use it.
  • Avoid no-referrer-when-downgrade on modern sites. It sends full URLs to every HTTPS third party, which is the leak most sites want to prevent.

Be aware of what depends on referrers before going stricter. Some analytics attribution, affiliate tracking, and partner integrations rely on receiving at least your origin. Some servers also check the Referer or Origin header as one layer of CSRF protection; no-referrer site-wide can break those checks, while origin-only policies keep them working.

Referrer-Policy among the security headers

Referrer-Policy belongs to the same family of low-effort, high-value response headers as Content Security Policy, HSTS, and frame protections against clickjacking. Each controls a different browser behavior, and they’re typically configured together at the CDN, reverse proxy, or framework middleware level so every response carries them.

The takeaway

Referrer-Policy controls how much of your page’s URL the browser shares in the Referer header. Set strict-origin-when-cross-origin site-wide to send full URLs only to yourself and bare origins to everyone else, apply no-referrer to pages whose URLs contain tokens or personal data, and never use unsafe-url. Check your analytics and CSRF defenses before tightening further, and configure it alongside your other security headers.

Chisato Chisato · · 5 min read

What Is an XXE Attack? XML External Entities Explained

An XXE attack abuses XML external entities to read files, reach internal services, or exhaust memory. How XXE works and how to configure parsers safely.

#Security #Web Development #Vulnerability
Chisato Chisato · · 5 min read

Refresh Token Rotation Explained: Safer Long Sessions

Refresh token rotation issues a new refresh token on every use and revokes the old one, so a stolen token gets caught on reuse. How it works and pitfalls.

#Security #Authentication #Web Development