使用Fontawesome Web字体(套件)时CSP警告
根据Fontawesome的V6文档:
使用CSS使用Web字体?您不必担心CSP问题。这些解决方法不需要。
我加载fontawesome之类的类似:
“ https://kit.fontawesome.com/589f449313.js“ crossorigin =“匿名”
=
< script src 代码> content-security-policy:default-src data:'self'https:// https:// bootstrap.com https:// jsdelivr.net https https:// fontawesome.com .com https://fonts.gstatic.com https://code.jquery.com;表格“自我”;升级 - 不确保 - 重新要求
但是,通用的图标没有加载,我在Inspector中收到此错误:
拒绝应用内联样式,因为它违反了以下内容安全策略指令:default-src data:“ default-src data:” 'self'https://'.bootstrap.com https:// jsdelivr.net https https:// fontawesome.com https://fonts.googleapis.com https://fonts.gstatic.com https https https:https:https:https:https: //code.jquery.com”。需要“不安全限制”关键字,即“ SHA256-VBZVW+MEGPQM/MTRC0CUTI1EZA7X/JNIBG8UVXROWNE ='),或者需要nonce('nonce -...')来启用内线执行。还请注意,“ style-src”不是明确设置的,因此“默认src”被用作后备。
我不确定我该怎么办在CSP中特殊的内联风格。
我在这里想念什么?
According to FontAwesome's documentation for V6:
Using Web Fonts with CSS? You don't need to worry about CSP issues. These workarounds aren't needed.
I load FontAwesome like so:
<script src="https://kit.fontawesome.com/589f449313.js" crossorigin="anonymous"></script>
My CSP is:
Content-Security-Policy: default-src data: 'self' https://*.bootstrap.com https://*.jsdelivr.net https://*.fontawesome.com https://fonts.googleapis.com https://fonts.gstatic.com https://code.jquery.com; form-action 'self'; upgrade-insecure-requests
However, the FontAwesome icons are not loading and I receive this error in the inspector:
Refused to apply inline style because it violates the following Content Security Policy directive: "default-src data: 'self' https://*.bootstrap.com https://*.jsdelivr.net https://*.fontawesome.com https://fonts.googleapis.com https://fonts.gstatic.com https://code.jquery.com". Either the 'unsafe-inline' keyword, a hash ('sha256-vbZVW+MEGpqM/MTrc0cuTI1eza7x/JNIBG8uVXROwnE='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'style-src' was not explicitly set, so 'default-src' is used as a fallback.
I am unsure what else I should do, as FontAwesome's documentation states that I should not need to do anything special in the CSP for inline styles.
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以看一下在这里
我没有使用过套件,而是单个文件:
这样,可以更好地使用Chrome Dev Tools,可以更好地查看。我添加了Chrome建议的sha-*值。
我没有添加
不安全inline
我的CSP代码块:
在
style> style-src
中,您必须添加sha256-*
希望它帮助!
You can have a look here
I've not used the kit, but the single files instead:
In that way it was possible to better see with the Chrome Dev Tools, where to handle. I've added one by one the sha-* values suggested by Chrome.
I did not add
unsafe-inline
anywhereMy CSP code-block:
In the
style-src
you have to add yoursha256-*
Hope it helps!
您的问题关注内联风格。可能是在您的HTML页面或脚本中。尝试这样的内容:
您可能需要添加使用的外部URI。
Your problem concern inline style. May be it's in your html page, or from the script. try somthing like this :
you may be need to add the externals uri you use.