目前,我正在开发 Django1.11 项目,我使用 nginx 和方案“https”部署了我的应用程序。我想提交表单但不想重新提交,所以我使用了 POST/REDIRECT/GET 模式。在 Mozilla 和 chrome 上一切正常,正如预期的那样,即对于 POST/REDIRECT/GET 调用将呈现相应的网页,在重新加载和重新提交相同的表单时将呈现 403 访问被拒绝,如预期的那样。只有当我在 Microsoft EDGE 浏览器中测试相同的 View 时才会出现此问题。在调用 POST/REDITECT/GET 方法时,它直接抛出 403。403 的原因是'REASON_NO_REFERER'。 Microsoft Edge 在使用 POST/REDIRECT/GET 模式时转发空的 HTTP-referer。
我找到了一个补丁:
添加<meta name="referrer" content="origin-when-cross-origin" />
在<head>
HTML 模板,现在它也适用于 Edge。但是,如果我不在标题中添加此元标记,我仍然不知道 Edge 有什么问题。另外,它是否会导致任何安全漏洞?
Django 解释了为什么 referer 检查是必须的。
Suppose a user visits http://example.com/
# An active network attacker (man-in-the-middle, MITM) sends a
# POST form that targets https://example.com/detonate-bomb/ and
# submits it via JavaScript.
#
# The attacker will need to provide a CSRF cookie and token, but
# that's no problem for a MITM and the session-independent
# secret we're using. So the MITM can circumvent the CSRF
# protection. This is true for any HTTP connection, but anyone
# using HTTPS expects better! For this reason, for
# https://example.com/ we need additional protection that treats
# http://example.com/ as completely untrusted. Under HTTPS,
# Barth et al. found that the Referer header is missing for
# same-domain requests in only about 0.2% of cases or less, so we can use strict Referer checking.
那么,在那种情况下,是否意味着必须在 HTML 中添加元数据才能在 HTTP-referer 中提供 xyz-origin?如果是,它是否会导致中间人攻击的任何安全漏洞,因为攻击者可能也有 http-referer?
我的网络概念很差,所以如果我这边有什么遗漏或错误,请纠正我。
最佳答案
meta referrer 标签适用于大多数浏览器,以用户定义的方式传递 referrer 信息。流量保持加密,使用 HTTPS 的所有好处仍然存在,但现在您可以将引荐来源数据传递到所有网站,即使是那些使用 HTTP 的网站。
Origin When Cross-Origin:当目标具有相同的方案、主机和端口(即子域)时,无论是 HTTP 还是 HTTPS,都发送完整的 URL 作为引荐来源网址,同时发送 origin-仅将信息推荐给外部站点。
因此,基于此,我认为您不会遇到任何与安全相关的问题。
引用资料:
(1) The Meta Referrer Tag: An Advancement for SEO and the Internet
(2) SEO for HTTPS Sites: Should You Implement the Meta Referrer Tag?
关于html - 如果请求和响应的 uri 相同,为什么 Microsoft edge 在调用 POST/REDIRECT/GET 方法时发送空的 http-referer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54511611/