簡體   English   中英

CSP、connect-src和base64中的excel

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM