[英]CSP, connect-src and excel in base64
在 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 ”。 请注意,' ' 仅匹配具有.network 方案('http'、'https'、'ws'、'wss')的 URL,或方案与self
的方案相匹配的 URL。 必须显式添加方案“数据:”。
问题:这个“connect-src”规则应该如何避免这个错误?
错误消息几乎说明了一切:* 匹配 http、https、ws、wss,但不匹配数据:。 为此,您的指令应该是“connect-src * data:;”。 这几乎允许任何事情,您应该尝试通过不允许通配符来限制它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.