gpt4 book ai didi

.htaccess - 内容安全策略 header - 升级不安全请求和报告事件

转载 作者:行者123 更新时间:2023-12-04 23:51:50 24 4
gpt4 key购买 nike

我想要达到的目标:两者都将页面内的所有 HTTP 请求升级到 HTTPS 并报告/记录事件。

服务器同时支持 HTTP 和 HTTPS。

测试 HTML 页面。注意 <img> 中的硬编码 HTTP 协议(protocol)

<html>
<head>
</head>
<body>
<img src="http://example.com/testimage.png" />
</body>
</html>

根据 W3C documentation ,我这样设置我的 .htaccess :
Header set Content-Security-Policy "upgrade-insecure-requests; default-src https:"
Header set Content-Security-Policy-Report-Only "default-src https:; report-uri https://report-uri.io/report/..."

当我调用 https://example.com/testpage.html ,它通过 HTTPS 加载图像但不报告事件。

我错过了什么?

最佳答案

我不确定 upgrade-insecure-requestsblock-all-mixed-content将生成事件,因为它们首先阻止了不良事件的发生。

我的推理可能是错误的,但我知道block-all-mixed-content不会产生违规。

对于 block 所有混合内容,它明确不会发送报告。来自 https://www.w3.org/TR/mixed-content/#strict-opt-in :

This directive has no effect when monitored. This directive’s only effect is to set a policy flag on the protected resource; it will therefore never be violated, and has no reporting requirements.

关于.htaccess - 内容安全策略 header - 升级不安全请求和报告事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35748905/

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