![](/img/trans.png)
[英]Content Security Policy: The page's settings blocked the loading of a resource at self?
[英]Socket.IO blocked by Content Security Policy
我正在尝试创建一个超级简单的网站,只是为了显示内容并让另一个页面能够更改页面上的所述内容。 (安全性是 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: *;">
但仍然得到错误,我想知道是否有人会知道修复。
干杯,山姆。
看起来您已经发布了 2 个 CSP - 一个通过<meta http-equiv='Content-Security-Policy'>
标签,第二个通过 CSP HTTP header。 在这种情况下,最严格的政策适用。
第二个 CSP 由 Helmet 中间件在服务器上发布,Helmet 版本 4 使用默认规则启用了 CSP。
如果您希望使用标签,请在helmet.contentSecurityPolicy(options)
中禁用 CSP:
app.use(
helmet({
contentSecurityPolicy: false,
})
);
或在 Helmet 中配置CSP header 并且不要使用元标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.