2017-10-20 71 views
1

我是新来的Socket IO的世界,如果他们的与此安全问题在想:我还使用CoffeeScript的插槽IO使用io.sockets.emit

服务器。

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每一个插座?

回答

0

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

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

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

+0

嗯,我以为一旦客户端js文件加载用户将无法用它做很多事情。他们将不得不刷新页面,只是给他们相同的“myName = snugglePuff”变量不是吗? 他的浏览器上的player2如何访问或查看“data.player1.secret”?当警报只会发生,如果它匹配'snugglePuff',player1的名字? 我很难把这个包裹在我的头上...... – user2648117

+0

在浏览器中,如果你检查页面,你可以添加一个脚本。用户可以很容易地摆脱if语句或修改它以适应它们,然后可以等待广播。网络安全的一个好的经验法则是假定客户端可以绕过客户端安全检查。 – Cromulent

+0

即使它在外部的js文件中? – user2648117

0

We have many way to send to clients

因此,在你的代码中,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');