我将CSP设置为允许连接到google字体服务,如下所示。在第一次加载时,一切正常(我怀疑SW缓存任何内容),但是当我刷新页面时,尽管connect-src显式地添加了Google字体url,我还是看到了错误。
CSP添加到index.html中
<meta http-equiv="Content-Security-Policy"
content="
default-src 'self' https: fonts.googleapis.com;
font-src 'self' https: fonts.googleapis.com fonts.gstatic.com data:;
style-src 'self' 'unsafe-inline' https: fonts.googleapis.com fonts.gstatic.com data:;
child-src 'self' fonts.googleapis.com;
connect-src 'self' https: fonts.googleapis.com;
object-src 'none';">ngsw-config:
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
],
"urls": [
"https://fonts.googleapis.com/**",
"https://fonts.gstatic.com/**"
]
}
}错误:

发布于 2020-09-20 16:49:03
看起来您已经将CSP添加到错误的index.html中,而不是从角配置中添加一个。
在您的CSP中,CSP显示为default-src 'self' https: fonts.googleapis.com;...connect-src 'self' https: fonts.googleapis.com;,但据console警告,这种违规发生在default-src 'self';上,并且由于没有connect指令而被用作后盾。
https://stackoverflow.com/questions/63835587
复制相似问题