CSP,在base64中连接src和excel



在Angular中,我创建了一个excel文件供下载:

urltoFile(url: string) {
return fetch(url)
.then(function(res) {
return res.arrayBuffer();
})
.then(function(buf) {
return new File([buf], 'excelfile.xlsx', {
type: 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
});
});
}

但是在我的web.config中的CSP头中,我有connect-src *;,并且在服务器上得到了这个错误:

拒绝连接到"data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,(base64code(',因为它违反了以下内容安全策略指令:;connect-src";。请注意,">"仅匹配具有网络方案("http"、"https"、"ws"、"wss"(的URL,或其方案与self的方案匹配的URL。必须显式添加方案"data:"。

问题:这个"connect-src"规则应该如何避免这个错误?

错误消息几乎说明了一切:*匹配http、https、ws、wss,但不匹配data:。为了允许这种情况,您的指令应该是";connect-src*数据:&";。这几乎允许任何事情,并且您应该尝试通过不允许通配符来限制它。

最新更新