【问题标题】:Blocking non-secure http request with service worker使用服务人员阻止不安全的 http 请求
【发布时间】:2016-07-26 09:22:27
【问题描述】:

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

【问题讨论】:

    标签: javascript security https service-worker


    【解决方案1】:

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

    Content-Security-Policy: block-all-mixed-content

    它将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 (我认为这比使用服务人员更好......)

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

    【讨论】:

    • 非常感谢,我不知道这个标题,正是我要找的!它还拥有比 service worker 更好的浏览器支持,完美:)
    • @RomainDurand 警告:如果滥用它可能会阻止其他请求或内联脚本!
    猜你喜欢
    • 2017-09-17
    • 2017-08-07
    • 2021-02-10
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多