我正在尝试创建一个超级简单的网站,只是为了显示内容,并让另一个页面能够更改页面上的所述内容。 (安全性是 0,所以请随意发布非常粗略的答案。
但是当我访问该站点(托管在 NGINX 背后的数字海洋服务器上)时,我收到以下错误:
Refused to connect to wss://subdomain.domain.online/socket.io/?EIO=4&transport=websocket&sid=SIDHERE because it appears in neither the connect-src directive nor the default-src directive of the Content Security Policy.
我到处寻找并得到了以下政策:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' wss: ws: *; connect-src 'self' ws: wss: *;">
但仍然出现错误,我想知道是否有人会知道修复方法。
干杯,山姆。
答案 0 :(得分:0)
看起来您有 publish 2 CSPs - 第一个通过 <meta http-equiv='Content-Security-Policy'>
标记,第二个通过 CSP HTTP 标头。在这种情况下,适用最严格的政策。
第二个 CSP 由 Helmet 中间件在服务器上发布,Helmet 版本 4 使用默认规则开启了 CSP。
如果您想使用标签,请在 helmet.contentSecurityPolicy(options)
中禁用 CSP:
app.use(
helmet({
contentSecurityPolicy: false,
})
);
或 configure 头盔中的 CSP 标头,不要使用元标记。