diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/http/headers/referrer-policy | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/http/headers/referrer-policy')
-rw-r--r-- | files/zh-cn/web/http/headers/referrer-policy/index.html | 259 |
1 files changed, 259 insertions, 0 deletions
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 +--- +<div><strong><code>Referrer-Policy</code></strong> 首部用来监管哪些访问来源信息——会在 {{HTTPHeader("Referer")}} 中发送——应该被包含在生成的请求当中。</div> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">Header type</th> + <td>{{Glossary("Response header")}}</td> + </tr> + <tr> + <th scope="row">{{Glossary("Forbidden header name")}}</th> + <td>no</td> + </tr> + </tbody> +</table> + +<h2 id="语法">语法</h2> + +<p>注意 {{HTTPHeader("Referer")}} 实际上是单词 "referrer" 的错误拼写。<code>Referrer-Policy</code> 这个首部并没有延续这个错误拼写。</p> + +<pre class="syntaxbox">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 +</pre> + +<h2 id="指令">指令</h2> + +<dl> + <dt>no-referrer</dt> + <dd>整个 {{HTTPHeader("Referer")}} 首部会被移除。访问来源信息不随着请求一起发送。</dd> + <dt>no-referrer-when-downgrade (默认值)</dt> + <dd>在没有指定任何策略的情况下用户代理的默认行为。在同等安全级别的情况下,引用页面的地址会被发送(HTTPS->HTTPS),但是在降级的情况下不会被发送 (HTTPS->HTTP)。</dd> + <dt>origin</dt> + <dd>在任何情况下,仅发送文件的源作为引用地址。例如 <code>https://example.com/page.html</code> 会将 <code>https://example.com/ 作为引用地址。</code></dd> + <dt>origin-when-cross-origin</dt> + <dd>对于同源的请求,会发送完整的URL作为引用地址,但是对于非同源请求仅发送文件的源。</dd> + <dt>same-origin</dt> + <dd>对于<a href="/en-US/docs/Web/Security/Same-origin_policy">同源的请求</a>会发送引用地址,但是对于非同源请求则不发送引用地址信息。</dd> + <dt>strict-origin</dt> + <dd>在同等安全级别的情况下,发送文件的源作为引用地址(HTTPS->HTTPS),但是在降级的情况下不会发送 (HTTPS->HTTP)。</dd> + <dt>strict-origin-when-cross-origin</dt> + <dd>对于同源的请求,会发送完整的URL作为引用地址;在同等安全级别的情况下,发送文件的源作为引用地址(HTTPS->HTTPS);在降级的情况下不发送此首部 (HTTPS->HTTP)。</dd> + <dt>unsafe-url</dt> + <dd>无论是同源请求还是非同源请求,都发送完整的 URL(移除参数信息之后)作为引用地址。 + <div class="note">这项设置会将受 TLS 安全协议保护的资源的源和路径信息泄露给非安全的源服务器。进行此项设置的时候要慎重考虑。</div> + </dd> +</dl> + +<h2 id="集成到_HTML">集成到 HTML</h2> + +<p>你也可以在 HTML 内设置 referrer 策略。例如,你可以用一个 name 为 referrer 的 {{HTMLElement("meta")}} 元素为整个文档设置 referrer 策略。</p> + +<pre><meta name="referrer" content="origin"></pre> + +<p>或者用 {{HTMLElement("a")}}、{{HTMLElement("area")}}、{{HTMLElement("img")}}、{{HTMLElement("iframe")}}、{{HTMLElement("script")}} 或者 {{HTMLElement("link")}} 元素上的 <code>referrerpolicy</code> 属性为其设置独立的请求策略。</p> + +<pre><a href="http://example.com" referrerpolicy="origin"></pre> + +<p>另外也可以在 {{HTMLElement("a")}}、{{HTMLElement("area")}} 或者 {{HTMLElement("link")}} 元素上将 <code>rel</code> 属性设置为 <code>noreferrer</code>。</p> + +<pre><a href="http://example.com" rel="noreferrer"></pre> + +<h2 id="集成到_CSS">集成到 CSS</h2> + +<p>CSS 可以从样式表获取引用的资源,这些资源也可以遵从 referrer 策略:</p> + +<ul> + <li>外部 CSS 样式表使用默认策略 (<code>no-referrer-when-downgrade</code>),除非 CSS 样式表的响应消息通过 <code>Referrer-Policy</code> 首部覆盖该策略。</li> + <li>对于 {{HTMLElement("style")}} 元素或 <code><a href="/zh-CN/docs/Web/API/HTMLElement/style">style</a></code> 属性,则遵从文档的 referrer 策略。</li> +</ul> + +<h2 id="示例">示例</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Policy</th> + <th scope="col">Document</th> + <th scope="col">Navigation to</th> + <th scope="col">Referrer</th> + </tr> + </thead> + <tbody> + <tr> + <td><code><strong>no-referrer</strong></code></td> + <td>https://example.com/page.html</td> + <td>any domain or path</td> + <td>no referrer</td> + </tr> + <tr> + <td><strong><code>no-referrer-when-downgrade</code></strong></td> + <td>https://example.com/page.html</td> + <td>https://example.com/otherpage.html</td> + <td>https://example.com/page.html</td> + </tr> + <tr> + <td><strong><code>no-referrer-when-downgrade</code></strong></td> + <td>https://example.com/page.html</td> + <td>https://mozilla.org</td> + <td>https://example.com/page.html</td> + </tr> + <tr> + <td><strong><code>no-referrer-when-downgrade</code></strong></td> + <td>https://example.com/page.html</td> + <td><strong>http</strong>://example.org</td> + <td>no referrer</td> + </tr> + <tr> + <td><strong><code>origin</code></strong></td> + <td>https://example.com/page.html</td> + <td>any domain or path</td> + <td>https://example.com/</td> + </tr> + <tr> + <td><code><strong>origin-when-cross-origin</strong></code></td> + <td>https://example.com/page.html</td> + <td>https://example.com/otherpage.html</td> + <td>https://example.com/page.html</td> + </tr> + <tr> + <td><code><strong>origin-when-cross-origin</strong></code></td> + <td>https://example.com/page.html</td> + <td>https://mozilla.org</td> + <td>https://example.com/</td> + </tr> + <tr> + <td><code><strong>origin-when-cross-origin</strong></code></td> + <td>https://example.com/page.html</td> + <td><strong>http</strong>://example.com/page.html</td> + <td>https://example.com/</td> + </tr> + <tr> + <td><strong><code>same-origin</code></strong></td> + <td>https://example.com/page.html</td> + <td>https://example.com/otherpage.html</td> + <td>https://example.com/page.html</td> + </tr> + <tr> + <td><strong><code>same-origin</code></strong></td> + <td>https://example.com/page.html</td> + <td>https://mozilla.org</td> + <td>no referrer</td> + </tr> + <tr> + <td><strong><code>strict-origin</code></strong></td> + <td>https://example.com/page.html</td> + <td>https://mozilla.org</td> + <td>https://example.com/</td> + </tr> + <tr> + <td><strong><code>strict-origin</code></strong></td> + <td>https://example.com/page.html</td> + <td><strong>http</strong>://example.org</td> + <td>no referrer</td> + </tr> + <tr> + <td><strong><code>strict-origin</code></strong></td> + <td><strong>http</strong>://example.com/page.html</td> + <td>any domain or path</td> + <td>http://example.com/</td> + </tr> + <tr> + <td><strong><code>strict-origin-when-cross-origin</code></strong></td> + <td>https://example.com/page.html</td> + <td>https://example.com/otherpage.html</td> + <td>https://example.com/page.html</td> + </tr> + <tr> + <td><strong><code>strict-origin-when-cross-origin</code></strong></td> + <td>https://example.com/page.html</td> + <td>https://mozilla.org</td> + <td>https://example.com/</td> + </tr> + <tr> + <td><strong><code>strict-origin-when-cross-origin</code></strong></td> + <td>https://example.com/page.html</td> + <td><strong>http</strong>://example.org</td> + <td>no referrer</td> + </tr> + <tr> + <td><strong><code>unsafe-url</code></strong></td> + <td>https://example.com/page.html</td> + <td>any domain or path</td> + <td>https://example.com/page.html</td> + </tr> + </tbody> +</table> + +<h3 id="指定后备策略">指定后备策略</h3> + +<p>如果你要为那些策略未获广泛的浏览器支持的情况指定一种后备策略,使用逗号分隔的列表,并将希望使用的策略放在最后:</p> + +<pre><code>Referrer-Policy: no-referrer, strict-origin-when-cross-origin</code></pre> + +<p>在上面的场景中,<code>no-referrer</code> 仅在 <code>strict-origin-when-cross-origin</code> 不被浏览器支持的情况下被使用。</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + </tr> + <tr> + <td><a href="https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-header">Referrer Policy </a></td> + <td>草稿</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("http.headers.Referrer-Policy")}}</p> + +<p><strong>注意:</strong> 从版本 53 起,Gecko 在 about:config 中提供了一项偏好设置,使得用户可以自行设定默认的 Referrer-Policy 值 —— network.http.referer.userControlPolicy 。可选的值包括:</p> + +<ul> + <li>0 — <code>no-referrer</code></li> + <li>1 — <code>same-origin</code></li> + <li>2 — <code>strict-origin-when-cross-origin</code></li> + <li>3 — <code>no-referrer-when-downgrade</code> (the default)</li> +</ul> + +<h2 id="相关内容">相关内容</h2> + +<ul> + <li>{{interwiki("wikipedia", "HTTP_referer", "HTTP referer on Wikipedia")}}</li> + <li>其他设定页面引用策略的方式: + <ul> + <li>A {{HTMLElement("meta")}} element with a <a href="/en-US/docs/Web/HTML/Element/meta#attr-name">name of <code>referrer</code></a>.</li> + <li>A <code>referrerpolicy</code> attribute on an {{HTMLElement("a")}}, {{HTMLElement("area")}}, {{HTMLElement("img")}}, {{HTMLElement("iframe")}}, or {{HTMLElement("link")}} element.</li> + <li>The <code>noreferrer</code> link relation on an a, area, or link element (<code>rel="noreferrer"</code>).</li> + <li>When using <a href="/en-US/docs/Web/API/Fetch_API">Fetch</a>: {{domxref("Request.referrerPolicy")}}</li> + </ul> + </li> + <li><a href="/en-US/docs/Web/Security/Same-origin_policy">同源策略</a></li> + <li> + <p><a href="https://blog.mozilla.org/security/2015/01/21/meta-referrer/">Tighter Control Over Your Referrers – Mozilla Security Blog</a></p> + </li> +</ul> |