【发布时间】:2018-07-01 00:52:32
【问题描述】:
您好,我有一些这样的内容安全政策:
<meta http-equiv="content-security-policy" content="default-src 'self';
script-src 'self' 'nonce-MhqUJrKKq9' https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com/; font-src 'self' https://fonts.gstatic.com/;
object-src 'none'; base-uri 'none';">
我试图允许使用谷歌字体,但它给了我这个错误:
webfont.js:17 拒绝加载样式表“http://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700%7CRoboto:300,400,500,600,700”,因为它违反了以下内容安全策略指令:“style-src 'self' 'unsafe-inline' https://fonts.googleapis.com/”。
那么是什么导致了这个错误呢?我虽然我已经将它排除在我的政策之外。
【问题讨论】:
-
试试不带 https 的 google 字体,'fonts.googleapis.com/…'
-
您需要使用
httpsURL:https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700%7CRoboto:300,400,500,600,700。 (问题中的错误消息表明您的代码正在调用httpURL。) -
@ishwarchandratiwari 啊谢谢它的工作,如果你愿意,你可以回答,所以我可以选择它。
-
@sideshowbarker 啊谢谢,我还在本地测试,没想到会造成麻烦。谢谢。
标签: content-security-policy google-fonts