【问题标题】:Google fonts blocked by Content Security Policy内容安全政策阻止的 Google 字体
【发布时间】: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/…'
  • 您需要使用https URL:https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700%7CRoboto:300,400,500,600,700。 (问题中的错误消息表明您的代码正在调用http URL。)
  • @ishwarchandratiwari 啊谢谢它的工作,如果你愿意,你可以回答,所以我可以选择它。
  • @sideshowbarker 啊谢谢,我还在本地测试,没想到会造成麻烦。谢谢。

标签: content-security-policy google-fonts


【解决方案1】:
猜你喜欢
  • 2016-03-03
  • 2022-10-06
  • 2015-09-05
  • 2021-09-29
  • 1970-01-01
  • 1970-01-01
  • 2019-04-15
  • 1970-01-01
  • 2022-08-19
相关资源
最近更新 更多