Referrer Policy 介紹

當(dāng)用戶在瀏覽器上點(diǎn)擊一個(gè)鏈接時(shí),會(huì)產(chǎn)生一個(gè) HTTP 請(qǐng)求,用于獲取新的頁面內(nèi)容,而在該請(qǐng)求的報(bào)頭中,會(huì)包含一個(gè) Referrer,用以指定該請(qǐng)求是從哪個(gè)頁面跳轉(zhuǎn)頁來的,常被用于分析用戶來源等信息。但是也有成為用戶的一個(gè)不安全因素,比如有些網(wǎng)站直接將 sessionid 或是 token 放在地址欄里傳遞的,會(huì)原樣不動(dòng)地當(dāng)作 Referrer 報(bào)頭的內(nèi)容傳遞給第三方網(wǎng)站。

所以就有了 Referrer Policy,用于過濾 Referrer 報(bào)頭內(nèi)容,目前是一個(gè)候選標(biāo)準(zhǔn),不過已經(jīng)有部分瀏覽器支持該標(biāo)準(zhǔn)。具體的可查看這里。

指令值

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

enum ReferrerPolicy {

"",

"no-referrer",

"no-referrer-when-downgrade",

"same-origin",

"origin",

"strict-origin",

"origin-when-cross-origin",

"strict-origin-when-cross-origin",

"unsafe-url"

};

空字符串

按照瀏覽器的默認(rèn)值執(zhí)行。默認(rèn)值為 no-referrer-when-downgrade。部分標(biāo)簽可重定義此安全策略。

no-referrer

從字面意思就可以理解,不傳遞 Referrer 報(bào)頭的值。

no-referrer-when-downgrade

當(dāng)發(fā)生降級(jí)(比如從 https:// 跳轉(zhuǎn)到 http:// )時(shí),不傳遞 Referrer 報(bào)頭。但是反過來的話不受影響。通常也會(huì)當(dāng)作瀏覽器的默認(rèn)安全策略。

原地址 跳轉(zhuǎn)地址 Referrer

https://example.com?token=123 https://example.com/path https://example.com?token=123

http://example.com?token=123 http://example.com/path http://example.com?token=123

https//example.com http://example.com/path 無(協(xié)議降級(jí))

http://example.com?token=123 https://example.com/path http://example.com?token=123

same-origin

同源,即當(dāng)協(xié)議、域名和端口(如果有一方指定的話)都相同,才會(huì)傳遞 Referrer。

原地址 跳轉(zhuǎn)地址 Referrer

https://example.com?token=123 https://example.com/path https://example.com?token=123

http://example.com?token=123 http://example.com/path http://example.com?token=123

https//example.com http://example.com/path 無(協(xié)議不同)

http://example.com?token=123 https://example.com/path 無(協(xié)議不同)

http://example.com?token=123 http://example.com:88/path 無(端口不同)

https://example.com?token=123 https://caixw.io 無(域名不同)

origin

將當(dāng)前頁面過濾掉參數(shù)及路徑部分,僅將協(xié)議、域名和端口(如果有的話)當(dāng)作 Referrer。

原地址 跳轉(zhuǎn)地址 Referrer

https://example.com?token=123 https://example.com/path https://example.com

http://example.com?token=123 https://example.com/path http://example.com

https://example.com?token=123 https://caixw.io https://example.com

strict-origin

類似于 origin,但是不能降級(jí)。

原地址 跳轉(zhuǎn)地址 Referrer

https://example.com?token=123 https://example.com/path https://example.com

http://example.com?token=123 https://example.com/path http://example.com

http://example.com?token=123 http://caixw.io http://example.com

https://example.com?token=123 http://caixw.io 無

origin-when-cross-origin

跨域時(shí)(協(xié)議、域名和端口只有一個(gè)不同)和 origin 模式相同,否則 Referrer 還是傳遞當(dāng)前頁的全路徑。

原地址 跳轉(zhuǎn)地址 Referrer

https://example.com?token=123 https://example.com/path https://example.com?token=123

http://example.com?token=123 https://example.com/path http://example.com?token=123

http://example.com?token=123 http://caixw.io http://example.com

strict-origin-when-cross-origin

與 origin-when-cross-origin 類似,但不能降級(jí)。

原地址 跳轉(zhuǎn)地址 Referrer

https://example.com?token=123 https://example.com/path https://example.com?token=123

https://example.com?token=123 https://caixw.io https://example.com

https://example.com?token=123 http://example.com/path 無

https://example.com?token=123 http://example.com/ 無

unsafe-url

任意情況下,都發(fā)送當(dāng)前頁的全部地址到 Referrer,最寬松和不安全的策略。

傳遞方式

Referrer-Policy 報(bào)頭

推薦的方式,直接在 Referrer-Policy 報(bào)頭中設(shè)置。

Referrer-Policy: origin;

Meta

通過指定 name 值為 referrer 的 meta 標(biāo)簽,也可以達(dá)到相同的效果:

content 可以是上面的指定的值,也可以是下面這幾種舊的指令值,會(huì)自動(dòng)作相應(yīng)的轉(zhuǎn)換,但不推薦這些舊的指令值:

Legacy Referrer

never no-referrer

default no-referrer-when-downgrade

always unsafe-url

origin-when-crossorigin origin-when-cross-origin

標(biāo)簽屬性

a 和 link 標(biāo)簽可以通過屬性 rel 指定 noreferrer,僅對(duì)當(dāng)前鏈接有效;

a、area、link、iframe 和 img 還可以通過 referrerpolicy 指定僅針對(duì)當(dāng)前鏈接的設(shè)置。

參考

Referrer Policy

Referrer-Policy

瀏覽器的同源策略

Referrer Policy 介紹

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,596評(píng)論 19 139
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,879評(píng)論 2 45
  • 現(xiàn)在的我在返程的車上,C2808,由鄭州東開往宋城路,現(xiàn)在的時(shí)間是1:20,車票是超哥訂的,地鐵票也是超哥買的?,F(xiàn)...
    我淑閱讀 628評(píng)論 25 12
  • (1) 兩個(gè)月前,第一天到達(dá)布魯塞爾的時(shí)候,是晉哥來接的我們。 晉哥是比利時(shí)的華裔,上了大學(xué)才學(xué)的中文,不過已經(jīng)說...
    嘿嘿皮卡秋閱讀 235評(píng)論 0 2
  • 只有專一,不要想太多,才能夠集中精力,才能夠認(rèn)真完成一件事。既然選擇考研,其他的就不要再想了,精力有限,有得必有失。
    小曹頭閱讀 264評(píng)論 0 0

友情鏈接更多精彩內(nèi)容