【问题标题】:Socket io using io.sockets.emit使用 io.sockets.emit 的套接字 io
【发布时间】:2018-04-01 11:38:00
【问题描述】:

我是 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 吗?

【问题讨论】:

    标签: ios node.js sockets coffeescript


    【解决方案1】:

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

    每个客户都可以看到您广播的任何内容。对于用户来说,在他们的页面版本上编辑脚本并从广播中抓取诸如此类的额外数据将是微不足道的。

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

    【讨论】:

    • 嗯,我认为一旦客户端 js 文件加载,用户将无法使用它做太多事情。他们必须刷新页面,这只会给他们相同的“myName = snugglePuff”变量,不是吗?浏览器上的 player2 如何访问或查看“data.player1.secret”?什么时候只有当它匹配'snugglePuff'时才会发生警报,​​player1的名字?我很难理解这个......
    • 在浏览器中,如果您检查页面,您可以添加脚本。用户可以很容易地摆脱 if 语句或修改它以适合他们,然后可以等待广播。 Web 安全的一个好的经验法则是假设客户端可以绕过客户端安全检查。
    • 即使在外部js文件中?
    • 是的,即使它是外部的。尝试检查您的页面(打开开发人员工具)并查看“源”选项卡,它将显示页面使用的所有外部脚本的列表。你会发现你可以在脚本中添加东西。
    • 实际上,即使不向脚本添加任何内容,用户也可以设置一个断点,以便在收到广播时触发,然后在空闲时查看数据(例如 Chrome 具有此功能) .关键是,数据被截获的方式有很多,所以一开始就不要广播它。
    【解决方案2】:

    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');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 2019-02-20
      • 2016-07-30
      相关资源
      最近更新 更多