2017-10-20 73 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');