# Referer-Policy

### Introductions&#x20;

As we know, HTTP Header Referer shows where you are coming from when accessing a website. Suppose you are surfing www.facebook.com and suddenly see a link to a store selling a shirt on sale. You click on it to see the shirt out of curiosity, maybe you will buy that shirt too. One thing that is not surprising is that the moment you click on the link, the clothing store will know that you came to their website from Facebook. Furthermore, they can measure the percentage of purchases coming from Facebook compared to other marketing channels. From there, appropriate adjustments can be made to the advertising campaign. The way it works is relatively simple, every time a user clicks on a link, a header referer will be attached.

However, let's look at another example, which is Google Docs. As we often use Google Docs to share documents with each other. The simplest is through two steps:

Share the permission of the text as "Anyone with link can view/edit" Send the link to others Each link of a document has the form [https://docs.google.com/document/d/some-random-id/edit.](https://docs.google.com/document/d/some-random-id/edit.) Basically, some-random-id is complex enough that no one can figure it out on their own unless it's shared. So basically sharing links with each other is relatively safe.

Take for example the text [https://docs.google.com/document/d/1QHmwfKoekal9HJDu-\_3zol5Ht2TGtfiSumHWVD9LRgo/edit](https://docs.google.com/document/d/1QHmwfKoekal9HJDu-_3zol5Ht2TGtfiSumHWVD9LRgo/edit). This document contains links to Dan Tri newspaper and VnExpress newspaper, as well as my bank account information. If you click on the link in the file above, will the request to Dan Tri and VnExpress newspapers have the header below attached?

If the answer is yes, it means that the web administrator of Dan Tri and VnExpress can know the link to my document, which means they know my bank account information, if I share it again. If you share this document with **Anyone with link can edit** permission, things will get worse, that person can change the password in this document, making it impossible for you to log in next time.

OK. If you have checked, you may be surprised because there is indeed a Referer header sent when clicking on the real newspaper page, but its value is only [https://www.google.com/](https://www.google.com/) and has absolutely no value. value of some-random-id.

<figure><img src="https://1722711354-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwNXdoUkfmcozr29fRrfb%2Fuploads%2FFJKTqEOmGD7c7DBNvoNo%2Fimage.png?alt=media&#x26;token=6bdfa03c-66bf-46bd-a31d-7eab027fea8b" alt=""><figcaption></figcaption></figure>

So that means you're still safe. In other words, if you click on a link in Google Docs, the webmaster only knows that you came to their website from Google's website, but cannot know exactly which link. So why?

### Referrer-Policy <a href="#referrer-policy" id="referrer-policy"></a>

Our savior is Referrer-Policy. In the example above, to put it simply, google docs does not allow the full link to be attached to the referer header, it only attaches the origin, which means some-random-id is not disclosed to Dan Tri and VnExpress, or any other website.

The Referrer-Policy HTTP header controls how much referrer information (sent via the Referer header) should be included with requests.

#### no-referrer <a href="#no-referrer" id="no-referrer"></a>

The `no-referrer` directive implies that the HTTP Referer header will not be sent and thus, HTTP requests will not contain such details.

#### no-referrer-when-downgrade <a href="#no-referrer-when-downgrade" id="no-referrer-when-downgrade"></a>

The `no-referrer-when-downgrade` directive stipulates that the origin, _path_, and _query string_ will be sent with HTTP requests unless the HTTP Connection is downgraded to one that is less secure. For example, if the HTTP Connection is downgraded from HTTPS to HTTP, then the HTTP Referer header will not be included with HTTP requests.

#### origin <a href="#origin" id="origin"></a>

The `origin` directive indicates that only the client’s origin will be sent in the HTTP Referer header.

#### origin-when-cross-origin <a href="#origin-when-cross-origin" id="origin-when-cross-origin"></a>

When the `origin-when-cross-origin` directive is included, a _same-origin_ HTTP request using the same protocol will include the origin, _path_, and _query string_. For _cross-origin_ HTTP requests, as well as where the security of the protocol is downgraded, only the origin will be sent with the HTTP Referer header.

#### same-origin <a href="#same-origin" id="same-origin"></a>

The `same-origin directive` implies that the origin will be sent with each HTTP request, but the HTTP Referer header will not be included with _cross-origin_ HTTP requests.

#### strict-origin <a href="#strict-origin" id="strict-origin"></a>

When the `strict-origin` directive is present, the origin will be sent but only when the security level of the protocol stays the same.

#### strict-origin-when-cross-origin <a href="#strict-origin-when-cross-origin" id="strict-origin-when-cross-origin"></a>

The `strict-origin-when-cross-origin` directive is the same as `strict-origin`, although the HTTP [Referer](https://http.dev/referer) header will not be sent for _cross-origin_ HTTP requests. When no policy is specified then this is the default value. It is also used if the specified directive is not understood.

{% hint style="info" %}
**Note**

Before November of 2020, the default directive was `no-referrer-when-downgrade`.
{% endhint %}

#### unsafe-url <a href="#unsafe-url" id="unsafe-url"></a>

The `unsafe-url` directive allows the origin, _path_, and _query string_ to be included for any HTTP request, even when the security is minimal.

### Fun fact <a href="#fun-fact" id="fun-fact"></a>

Header Referer is spelled incorrectly, the correct spelling should be Referrer, but when too many people use it, no one dares to correct it. Fear of damaging the already complex internet system. This is a very typical example of how the entire global digital system is built and operated 😅. And it is a fertile ground for hackers around the world to exploit.
