Privacy & Data Leak Prevention

Referrer-Policy: Guarding Against Accidental Data Leaks

The forgotten HTTP header that dictates how much of your URL is shared when users navigate away from your site.

Author Avatar By Chris Tyler | October 30, 2025 | 4 min read

Every time a user clicks a link on your site, their browser sends a Referer (or Referrer) header to the destination site, indicating the exact URL they came from. If your URL contains sensitive data (e.g., session IDs, filter parameters, or internal page names), you are leaking that data to a third party. This leakage can occur to external analytics, ad platforms, or any site the user navigates to from yours.

The Unintentional Data Exposure

The problem is most acute when your application stores state or sensitive identifiers directly within the URL's query parameters. Consider a scenario where a banking application uses a temporary session identifier in the URL before a permanent cookie is set, or an e-commerce site uses a highly descriptive internal ID.

Example of Leaked Data

If your user clicks an external link from this page:

https://myservice.com/profile?user_id=12345&temp_sess=xyz789&secret_code=42

The external site receives the entire URL in the `Referer` header, including `user_id`, `temp_sess`, and the sensitive `secret_code`.

The Solution: The Referrer-Policy Header

The Referrer-Policy HTTP header allows you to control exactly how much information the browser includes when a user clicks a link that leaves your origin. This prevents the accidental leakage of sensitive query string data from your internal application to external analytics or ad platforms.

Here are the two most crucial and recommended policies for modern web security:

Implementation Methods

You should implement a single, consistent policy across your entire site. The preferred and most robust method is setting it as an HTTP header.

Method 1: HTTP Response Header (Best Practice)

// Sent by your server on every page request

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

Method 2: HTML Meta Tag (Fallback or Specific Page Override)

You can also set this within the HTML document's <head>, though the HTTP header method is generally superior as it applies before the browser processes the page content.

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

By adopting a robust Referrer-Policy, you take a critical step in protecting your user's privacy and ensuring that internal application details stay where they belong: securely within your domain boundaries.

Ready to harden your HTTP headers?

Implementing `Referrer-Policy` is just one step in securing your entire header set. Don't forget CSP and HSTS!

Check Your Current Policy