---
url: "https://web.dev/articles/referrer-best-practices"
titulek: "Referer and Referrer-Policy best practices | Articles | web.dev"
h1: "Referer and Referrer-Policy best practices Stay organized with collections Save and categorize content based on your preferences."
popis: "Consider setting a referrer policy of `strict-origin-when-cross-origin`. It retains much of the referrer's usefulness, while mitigating the risk of leaking data cross-origins."
jazyk: "en"
kanonicka: "https://web.dev/articles/referrer-best-practices"
drobecky: ["Articles", "Referer and Referrer-Policy best practices"]
zdroj: "live"
wayback_snapshot: ""
stazeno: "2026-09-13 22:27:25"
znaku: 20027
slov: 2924
kodovani: "iso-8859-2"
sha256: "e1a3157daae9319584f269fade2637c8aa8376dbe94f78bf24d07b282f8adb73"
---
Referer and Referrer-Policy best practices
Stay organized with collections
Save and categorize content based on your preferences.
Maud Nalpas
This page outlines some best practices for setting your Referrer-Policy and
using the referrer in incoming requests. Summary Unexpected cross-origin information leakage damages web users' privacy. A
protective referrer policy can help. Consider setting a referrer policy of `strict-origin-when-cross-origin`. It
preserves most of the referrer's usefulness, while mitigating the risk of
leaking data cross-origins. Don't use referrers for Cross-Site Request Forgery (CSRF) protection. Use
[CSRF tokens](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#token-based-mitigation)
instead, and other headers as an extra layer of security. Referer and Referrer-Policy 101 HTTP requests can include an optional [`Referer` header](https://developer.mozilla.org/docs/Web/HTTP/Headers/Referer),
which indicates the origin or web page URL the request was made from. The
[`Referrer-Policy` header](https://developer.mozilla.org/docs/Web/HTTP/Headers/Referrer-Policy)
defines what data is made available in the `Referer` header. In the following example, the `Referer` header includes the complete URL of the
page on `site-one` that the request was made from. An HTTP request with a Referer header. The `Referer` header might be present in different types of requests: Navigation requests, when a user clicks a link. Subresource requests, when a browser requests images, iframes, scripts, and
other resources that a page needs. For navigations and iframes, you can also access this data with JavaScript using
`document.referrer`. You can learn a lot from `Referer` values. For example, an analytics service
might use them to determine that 50% of the visitors on `site-two.example` came
from `social-network.example`. But when the full URL, including the path and
query string, is sent in the `Referer` **across origins**, it can endanger user
privacy and create security risks: Using the full URL can impact user privacy
and security. URLs #1 to #5 contain private information, and sometimes sensitive or
identifying information. Leaking these silently across origins can compromise
web users' privacy. URL #6 is a [capability URL](https://www.w3.org/TR/capability-urls/). If anyone
other than the intended user receives this, a malicious actor can take control
of this user's account. **To restrict what referrer data is made available for requests from your site,
you can set a referrer policy.** What policies are available and how do they differ? You can select one of eight policies. Depending on the policy, the data
available from the `Referer` header (and `document.referrer`) can be: No data (no `Referer` header is present) Only the [origin](/articles/same-site-same-origin#origin) The full URL: origin, path, and query string Examples of Referer data. Some policies are designed to behave differently depending on the **context**:
cross-origin or same-origin request, whether the request destination is as
secure as the origin, or both. This is useful to limit the amount of information
shared across origins or to less secure origins, while maintaining the richness
of the referrer within your own site. The following table shows how referrer policies restrict the URL data available
from the Referer header and `document.referrer`: Policy scope Policy name Referer: No data Referer: Origin only Referer: Full URL Doesn't consider the request context `no-referrer` check `origin` check `unsafe-url` check Security-focused `strict-origin` Request from HTTPS to HTTP Request from HTTPS to HTTPS
or HTTP to HTTP `no-referrer-when-downgrade` Request from HTTPS to HTTP Request from HTTPS to HTTPS
or HTTP to HTTP Privacy-focused `origin-when-cross-origin` Cross-origin request Same-origin request `same-origin` Cross-origin request Same-origin request Privacy and security-focused `strict-origin-when-cross-origin` Request from HTTPS to HTTP Cross-origin request
from HTTPS to HTTPS
or HTTP to HTTP Same-origin request MDN provides a [full list of policies and behavior
examples](https://developer.mozilla.org/docs/Web/HTTP/Headers/Referrer-Policy#Directives). Here are some things to be aware of when setting a referrer policy: All policies that take the scheme (HTTPS versus HTTP) into account
(`strict-origin`, `no-referrer-when-downgrade`, and
`strict-origin-when-cross-origin`) treat requests from one HTTP origin to
another HTTP origin the same way as requests from an HTTPS origin to another
HTTPS origin, even though HTTP is less secure. That's because for these
policies, what matters is whether a security **downgrade** takes place; that
is, if the request can expose data from an encrypted origin to an unencrypted
one, as in HTTPS â HTTP requests. An HTTP â HTTP request is completely
unencrypted, so there's no downgrade. If a request is **same-origin**, this means that the scheme (HTTPS or HTTP) is
the same, so there's no security downgrade. Default referrer policies in browsers *As of October 2021* **If no referrer policy is set, the browser uses its default policy.** Browser Default `Referrer-Policy` / Behavior Chrome
The default is `strict-origin-when-cross-origin`.
Firefox
The default is `strict-origin-when-cross-origin`.
Starting from [version 93](https://blog.mozilla.org/security/2021/10/05/firefox-93-features-an-improved-smartblock-and-new-referrer-tracking-protections/),
for Strict Tracking Protection and Private Browsing users, the less
restrictive referrer policies `no-referrer-when-downgrade`,
`origin-when-cross-origin`, and `unsafe-url` are
ignored for cross-site requests, meaning the referrer is always trimmed
for cross-site requests, regardless of the website's policy.
Edge
The default is `strict-origin-when-cross-origin`.
Safari
The default is similar to `strict-origin-when-cross-origin`,
with some specific differences. See
[Preventing Tracking Prevention Tracking](https://webkit.org/blog/9661/preventing-tracking-prevention-tracking/) for details.
Best practices for setting referrer policy There are different ways to set referrer policies for your site: As an HTTP header Within your
[HTML](https://developer.mozilla.org/docs/Web/HTTP/Headers/Referrer-Policy#Integration_with_HTML) From JavaScript on a [per-request basis](https://javascript.info/fetch-api#referrer-referrerpolicy) You can set different policies for different pages, requests, or elements. The HTTP header and the meta element are both page-level. The priority order for
determining an element's effective policy is as follows: Element-level policy Page-level policy Browser default **Example:** `index.html`: `
` The image is requested with a `no-referrer-when-downgrade` policy, and all other
subresource requests from this page follow the `strict-origin-when-cross-origin`
policy. How to see the referrer policy? [securityheaders.com](https://securityheaders.com/) is handy to determine which
policy a specific site or page is using. You can also use the developer tools in Chrome, Edge, or Firefox to see the
referrer policy used for a specific request. At the time of this writing, Safari
doesn't show the `Referrer-Policy` header, but does show the `Referer` that was
sent.
Chrome DevTools' **Network** panel with a request selected.
Which policy should you set for your website? We strongly recommend explicitly setting a privacy-enhancing policy such as
`strict-origin-when-cross-origin` (or stricter). Why "explicitly"? If you don't set a referrer policy, the browser's default policy will be usedâin fact, websites often
defer to the browser's default. But this is not ideal, because: Different browsers have different default policies, so if you rely on browser
defaults, your site won't behave predictably across browsers. Browsers are adopting stricter defaults such as `strict-origin-when-cross-origin`
and mechanisms such as [referrer trimming](https://github.com/privacycg/proposals/issues/13)
for cross-origin requests. Explicitly opting into a privacy-enhancing policy
before browser defaults change gives you control and helps you run tests as
you see fit. Why `strict-origin-when-cross-origin` (or stricter)? You need a policy that is secure, privacy-enhancing, and useful. What "useful"
means depends on what you want from the referrer: **Secure**: if your website uses HTTPS ([if not, make it a
priority](/why-https-matters)), you don't want your website's URLs to leak in
non-HTTPS requests. Since anyone on the network can see these, leaks would
expose your users to person-in-the-middle-attacks. The policies
`no-referrer-when-downgrade`, `strict-origin-when-cross-origin`, `no-referrer`,
and `strict-origin` solve this problem. **Privacy-enhancing**: for a cross-origin request, `no-referrer-when-downgrade`
shares the full URL, which can cause privacy issues.
`strict-origin-when-cross-origin` and `strict-origin` only share the origin,
and `no-referrer` shares nothing at all. This leaves you with
`strict-origin-when-cross-origin`, `strict-origin`, and `no-referrer` as
privacy-enhancing options. **Useful**: `no-referrer` and `strict-origin` never share the full URL, even
for same-origin requests. If you need the full URL, `strict-origin-when-cross-origin`
is a better option. All of this means that **`strict-origin-when-cross-origin`** is generally a
sensible choice. **Example: Setting a `strict-origin-when-cross-origin` policy** `index.html`: `` Or server-side, for example in Express: `const helmet = require('helmet'); app.use(helmet.referrerPolicy({policy: 'strict-origin-when-cross-origin'}));` What if `strict-origin-when-cross-origin` (or stricter) doesn't accommodate all your use cases? In this case, take a **progressive approach**: set a protective policy like
`strict-origin-when-cross-origin` for your website and, if you need to, a more
permissive policy for specific requests or HTML elements. Example: element-level policy `index.html`: `