首页 > 解决方案 > 从 localhost:xxxx 加载时的内容安全策略 ( style-src )

问题描述

我在控制台中的错误如下:

拒绝加载样式表 'data:text/css,@import%20url%28%27http%3A//localhost%3A8080/scorm/company1/scorm12/style/assessment.css%27%29%3B' 因为它违反了遵循内容安全策略指令:“style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.googleapis.com ”。

我在 http-header 中的 Content-Security-Policy 如下:

'Content-Security-Policy' "default-src 'self' https://fonts.googleapis.com https://fonts.gstatic.com http://www.google-analytics.com 'unsafe-inline';  **style-src * 'unsafe-inline'** ; 

问题是我用过style-src,但为什么会发生错误我不知道。请帮助我并解释错误的详细信息。

最重要的是我现在在我的商业项目中使用这个策略。

所以我想快点。

标签: javascripthtmlcssnginxlocalhost

解决方案


为什么要在 中使用双“通配符”(**)**style-src * 'unsafe-inline'**

它应该是"default-src 'self' https://fonts.googleapis.com https://fonts.gstatic.com http://www.google-analytics.com 'unsafe-inline'; style-src * 'unsafe-inline'"


推荐阅读