【发布时间】:2019-07-12 10:50:29
【问题描述】:
我的index.html 中有以下cordova content-security-policy:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https: http: data: blob: 'unsafe-eval'; style-src 'self' 'unsafe-inline'">
我的config.xml 文件如下所示:
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
我尝试连接一个socket io实例,连接成功,但是控制台总是报如下错误:
拒绝连接到“ws://192.168.178.52:8091/socket.io/?EIO=3&transport=websocket&sid=7wM1iepvGxtcJUhcAAAB”,因为它违反了以下内容安全策略指令:“default-src 'self' https: http:数据:blob:'unsafe-eval'”。请注意,'connect-src' 没有显式设置,因此 'default-src' 用作备用。
之后,我尝试将content-server 192.168.178.52:8091 添加到我的index 文件的元标记中,但没有成功。我还尝试将ws://*/* 和ws://* 添加到我的config.xml(也没有成功)。
客户:
socketIO.exec = io('http://192.168.178.52:8091');
服务器::
const socketIO = require('socket.io');
const server = {};
server.port = 8091;
server.start = function() {
this.init(port);
console.log('server running on port:' + this.port);
};
server.init = function() {
this.io_socket = socketIO(this.port);
this.io_socket.on('connection', function(socket) {
console.log(socket.id); // 7wM1iepvGxtcJUhcAAAB
});
};
一切都按预期工作,客户端控制台中的错误消息除外。感谢您的帮助。
编辑:
如果我将元标记中的'self' 属性替换为*,则根本没有错误消息,所以我认为这些更改不会影响白名单?
【问题讨论】:
标签: javascript node.js cordova socket.io content-security-policy