Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

详解 referrer #85

Open
vincentzyc opened this issue Dec 21, 2021 · 0 comments
Open

详解 referrer #85

vincentzyc opened this issue Dec 21, 2021 · 0 comments

Comments

@vincentzyc
Copy link
Owner

在 HTML 内设置 referrer 策略。例如,你可以用一个 name 为 referrer 的 元素为整个文档设置 referrer 策略。

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

或者用 、、、<iframe>、<script> 或者 元素上的 referrerpolicy 属性为其设置独立的请求策略。

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

另外也可以在 、 或者 元素上将 rel 属性设置为 noreferrer。

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

的 content 属性的值

解释
no-referrer 不发送 HTTP Referer 请求头。
origin 只发送当前文档的 origin。
no-referrer-when-downgrade 如果请求目标与当前页面一样安全或者更加安全(HTTP(S)→HTTPS),则发送完整 URL;如果请求目标更加不安全(HTTPS→HTTP),则不发送 referrer。这是默认行为。
origin-when-cross-origin 对同源请求发送完整 URL(不含 URL 参数),其他情况下,只发送 origin。
same-origin 对同源请求发送完整 URL(不含 URL 参数),其他情况下,请求不包含 referrer 请求头。
strict-origin 如果请求目标与当前页面一样安全或者更加安全(HTTP(S)→HTTPS),则发送 origin;如果请求目标更加不安全(HTTPS→HTTP),则不发送 referrer。
strict-origin-when-cross-origin 对同源请求发送完整 URL(不含 URL 参数);其他情况下,如果请求目标与当前页面一样安全或者更加安全(HTTP(S)→HTTPS),则发送 origin;如果请求目标更加不安全(HTTPS→HTTP),则不发送 referrer。
unsafe-URL 对同源请求和跨源请求发送完整 URL(不含 URL 参数)。

备注:
动态插入 (使用 document.write() 方法或者 appendChild() 等方法)会使 referrer 行为变得不可预测。
如果定义了互相冲突的策略,则会转而使用 no-referrer 策略。

参考文档

MDN Web Docs Referrer-Policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant