gpt4 book ai didi

javascript - 使用 Service Worker 阻止不安全的 http 请求

转载 作者:行者123 更新时间:2023-11-30 11:54:04 25 4
gpt4 key购买 nike

我正在将网站迁移到 https,但我们的广告转换网络经常通过 http 发送不安全的广告,从而导致出现“混合内容”警告。用 service worker 阻止/ stub 所有 http 请求是个好主意吗?

最佳答案

您可以使用 CSP 来阻止所有非 https 请求:

内容安全策略:阻止所有混合内容

它将http请求重写为https。如果您只想阻止它们,类似的方法应该有效:

Content-Security-Policy:default-src 'self' data:'unsafe-inline' 'unsafe-eval' https:;

更多详情:https://scotthelme.co.uk/migrating-from-http-to-https-ease-the-pain-with-csp-and-hsts/

https://report-uri.io/home/generate(我认为这比使用 Service Worker 更好...)

警告:如果滥用,CSP 可以阻止合法请求和/或内联脚本/css/插件...

关于javascript - 使用 Service Worker 阻止不安全的 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38585890/

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