一、传递指定。g0d易塔云建站-模板下载,web开发资源,技术博客g0d易塔云建站-模板下载,web开发资源,技术博客所以就有了 Referrer Policy,用于过滤 Referrer 报头包容,目前是一个候选标准,不过已经有部分浏览器支持该标准。
g0d易塔云建站-模板下载,web开发资源,技术博客g0d易塔云建站-模板下载,web开发资源,技术博客指令值:g0d易塔云建站-模板下载,web开发资源,技术博客目前包含了以下几种指令值:
enum ReferrerPolicy {g0d易塔云建站-模板下载,web开发资源,技术博客
"",g0d易塔云建站-模板下载,web开发资源,技术博客
"no-referrer",g0d易塔云建站-模板下载,web开发资源,技术博客
"no-referrer-when-downgrade",g0d易塔云建站-模板下载,web开发资源,技术博客
"same-origin",g0d易塔云建站-模板下载,web开发资源,技术博客
"origin",g0d易塔云建站-模板下载,web开发资源,技术博客
"strict-origin",g0d易塔云建站-模板下载,web开发资源,技术博客
"origin-when-cross-origin",g0d易塔云建站-模板下载,web开发资源,技术博客
"strict-origin-when-cross-origin",g0d易塔云建站-模板下载,web开发资源,技术博客
"unsafe-url"g0d易塔云建站-模板下载,web开发资源,技术博客
};
空字符串:g0d易塔云建站-模板下载,web开发资源,技术博客安装浏览器的默认值执行。默认值为 no-referrer-when-downgrade。部分标签可重定义此安全策略。g0d易塔云建站-模板下载,web开发资源,技术博客
g0d易塔云建站-模板下载,web开发资源,技术博客
no-referrer:g0d易塔云建站-模板下载,web开发资源,技术博客
从字面理解,不传递Referrer报头的值。g0d易塔云建站-模板下载,web开发资源,技术博客g0d易塔云建站-模板下载,web开发资源,技术博客no-referrer-when-downgrade:g0d易塔云建站-模板下载,web开发资源,技术博客当发生降级(比如从https://跳转到http://)时,不传递Referrer报头。但是反过来的话不受影响。通常也会当作浏览器的默认安全策略。
原地址 |
跳转地址 |
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 |
无(协议降级) |
http://example.com?token=123 |
https://example.com/path |
http://example.com?token=123 |
g0d易塔云建站-模板下载,web开发资源,技术博客same-origing0d易塔云建站-模板下载,web开发资源,技术博客
同源,即当协议、域名和端口(如果有一方指定的话)都相同,才会传递Referrer。
原地址 |
跳转地址 |
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 |
无(协议不同) |
http://example.com?token=123 |
https://example.com/path |
无(协议不同) |
http://example.com?token=123 |
http://example.com:88/path |
无(协议不同) |
https://example.com?token=123 |
https://caixw.io |
无(协议不同) |
g0d易塔云建站-模板下载,web开发资源,技术博客origing0d易塔云建站-模板下载,web开发资源,技术博客
将当前页面过滤掉参数及路径部分(仅将协议、域名和端口)当作传递Referrer。
原地址 |
跳转地址 |
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 |
g0d易塔云建站-模板下载,web开发资源,技术博客strict-origing0d易塔云建站-模板下载,web开发资源,技术博客
类似于origin,但是不能降级。
原地址 |
跳转地址 |
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 |
无(协议降级) |
g0d易塔云建站-模板下载,web开发资源,技术博客origin-when-cross-origing0d易塔云建站-模板下载,web开发资源,技术博客
跨域时(协议、域名和端口只有一个不同)和origin模式相同,否则Referrer还是传递当前页面的全路径。
原地址 |
跳转地址 |
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 |
g0d易塔云建站-模板下载,web开发资源,技术博客strict-origin-when-cross-origing0d易塔云建站-模板下载,web开发资源,技术博客
与origin-when-cross-origin类似,但不能降级。
原地址 |
跳转地址 |
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/ |
无 |
g0d易塔云建站-模板下载,web开发资源,技术博客
unsafe-urlg0d易塔云建站-模板下载,web开发资源,技术博客
任意情况下,都发送当前页的全部地址到 Referrer,最宽松和不安全的策略。g0d易塔云建站-模板下载,web开发资源,技术博客
g0d易塔云建站-模板下载,web开发资源,技术博客
二、传递方式。g0d易塔云建站-模板下载,web开发资源,技术博客
g0d易塔云建站-模板下载,web开发资源,技术博客
Referrer-Policy报头。g0d易塔云建站-模板下载,web开发资源,技术博客
推荐的方式,直接在Referrer-Policy报头中设置。g0d易塔云建站-模板下载,web开发资源,技术博客
Referrer-Policy: origin;g0d易塔云建站-模板下载,web开发资源,技术博客
g0d易塔云建站-模板下载,web开发资源,技术博客
Metag0d易塔云建站-模板下载,web开发资源,技术博客
通过指定name值为referrer的meta标签,也可以达到相同的效果:g0d易塔云建站-模板下载,web开发资源,技术博客
g0d易塔云建站-模板下载,web开发资源,技术博客
<meta name="referrer" content="strict-origin" />
g0d易塔云建站-模板下载,web开发资源,技术博客
content可以是上面指定的值,也可以是下面这几种旧的指令值,会自动做相应的转换,但不推荐这些旧的指令值:
Legacy |
Referrer |
never |
no-referrer |
default |
no-referrer-when-downgrade |
always |
unsafe-url |
origin-when-crossorigin |
origin-when-cross-origin |
g0d易塔云建站-模板下载,web开发资源,技术博客标签属性g0d易塔云建站-模板下载,web开发资源,技术博客· a和link标签可以通过属性rel指定noreferrer,仅对当前链接有效;
g0d易塔云建站-模板下载,web开发资源,技术博客· a、area、link、iframe、和img还可以通过referrerplolicy指定针对当前链接的设置。
g0d易塔云建站-模板下载,web开发资源,技术博客g0d易塔云建站-模板下载,web开发资源,技术博客参考规范:
g0d易塔云建站-模板下载,web开发资源,技术博客Referrer Policyg0d易塔云建站-模板下载,web开发资源,技术博客
Referrer Policyg0d易塔云建站-模板下载,web开发资源,技术博客
浏览器的同源策略