解决百度统计无法获取https来源的referrer

Similar documents
通过Hive将数据写入到ElasticSearch

Flume-ng与Mysql整合开发

如何在 Apache Hive 中解析 Json 数组

Guava学习之Resources

Hadoop&Spark解决二次排序问题(Hadoop篇)

使用MapReduce读取XML文件

Hive:用Java代码通过JDBC连接Hiveserver

在Spring中使用Kafka:Producer篇

使用Apache Beam读写HDFS上的文件

三种方法实现Hadoop(MapReduce)全局排序(1)

Apache Spark 2.4 新增内置函数和高阶函数使用介绍

Hadoop元数据合并异常及解决方法

江门:中国第一侨乡

是 喔, 就 是 那 個 在 BBS 醫 療 版 跟 你 嗆 聲, 自 稱 有 三 十 多 年 推 拿 經 驗 的 大 叔 嗎? 一 個 看 來 頗 為 清 秀 的 女 生 問 道, 她 語 氣 中 略 感 訝 異 是 啊, 什 麼 推 拿 按 摩 有 多 好, 還 要 人 生 病 盡 量 不 要

Flink on YARN部署快速入门指南

标题

Spark作业代码(源码)IDE远程调试

國立臺東高級中學102學年度第一學期第二次期中考高一國文科試題

<D2B0D0C4D3C5D1C52DC8CED6BEC7BF202D20BCC7CAC2B1BE>

Microsoft Word - Sunday

鎶ョ焊0

秘密大乘佛法(下)

!! :!!??!!?!??!!!... :... :'?'?! :' ' :'?' :'?' :'!' : :? Page 2

Page 2 of 12

天仁期末個人報告1.PDF

三种恢复 HDFS 上删除文件的方法

公 司 年 度 大 事 记 2015 年 10 月 -11 月, 公 司 完 成 股 份 制 改 造 10 月 13 日, 百 灵 有 限 临 时 股 东 会 作 出 决 议, 同 意 各 发 起 人 将 其 在 百 灵 有 限 拥 有 的 截 至 2015 年 8 月 31 日 经 审 计 的 原

PDF 入不思議解脫境界普賢行願品 ... 《大方廣佛華嚴經卷第四十》

Urdu Naat Books Free Download Pdf

Free Download Mivo Tv For Pc. Paraiso About private Sunday effect Georgia letra Results

Risala Film Nederlands Ondertiteld Downloadinstmank. awarded Clive ministry consulta relaxed Pocos points which

cyberghost vpn premium keygen torrent

22. PTC 能 为 用 户 托 管 ThingWorx 吗? ThingWorx 可 配 置 在 什 么 方 面? 在 哪 里 可 看 到 ThingWorx 演 示 视 频? 什 么 材 料 和 课 程 可 用 来 支 持 我 的 物 联

UDC The Design and Implementation of a Specialized Search Engine Based on Robot Technology 厦门大学博硕士论文摘要库

當母親禱告時

三种方法实现Hadoop(MapReduce)全局排序(2)

PowerPoint 演示文稿

使用Apache Spark将数据写入ElasticSearch

Itext Sign Pdf Example Download

Transcription:

我们都知道, 当我们的页面请求一个 js 文件 一个 cs 文件或者点击到其他页面, 浏览器一般都会给这些请求头加上表示来源的 Referrer 字段 Referrer 在分析用户的来源时非常有用, 比如大家熟悉的百度统计里面就利用到 Referrer 信息了 但是遗憾的是, 目前百度统计仅仅支持来源于 http 页面的 referrer 头信息 ; 也就是说, 如果你网站是 http 的, 那么百度统计只能统计到从其他 http 页面进入到你网站的 referrer, 而如果是从 https 页面进入到你的网站, 百度统计目前是无法统计到 在介绍解决办法之前, 我们先来了解 Referrer Policies Referrer Policies 如果想及时了解 Spark Hadoop 或者 Hbase 相关的文章, 欢迎关注微信公共帐号 :iteblog_hadoop 目前存在九种 Referrer Policies, 包括 : 空字符串 no-referrer, no-referrer-whendowngrade, same-origin, origin, strict-origin, origin-when-cross-origin, strict-origin-whencross-origin 以及 unsafe-url: enum ReferrerPolicy { "", "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin", "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", 1 / 5

"unsafe-url" }; 我们这对每种 Referrer Policies 进行介绍 空字符串 空字符串表示没有 referrer 策略 比如我们有一个 HTML 标签元素, 而且并没有声明任何的 Referrer Policies, 这时候的 Referrer Policies 就是空字符串 默认的空字符串 Referrer Policies 就等同于 no-referrer-whendowngrade no-referrer 最简单的 Referrer Policies 就是 no-referrer ; 这种 Referrer Policies 会导致所有的请求都不带 referrer 信息 比如如果 https://www.iteblog.com/archives/1929 页面将 Referrer Policies 设置成 no-referrer, 那么从这个页面转到 https://www.iteblog.com/( 或者其他任何页面 ) 都不会发送 Referer 头信息 no-referrer-when-downgrade 这种策略在从受 TLS 保护的 URL 跳转到任何潜在可信的 URL 以及从不受 TLS 保护的 URL( 比如 H TTP) 跳转到任何 URL 都会发送完整的 URL Referrer 信息 但是如果从受 TLS 保护的 URL( 比如 HTTPS) 跳转不受信任的 URL( 比如 HTTP), 那么 Referr er 头将不会带任何的信息 这是大多数浏览器默认的 Referrer Policies 比如 : 假设 https://www.iteblog.com/archives/1929 页面的 Referrer Policies 设置成 noreferrer-when-downgrade, 那么从这个页面跳转到任何的 https 页面将会带上值为 https://www.iteblog.com/archives/1929 的 Referer 头信息 ; 但是如果从那个页面跳转到任何 HTTP 页面, 将不会带上任何的 Referer 头信息 这就是为什么百度统计无法获取到从 HTTPS 跳转到 HTTP 的信息 same-origin 对于同源的链接, 会发送 referrer, 其他的不会 同源意味着域名需要相同,iteblog.com 和 idea.iteblog.com 是非同源的 origin 2 / 5

这种 Referrer Policies 对于任何资源 ( 包括可信和不可信 ) 来说只发送网站的根域名, 不发送完整的 url 比如 :https://www.iteblog.com/archives/1929 页面的 Referrer Policies 设置成 origin, 那么从这个页面跳转到任何网站将会带上值为 https://www.iteblog.com/ 的 Referer 头信息 strict-origin 我们可以把他看做是 origin 和 no-referrer-when-downgrade 的结合体 也就是说, 如果从受 TLS 保护的 URL 跳转到任何潜在可信的 URL 以及从不受 TLS 保护的 URL( 比如 HTTP) 跳转到任何 U RL 都会发送根域名的 Referrer 头信息 但是如果从受 TLS 保护的 URL( 比如 HTTPS) 跳转不受信任的 URL( 比如 HTTP), 那么 Referr er 头将不会带任何的信息 比如 https://www.iteblog.com/archives/1929 页面的 Referrer Policies 设置成 strict-origin, 那么从它跳转到 https://xxx.iteblog.com 将会带上值为 https://www.iteblog.com/ 的 Referer 头信息 ; 如果从那个页面跳转到 http://idea.iteblog.com 将不会带上任何的 Referer 头信息 再比如 :http://idea.iteblog.com 页面的 Referrer Policies 设置成 strictorigin, 那么从这个页面跳转到 http://books.iteblog.com 或者 https://www.iteblog.com/archives/1929 将会带上值为 http://idea.iteblog.com/ 的 Referer 头信息 不过目前这种 Referrer Policies 浏览器可能不支持 origin-when-cross-origin 该策略在同源的链接中发送完整的 URL, 其他情况仅发送根域名 需要注意的是 https://www.iteblog.com 和 https://www.iteblog.com 被认为是非同源的 比如 https://www.iteblog.com/archives/1929 页面的 Referrer Policies 设置成 origin-whencross-origin, 那么从它跳转到 https://www.iteblog.com/archives/1464 将会带上值为 https://www.iteblog.com/archives/1929 的 Referer 头信息 ; 如果从那个页面跳转到 http://idea.iteblog.com/ 页面 ( 注意这里 HTTP 和 HTTPS 页面都可以 ), 将会带上值为 https://ww w.iteblog.com/ 的 Referer 头信息 不过这种 Referrer Policies 在 Chrome 实现的时候被误写成了 origin-when-crossorigin strict-origin-when-cross-origin 这种策略可以看做是 origin-when-cross-origin 和 no-referrer-when-downgrade 的结合体 对于同源请求, 发送完整的 URL; 对于同为 https 的页面, 或者是从 HTTP 页面跳转到任何的页面 ( 包括 HTTP 和 HTTPS) 只发送根域名 ; 如果是从 https 页面跳转到 http 将不发送 referrer If a document at https://example.com/page.html sets a policy of "strict-origin-whencross-origin", then navigations to https://example.com/not-page.html would send a 3 / 5

Referer header with a value of https://example.com/page.html. Navigations from that same page to https://not.example.com/ would send a Referer header with a value of https://example.com/. Navigations from that same page to http://not.example.com/ would send no Referer header. unsafe-url 无论是否发生协议降级 (HTTPS 到 HTTP), 无论是本站链接还是站外链接, 统统都发送 Referrer 信息 这是最宽松而最不安全的策略 ; 比如 :https://www.iteblog.com/archives/1929 页面的 Referrer Policies 设置成 unsafe-url, 那么从它跳转到 http://idea.iteblog.com/ 页面 ( 注意这里 HTTP 和 HTTPS 页面都可以 ), 将会带上值为 https://www.iteblog.com/archives/1929 的 Referer 头信息 如何设置 页面是设置 Referrer Policies 主要有以下几种 CSP 响应头 CSP(Content Security Policy), 是一个跟页面内容安全有关的规范 在 HTTP 中通过响应头中的 Content-Security-Policy 字段来告诉浏览器当前页面要使用何种 CSP 策略 : Content-Security-Policy: referrer 我们还可以在里面设置 : <meta http-equiv="content-security-policy" content="referrer"> <meta> 标签 通过标签也可以指定 Referrer 策略, 同样很简单 : <meta name="referrer" content="no-referrer"> 4 / 5

Powered by TCPDF (www.tcpdf.org) 我们把 <meta> 放在 <head>...</head> 之间 注意, 如果出现的位置不对会被忽略 同样, 如果没有给它定义 content 属性, 或者 content 属性为空, 也会被忽略 如果 content 属性不是合法的取值, 浏览器会自动选择 noreferrer 这种最严格的策略 <a> 标签的 referrer 属性 通过给 <a> 标签增加 referrer 属性也可以指定 Referrer 策略, 格式如下 : <a href="https://www.iteblog.com" referrer="no-referrer"> 过往记忆 </a> 这种方式作用的只是这一个链接 并且,<a> 标签可用的 Referrer 策略只有三种 :noreferrer origin 以及 unsafe-url 另外, 这样针对单个链接设置的策略优先级比 CSP 和要高 解决百度统计无法获取 https 页的 referrer 说到这里, 如果我们想让百度统计能够统计到来源 HTTPS 的页面, 我们有两种方式 :(1) 将自己的网站也升级到 HTTPS( 参考 在 Nginx 中使用 Let's Encrypt 免费证书配置 HTTPS );(2) 让对方网站设置相关的 Referrer Policies 本博客文章除特别声明, 全部都是原创! 转载本文请加上 : 转载自过往记忆 (https://www.iteblog.com/) 本文链接 : () 5 / 5