【问题标题】:Angular 4 production builld css blocked by CSP in Chrome Firefox but not IEAngular 4 production build css 在 Chrome Firefox 中被 CSP 阻止,但不是 IE
【发布时间】:2018-01-09 08:47:21
【问题描述】:

我的 Angular 生产版本部署在我的 Java Springboot 的静态资源中。 我测试了它在 3 种不同的浏览器(Chrome、Firefox、IE)中运行,并在 Chrome 和 Firefox 中都收到了被阻止的 css。

我在 Chrome 中检索到的一些消息是:

Refuse to apply inline style.......

在 Firefox 中:

Content Security Policy: The page’s settings blocked the loading of a resource at self (“style-src......

但在 IE 中一切正常

如何解决 Chrome 和 Firefox 中的问题?

【问题讨论】:

    标签: angular google-chrome internet-explorer firefox content-security-policy


    【解决方案1】:

    Internet Explorer 本质上没有内容安全策略:它只支持Sandbox directive。随着 Edge 的推出,可以肯定地说 Internet Explorer 永远不会获得适当的 CSP 支持。所以它“有效”,因为它没有被强制执行。 IE 不应成为 CSP 测试的一部分。

    Chrome 警告信息量很大,请完整阅读;它会准确地告诉你你需要做什么,甚至给出一个你可以使用的 SHA 哈希值,比如:

    style-src 'sha256-076c8f1ca6979ef156b510a121b69b6265011597557ca2971db5ad5a2743545f'
    

    如果您的应用有大量内联代码并且您无法删除它们,'unsafe-inline' 是可能的,但顾名思义,它不安全也不首选。

    【讨论】:

      猜你喜欢
      • 2021-09-14
      • 2015-07-25
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      相关资源
      最近更新 更多