CheckWebSecurity Brand Logo

Article

Referrer-Policy explained: what your URLs say when they leave

Published 2026-11-24

Referrer-Policy explained: what your URLs say when they leave

Every time someone clicks a link on your site, the browser answers a question on your behalf: how much of the current URL should travel with the request? The answer goes into the Referer header, and without a policy, the answer can be the whole URL: scheme, host, path, and query string. If any of your URLs carry a password-reset token, a customer email in a path segment, or a session id in a query parameter, those values get handed to every site you link to, and to every third-party script on those sites.

Referrer-Policy is the response header that decides. It is cheap to set, it has no performance cost, and when set to the recommended value it does not interfere with how a site works: your own analytics keep the full referrer, and outbound requests get trimmed. Plenty of sites still send nothing at all. This article covers what the header does, what each value sends, the two or three values worth considering, and how to check your site with curl and a headers scan.

What the Referer header carries, exactly

The Referer header is the old spec typo that stuck; the policy header is spelled correctly with the double R. When a browser makes a request, the header tells the destination which page the request came from. What goes in it is not fixed: that is the entire point of the policy.

The full URL has three interesting parts:

  • Origin: https://example.com, meaning scheme, host, port. Nothing about which page.
  • Path: /orders/8441, which page, without the query string.
  • Query string: ?email=janet@example.com&token=..., the part that gets people in trouble.

The fragment (the #... part) never travels in the Referer under any policy. That is the one free guarantee. Everything else is negotiable, and the negotiation is what the header controls. The W3C Referrer Policy spec defines the eight values and exactly what each sends in which context, and the rest of this article is mostly that spec with the jargon removed.

A concrete scenario, built from the standard failure pattern. Say a site has an internal page behind a URL like /app/clients/8441/summary?preview=true. The page links out to a partner's status page, an analytics vendor, and two social networks. Without a policy, under the legacy default the full URL, including the customer id in the path, goes to all four on every click. Nobody on that team could tell you the customer id was being shared. If your URLs contain emails, order ids, or tokens, this is the failure mode: not a dramatic breach, just a steady, silent sharing of URL contents with every third party a page touches.

The eight values, in plain terms

The spec defines eight policies. They differ on two axes: how much of the URL goes out, and whether the context (same-origin vs cross-origin, HTTPS-to-HTTPS vs HTTPS-to-HTTP) matters.

Values that ignore context

no-referrer sends nothing. Ever. No Referer header at all. This is the maximum-privacy setting and it is usually overkill for a whole site, because analytics tools that read the Referer for traffic attribution go blind for cross-origin traffic.

origin sends only https://example.com/ on every request, same-origin or not. The path and query string never leave the site.

unsafe-url sends the full URL everywhere, including from HTTPS pages to HTTP destinations, which is why the name contains the word unsafe. The spec says this value exists for compatibility; there is no good reason to send it. If a monitoring tool asks for it, that tool wants to track users, not help you.

no-referrer-when-downgrade is the old default. Full URL when the protocol stays the same or improves, nothing on a downgrade (HTTPS to HTTP). Browsers replaced this default one by one between 2020 and 2021, which is the actual reason the header is worth setting explicitly: with no header you inherit whatever the visitor's browser decided, and that decision can change under you.

Values that consider context

same-origin sends the full URL for same-origin requests and nothing for anything cross-origin. This is the strictest contextual policy. Your own analytics keep working; every external site gets silence.

strict-origin sends only the origin, and sends nothing on a downgrade. A stricter version of origin.

origin-when-cross-origin sends the full URL same-origin, and only the origin cross-origin, including on a downgrade (HTTPS to HTTP). That last part is the difference from its strict sibling.

strict-origin-when-cross-origin sends the full URL for same-origin requests, only the origin for cross-origin requests, and nothing on a downgrade. It is the value browsers now use as their default when no header is present (Chrome switched with version 85 in 2020, Firefox with 87 in 2021, Safari with 15), it is the value the OWASP Secure Headers cheat sheet recommends, and it is the value web.dev recommends with the same reasoning: keep the full referrer inside your own site, send the origin elsewhere, never leak to plain HTTP.

The naming is systematic, which helps once you see it: strict- means nothing is sent on a downgrade, and -when-cross-origin means the full URL stays on same-origin requests while less goes out cross-origin.

Which one to actually set

For almost every site, strict-origin-when-cross-origin is the right answer, and the reasoning is short: your own analytics and internal links keep the full referrer, every external destination learns only your domain, and nothing travels to plain-HTTP endpoints where anyone on the network path can read it. The header costs one line in nginx or Apache and matches the browser default, so setting it explicitly buys you two things: consistency across the browsers that have not switched defaults, and a scanner line that stops flagging the absence of the header.

Two situations push toward something else:

Your URLs carry secrets even same-origin. Password-reset links, signed URLs, magic-login tokens, one-time codes. The full URL goes out on same-origin requests too, so a token in a query parameter still travels to any same-origin subresource load. If that describes your URL shapes, step up to no-referrer and accept that Referer-based analytics stop working. Test the analytics impact first with a staged rollout rather than flipping it site-wide on a Friday.

You need analytics attribution to work. If marketing depends on knowing which external site sent the traffic, the direction matters: Referrer-Policy controls what your site sends when users leave, not what you learn about incoming traffic. Your incoming attribution depends on other sites' policies, so restricting your own does not blind your analytics. This is the most common confusion about the header.

If you are unsure, strict-origin-when-cross-origin is the safe middle. It is what modern browsers already do; the header just makes it explicit and universal.

How to set it

nginx, in the server or location block:

add_header Referrer-Policy "strict-origin-when-cross-origin" always;

Apache, either in the virtual host or in .htaccess:

Header always set Referrer-Policy "strict-origin-when-cross-origin"

For Laravel/Symfony applications, set it in middleware if you prefer app-level control, though the web server level is simpler because it covers every response including static assets.

IIS, via web.config:

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Referrer-Policy" value="strict-origin-when-cross-origin" />
    </customHeaders>
  </httpProtocol>
</system.webServer>

Meta tag fallback, if you cannot touch server config: <meta name="referrer" content="strict-origin-when-cross-origin">. This is the fallback the MDN practical guide lists, and it works, but it only covers HTML documents, not API responses, and it must be the first meta element in the head to take effect for subresources that start loading early. The header is better whenever you have the choice. One more note from the spec worth knowing: the fallback syntax Referrer-Policy: no-referrer, strict-origin-when-cross-origin is valid in the header (browsers use the last recognized value), but the per-element referrerpolicy attribute does not support multiple values.

Per-element overrides: the quiet leak path

The header sets a default, but any element can override it. An <a href="..." referrerpolicy="unsafe-url"> sends the full URL from that page to that destination, no matter what the header says. A <meta> tag in a single page can set a different policy for that page. A fetch call can pass referrerPolicy in its options.

In practice this is where the header goes to die. The site sets a good global policy, a tracking script on the checkout page sets referrerpolicy="unsafe-url" on its pixel because the vendor's integration guide said to, and the policy is silently worthless on that one page. If a scan flags your Referrer-Policy while the header looks fine, this is the first place to look.

Grep the rendered HTML for referrerpolicy attributes:

curl -s https://example.com/ | grep -i referrerpolicy

If the crawl finds attributes with weak values, either fix them or set a CSP that blocks the scripts that add them. The honest option is usually to accept that you cannot fully control third-party scripts' attribute usage, and to keep the global policy for the content you control.

How to check your header today

Three levels of checking, in increasing effort.

curl, from anywhere:

curl -sI https://example.com/ | grep -i referrer

You want to see Referrer-Policy: strict-origin-when-cross-origin in the response. Absence of the header means every browser falls back to its own default, which today is mostly strict-origin-when-cross-origin but is not a commitment on your side.

DevTools, for the behavior beyond the header. Open the Network tab, click a link to an external site, and look at the request that lands on the third-party domain: the Referer value on that request is the truth, not the header. The header on your HTML is a claim; the Referer on outbound requests is the fact. DevTools shows the referrer policy per request, which is the fastest way to find a script overriding your global setting.

A full security headers scan, which checks the header on every response type, HTML included but also API responses and redirects. Some servers add the header to HTML only; a scan will find the gap. The scan also cross-checks the effective behavior: whether the values on your per-element overrides contradict the header, and whether the header value is one of the eight valid tokens (a typo like strict-origin-cross-origin silently degrades to browser default, and nothing warns you).

What this header does not do

Two limits worth stating plainly, because the header gets oversold in both directions.

It does not stop cross-site tracking. Ad networks track via cookies and fingerprinting; the Referer header is one channel among many, and closing it removes a leak, not tracking itself.

It is not CSRF protection. The presence or absence of a Referer is not an integrity signal, and the web.dev best-practices page says this directly: do not use referrers for CSRF protection, use CSRF tokens. Browsers can strip the Referer for legitimate reasons (extensions, privacy settings, other policies on the referring page), so a missing Referer proves nothing either way.

The five-minute version

  1. curl -sI https://yourdomain/ | grep -i referrer — see what you send today.
  2. If nothing comes back, add the header: add_header Referrer-Policy "strict-origin-when-cross-origin" always; in nginx or the Apache equivalent.
  3. Click an outbound link in DevTools and confirm the Referer on the third-party request is origin-only.
  4. Crawl for referrerpolicy attributes that override the header with weak values.
  5. Re-run a headers scan to confirm the header is on every response type, and that API endpoints and redirects carry it too.

The whole change is one line of server config and one round of checking. If your URLs contain anything you would not paste into a partner's contact form, this is the cheapest fix on the security headers list.

CheckWebSecurity's external scan checks your full security headers set from the outside, including Referrer-Policy on every response type, per-element override conflicts, and invalid token values that silently fall back to browser defaults. Start a free scan and see what your site sends when nobody is watching the outbound requests.


Related: Content Security Policy explained · HSTS explained · Mixed content: how to find every instance