问题描述
我将CSP设置为允许连接到Google字体服务,如下所示。第一次加载时,一切工作正常(我怀疑SW是否会缓存任何东西),但是当我刷新页面时,尽管看到connect-src
明确添加了Google字体网址,但仍然看到错误。
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/**"
]
}
}
错误:
解决方法
好像您将CSP添加到错误的*.exe
,而不是角度配置中添加了CSP。
在您的CSP中显示index.html
,但根据控制台警告,default-src 'self' https: fonts.googleapis.com;...connect-src 'self' https: fonts.googleapis.com;
发生了违规,并且由于缺少 connect-src 指令而被用作备用。