From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/http/headers/referrer-policy/index.html | 259 +++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 files/zh-cn/web/http/headers/referrer-policy/index.html (limited to 'files/zh-cn/web/http/headers/referrer-policy') diff --git a/files/zh-cn/web/http/headers/referrer-policy/index.html b/files/zh-cn/web/http/headers/referrer-policy/index.html new file mode 100644 index 0000000000..cf90261cd7 --- /dev/null +++ b/files/zh-cn/web/http/headers/referrer-policy/index.html @@ -0,0 +1,259 @@ +--- +title: Referrer-Policy +slug: Web/HTTP/Headers/Referrer-Policy +tags: + - HTTP + - 响应 + - 请求头 + - 请求首部 + - 隐私 + - 首部 +translation_of: Web/HTTP/Headers/Referrer-Policy +--- +
Referrer-Policy 首部用来监管哪些访问来源信息——会在 {{HTTPHeader("Referer")}}  中发送——应该被包含在生成的请求当中。
+ + + + + + + + + + + + +
Header type{{Glossary("Response header")}}
{{Glossary("Forbidden header name")}}no
+ +

语法

+ +

注意 {{HTTPHeader("Referer")}} 实际上是单词 "referrer" 的错误拼写。Referrer-Policy 这个首部并没有延续这个错误拼写。

+ +
Referrer-Policy: no-referrer
+Referrer-Policy: no-referrer-when-downgrade
+Referrer-Policy: origin
+Referrer-Policy: origin-when-cross-origin
+Referrer-Policy: same-origin
+Referrer-Policy: strict-origin
+Referrer-Policy: strict-origin-when-cross-origin
+Referrer-Policy: unsafe-url
+
+ +

指令

+ +
+
no-referrer
+
整个 {{HTTPHeader("Referer")}}  首部会被移除。访问来源信息不随着请求一起发送。
+
no-referrer-when-downgrade (默认值)
+
在没有指定任何策略的情况下用户代理的默认行为。在同等安全级别的情况下,引用页面的地址会被发送(HTTPS->HTTPS),但是在降级的情况下不会被发送 (HTTPS->HTTP)。
+
origin
+
在任何情况下,仅发送文件的源作为引用地址。例如  https://example.com/page.html 会将 https://example.com/ 作为引用地址。
+
origin-when-cross-origin
+
对于同源的请求,会发送完整的URL作为引用地址,但是对于非同源请求仅发送文件的源。
+
same-origin
+
对于同源的请求会发送引用地址,但是对于非同源请求则不发送引用地址信息。
+
strict-origin
+
在同等安全级别的情况下,发送文件的源作为引用地址(HTTPS->HTTPS),但是在降级的情况下不会发送 (HTTPS->HTTP)。
+
strict-origin-when-cross-origin
+
对于同源的请求,会发送完整的URL作为引用地址;在同等安全级别的情况下,发送文件的源作为引用地址(HTTPS->HTTPS);在降级的情况下不发送此首部 (HTTPS->HTTP)。
+
unsafe-url
+
无论是同源请求还是非同源请求,都发送完整的 URL(移除参数信息之后)作为引用地址。 +
这项设置会将受 TLS 安全协议保护的资源的源和路径信息泄露给非安全的源服务器。进行此项设置的时候要慎重考虑。
+
+
+ +

集成到 HTML

+ +

你也可以在 HTML 内设置 referrer 策略。例如,你可以用一个 name 为 referrer 的 {{HTMLElement("meta")}} 元素为整个文档设置 referrer 策略。

+ +
<meta name="referrer" content="origin">
+ +

或者用 {{HTMLElement("a")}}、{{HTMLElement("area")}}、{{HTMLElement("img")}}、{{HTMLElement("iframe")}}、{{HTMLElement("script")}} 或者 {{HTMLElement("link")}} 元素上的 referrerpolicy 属性为其设置独立的请求策略。

+ +
<a href="http://example.com" referrerpolicy="origin">
+ +

另外也可以在 {{HTMLElement("a")}}、{{HTMLElement("area")}} 或者 {{HTMLElement("link")}} 元素上将 rel 属性设置为 noreferrer

+ +
<a href="http://example.com" rel="noreferrer">
+ +

集成到 CSS

+ +

CSS 可以从样式表获取引用的资源,这些资源也可以遵从 referrer 策略:

+ + + +

示例

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PolicyDocumentNavigation toReferrer
no-referrerhttps://example.com/page.htmlany domain or pathno referrer
no-referrer-when-downgradehttps://example.com/page.htmlhttps://example.com/otherpage.htmlhttps://example.com/page.html
no-referrer-when-downgradehttps://example.com/page.htmlhttps://mozilla.orghttps://example.com/page.html
no-referrer-when-downgradehttps://example.com/page.htmlhttp://example.orgno referrer
originhttps://example.com/page.htmlany domain or pathhttps://example.com/
origin-when-cross-originhttps://example.com/page.htmlhttps://example.com/otherpage.htmlhttps://example.com/page.html
origin-when-cross-originhttps://example.com/page.htmlhttps://mozilla.orghttps://example.com/
origin-when-cross-originhttps://example.com/page.htmlhttp://example.com/page.htmlhttps://example.com/
same-originhttps://example.com/page.htmlhttps://example.com/otherpage.htmlhttps://example.com/page.html
same-originhttps://example.com/page.htmlhttps://mozilla.orgno referrer
strict-originhttps://example.com/page.htmlhttps://mozilla.orghttps://example.com/
strict-originhttps://example.com/page.htmlhttp://example.orgno referrer
strict-originhttp://example.com/page.htmlany domain or pathhttp://example.com/
strict-origin-when-cross-originhttps://example.com/page.htmlhttps://example.com/otherpage.htmlhttps://example.com/page.html
strict-origin-when-cross-originhttps://example.com/page.htmlhttps://mozilla.orghttps://example.com/
strict-origin-when-cross-originhttps://example.com/page.htmlhttp://example.orgno referrer
unsafe-urlhttps://example.com/page.htmlany domain or pathhttps://example.com/page.html
+ +

指定后备策略

+ +

如果你要为那些策略未获广泛的浏览器支持的情况指定一种后备策略,使用逗号分隔的列表,并将希望使用的策略放在最后:

+ +
Referrer-Policy: no-referrer, strict-origin-when-cross-origin
+ +

在上面的场景中,no-referrer 仅在 strict-origin-when-cross-origin 不被浏览器支持的情况下被使用。

+ +

规范

+ + + + + + + + + + + + +
规范状态
Referrer Policy 草稿
+ +

浏览器兼容性

+ + + +

{{Compat("http.headers.Referrer-Policy")}}

+ +

注意: 从版本 53 起,Gecko 在 about:config 中提供了一项偏好设置,使得用户可以自行设定默认的 Referrer-Policy 值 —— network.http.referer.userControlPolicy 。可选的值包括:

+ + + +

相关内容

+ + -- cgit v1.2.3-54-g00ecf