Referrer Policy 介紹

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

當使用者在瀏覽器上點擊一個連結時,會產生一個 HTTP 要求,用於擷取新的頁面內容,而在該請求的前序中,會包含一個 Referrer,用以指定該請求是從哪個頁面跳轉頁來的,常被用於分析使用者來源等資訊。但是也有成為使用者的一個不安全因素,比如有些網站直接將 sessionid 或是 token 放在地址欄裡傳遞的,會原樣不動地當作 Referrer 前序的內容傳遞給第三方網站。

所以就有了 Referrer Policy,用於過濾 Referrer 前序內容,目前是一個候選標準,不過已經有部分瀏覽器支援該標準。具體的可查看這裡。

指令值

目前包含了以下幾種指令值:

enum ReferrerPolicy {  "",  "no-referrer",  "no-referrer-when-downgrade",  "same-origin",  "origin",  "strict-origin",  "origin-when-cross-origin",  "strict-origin-when-cross-origin",  "unsafe-url"};

Null 字元串

按照瀏覽器的預設值執行。預設值為 no-referrer-when-downgrade。部分標籤可重定義此安全性原則。

 

no-referrer

從字面意思就可以理解,不傳遞 Referrer 前序的值。

no-referrer-when-downgrade

當發生降級(比如從 https:// 跳轉到 http:// )時,不傳遞 Referrer 前序。但是反過來的話不受影響。通常也會當作瀏覽器的預設安全性原則。

原地址跳轉地址Referrerhttps://example.com?token=123https://example.com/pathhttps://example.com?token=123http://example.com?token=123http://example.com/pathhttp://example.com?token=123https//example.comhttp://example.com/path無(協議降級)http://example.com?token=123https://example.com/pathhttp://example.com?token=123

same-origin

同源,即當協議、網域名稱和連接埠(如果有一方指定的話)都相同,才會傳遞 Referrer。

原地址跳轉地址Referrerhttps://example.com?token=123https://example.com/pathhttps://example.com?token=123http://example.com?token=123http://example.com/pathhttp://example.com?token=123https//example.comhttp://example.com/path無(協議不同)http://example.com?token=123https://example.com/path無(協議不同)http://example.com?token=123http://example.com:88/path無(連接埠不同)https://example.com?token=123https://caixw.io無(網域名稱不同)

origin

將當前頁面過濾掉參數及路徑部分,僅將協議、網域名稱和連接埠(如果有的話)當作 Referrer。

原地址跳轉地址Referrerhttps://example.com?token=123https://example.com/pathhttps://example.comhttp://example.com?token=123https://example.com/pathhttp://example.comhttps://example.com?token=123https://caixw.iohttps://example.com

strict-origin

類似於 origin,但是不能降級。

原地址跳轉地址Referrerhttps://example.com?token=123https://example.com/pathhttps://example.comhttp://example.com?token=123https://example.com/pathhttp://example.comhttp://example.com?token=123http://caixw.iohttp://example.comhttps://example.com?token=123http://caixw.io無

origin-when-cross-origin

跨域時(協議、網域名稱和連接埠只有一個不同)和 origin 模式相同,否則 Referrer 還是傳遞當前頁的全路徑。

原地址跳轉地址Referrerhttps://example.com?token=123https://example.com/pathhttps://example.com?token=123http://example.com?token=123https://example.com/pathhttp://example.com?token=123http://example.com?token=123http://caixw.iohttp://example.com

strict-origin-when-cross-origin

與 origin-when-cross-origin 類似,但不能降級。

原地址跳轉地址Referrerhttps://example.com?token=123https://example.com/pathhttps://example.com?token=123https://example.com?token=123https://caixw.iohttps://example.comhttps://example.com?token=123http://example.com/path無https://example.com?token=123http://example.com/無

unsafe-url

任意情況下,都發送當前頁的全部地址到 Referrer,最寬鬆和不安全的策略。

傳遞方式

Referrer-Policy 前序

推薦的方式,直接在 Referrer-Policy 前序中設定。

Referrer-Policy: origin;

Meta

通過指定 name 值為 referrer 的 meta 標籤,也可以達到相同的效果:

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

content 可以是上面的指定的值,也可以是下面這幾種舊的指令值,會自動作相應的轉換,但不推薦這些舊的指令值:

LegacyReferrerneverno-referrerdefaultno-referrer-when-downgradealwaysunsafe-urlorigin-when-crossoriginorigin-when-cross-origin

標籤屬性

  • a 和 link 標籤可以通過屬性 rel 指定 noreferrer,僅對當前連結有效;
  • a、area、link、iframe 和 img 還可以通過 referrerpolicy 指定僅針對當前連結的設定。

參考

Referrer Policy

Referrer-Policy

瀏覽器的同源策略

 

 

原文地址:https://caixw.io/posts/2017/referrer-policy.html

211 次點擊  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.