使用io.sockets.emit的套接字io

我是新来的Socket io的世界,并想知道如果他们是这样的安全问题:

我也使用Coffeescript。

服务器。

io.sockets.emit('UserInfo', {player1: AllData1, player2: AllData2}) 

AllData1基本上是player1的敏感信息,AllData2是player2的敏感信息。

客户。

  myName = 'snugglePuff' socket.on('UserInfo', (data) -> if data.player1.name = myName alert(data.player1.secret) ) 

所以我的问题是:当服务器广播到每个连接的套接字,将“player2”以某种方式使用他们的浏览器能够看到data.player1.secret?

是的,这是一个巨大的安全问题。

任何广播都可以被每个客户看到。 用户在其版本的页面上编辑脚本并为广播寻找额外的数据将是微不足道的。

如果您必须发送敏感信息,请确保只发送给其所有者。 或者,不要发送任何敏感的东西,并考虑保持服务器端所有敏感内容的方式(例如,使用安全随机生成的ID来识别每个用户的会话)。

我们有很多方式发送给客户 ,

所以在你的代码中,player2可以看到player1.secret。

 // sending to sender-client only socket.emit('message', "this is a test"); // sending to all clients, include sender io.emit('message', "this is a test"); // sending to all clients except sender socket.broadcast.emit('message', "this is a test"); // sending to all clients in 'game' room(channel) except sender socket.broadcast.to('game').emit('message', 'nice game'); // sending to all clients in 'game' room(channel), include sender io.in('game').emit('message', 'cool game'); // sending to sender client, only if they are in 'game' room(channel) socket.to('game').emit('message', 'enjoy the game'); // sending to all clients in namespace 'myNamespace', include sender io.of('myNamespace').emit('message', 'gg'); // sending to individual socketid socket.broadcast.to(socketid).emit('message', 'for your eyes only');