gpt4 book ai didi

security - 我可以使用 CSP 将请求限制为 https : AND 'self' ?

转载 作者:可可西里 更新时间:2023-11-01 16:09:33 25 4
gpt4 key购买 nike

我最初在我的 CSP header 中有这个:default-src 'self'; ,它只限制了我的域的来源,但它没有说明方案/协议(protocol)。据我所知,如果页面本身是通过 http 加载的,这将允许通过 http 加载源。我正在使用 HSTS 和 CDN 重定向来尝试将所有流量保持在 https 上,但无论如何我都想解决这个问题。 (事实上​​,我试图让 this header checker 给我所有的绿色勾号。) .我只需要修正一些拼写错误。

无论如何,我尝试将 CSP 指令更改为 'self' ,但似乎添加该方案允许从任何域加载资源,只要它通过 https。即,如果任一规则(https 或“self”)匹配,则请求被允许。我通过在 chrome 开发工具中使用 URL 来测试这一点。

有没有办法表明:

  1. 所有资源都应该通过https加载;和
  2. 资源应该只来自原始域?

类似于 default-src https: 'self'; ,但我不认为这是有效的,是吗?

一种解决方案是对域名进行硬编码,但我想使用 default-src https://'self';如果可能的话。

最佳答案

根据 https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives , 'self' 内容源关键字:

Refers to the origin from which the protected document is being served, including the same URL scheme and port number.

如果您通过 https 提供网页,则自己仅允许对同一域的 https 请求。

CSP2 规范 http://www.w3.org/TR/CSP2/#match-source-expression说同样的话:

If the source expression is a case insensitive match for 'self' (including the quotation marks), then:

Return does match if the origin of url matches the origin of protected resource’s URL.

关于security - 我可以使用 CSP 将请求限制为 https : AND 'self' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34396309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com