Referrer Policy 介绍
发布于 署名 4.0 国际 (CC BY 4.0) 原文链接:https://caixw.io/posts/2017/referrer-policy.html
当用户在浏览器上点击一个链接时,会产生一个 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"
};
空字符串
按照浏览器的默认值执行。默认值为 no-referrer-when-downgrade。部分标签可重定义此安全策略。
no-referrer
从字面意思就可以理解,不传递 Referrer 报头的值。
no-referrer-when-downgrade
当发生降级(比如从 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 |
same-origin
同源,即当协议、域名和端口(如果有一方指定的话)都相同,才会传递 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 | 无(域名不同) |
origin
将当前页面过滤掉参数及路径部分,仅将协议、域名和端口(如果有的话)当作 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 |
strict-origin
类似于 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 | 无 |
origin-when-cross-origin
跨域时(协议、域名和端口只有一个不同)和 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 |
strict-origin-when-cross-origin
与 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/ | 无 |
unsafe-url
任意情况下,都发送当前页的全部地址到 Referrer,最宽松和不安全的策略。
传递方式
Referrer-Policy 报头
推荐的方式,直接在 Referrer-Policy 报头中设置。
Referrer-Policy: origin;
Meta
通过指定 name 值为 referrer 的 meta 标签,也可以达到相同的效果:
<meta name="referrer" content="strict-origin" />
content 可以是上面的指定的值,也可以是下面这几种旧的指令值,会自动作相应的转换,但不推荐这些旧的指令值:
| Legacy | Referrer |
|---|---|
| never | no-referrer |
| default | no-referrer-when-downgrade |
| always | unsafe-url |
| origin-when-crossorigin | origin-when-cross-origin |
标签属性
a和link标签可以通过属性rel指定noreferrer,仅对当前链接有效;a、area、link、iframe和img还可以通过referrerpolicy指定仅针对当前链接的设置。
参考
Referrer Policy 介绍的更多相关文章
- HTTP系列之Referer和Referrer policy简介
目录 @ 1.前言摘要 在csdn网站随便抓个链接来看看: Referer参数: referrer policy是unsafe url的,ok,下面介绍一下Referer和referrer polic ...
- referrer policy
我们知道,在页面引入图片.JS 等资源,或者从一个页面跳到另一个页面,都会产生新的 HTTP 请求,浏览器一般都会给这些请求头加上表示来源的 Referrer 字段.Referrer 在分析用户来源时 ...
- HTTP的Referrer和Referrer Policy设置
Referrer referrer是HTTP请求header的报文头,用于指明当前流量的来源参考页面.通过这个信息,我们可以知道访客是怎么来到当前页面的.这对于Web Analytics非常重要,可以 ...
- HTTP Referrer和Referrer Policy 设置
referrer是HTTP请求header的报文头,用于指明当前流量的来源参考页面.通过这个信息,我们可以知道访客是怎么来到当前页面的.这对于Web Analytics非常重要,可以用于分析不同渠道流 ...
- 请求出现Referrer Policy: no-referrer-when-downgrade
请求出现Referrer Policy: no-referrer-when-downgrade,一直请求不成功,原因是请求连接出现问题,我这里的问题是api前少了/,导致字段和域名拼接起来,所以请求U ...
- Content Security Policy介绍
Content Security Policy https://content-security-policy.com/ The new Content-Security-Policy HTTP re ...
- 关于启用 HTTPS 的一些经验分享
https://imququ.com/post/sth-about-switch-to-https.html 随着国内网络环境的持续恶化,各种篡改和劫持层出不穷,越来越多的网站选择了全站 HTTPS. ...
- JavaWeb_响应和请求数据包
Google浏览器 F12中Network->Header部分 <%@ page language="java" import="java.util.*&qu ...
- img引用网络图片资源无法加载问题解决
近期在自己项目中遇到引用一些网络图片资源,显示无法加载,但是在浏览器打开图片路径又可以显示的问题 解决办法: 在图片显示的界面把meta referrer标签改为never <meta name ...
随机推荐
- Jersey RESTful WebService框架学习(六)接收MultivaluedMap类型参数
现在的web开发中有些工程会觉得实体bean的架构会比较重,现在的持久层的框架的特点也层出不穷,核心思想的ORM在此基础上,提供了很多便捷操作,mybatis,jfinal(内部持久层框架)之类的也诞 ...
- 知识点:CSS代码语法
css 样式由选择符和声明组成,而声明又由属性和值组成,如下图所示: 选择符:又称选择器,指明网页中要应用样式规则的元素,如本例中是网页中所有的段(p)的文字将变成蓝色,而其他的元素(如ol)不会受到 ...
- (转)Log4Net 全方位跟踪程序运行
转自:http://www.cnblogs.com/qingyuan/archive/2011/05/13/2045616.html 前端日子自己写了一个简单的日志跟踪程序,现在目前正在做的一个项目中 ...
- Alpha阶段敏捷冲刺(八)
1.站立式会议 提供当天站立式会议照片一张 2.每个人的工作 (有work item 的ID),并将其记录在码云项目管理中: 昨天已完成的工作. 祁泽文:写了关于统计的按钮的代码. 徐璐琳:完善了&q ...
- hihocoder#1631 : Cats and Fish
Description There are many homeless cats in PKU campus. They are all happy because the students in t ...
- PB常用函数
弹出窗口:messagebox() 基本写法:Messagebox('标题','内容') 完整写法: MessageBox ( '标题','内容',图标,按键,默认值) (1)其中标题与内容为要显示的 ...
- 64位进程调用32位dll的解决方法
64位进程调用32位dll的解决方法 最近做在Windows XP X64,VS2005环境下做32位程序编译为64位程序的工作,遇到了一些64位编程中可能遇到的问题:如内联汇编(解决方法改为C/ ...
- 在windows右键菜单中加入自己的程序 [转载]
原文链接: http://blog.csdn.net/marklr/article/details/4006356 在windows右键菜单中加入自己的程序 标签: windowsattribute ...
- Spring下配置几种常用连接池
1.连接池概述 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正是 ...
- petapoco 新手上路
PetaPoco是一个轻量级ORM框架 用法可参考http://www.toptensoftware.com/petapoco/ https://github.com/CollaboratingPl ...