从websockets解析JSON字符串有风险吗?

时间:2017-01-11 01:48:43

标签: javascript json security websocket xss

我正在编写一个Angular2 Web应用程序,我希望与服务器进行双向通信,因此完美的解决方案是使用websockets。

Mozilla fundation teaches使用(gdb) n- before clone (gdb) n- Detaching after fork from child process 26709. warning: Unexpected waitpid result 000000 when waiting for vfork-done Cannot remove breakpoints because program is no longer writable. It might be running in another process. Further execution is probably impossible. 0x00007fb18a446bf1 in clone () from /lib64/libc.so.6 ptrace: No such process. 来解析表示JSON消息的字符串,用于使用websocket发送和接收数据。这导致了对注射的一些想法。例如,假设以下JSON文档从服务器传输到客户端的计算机:

JSON.stringify(msg)

现在假设paul将他的名字改为{ message{ from: "paul", text:"hello!", date:"01/01/2017" } } 并发送以下文字:

"paul\"

然后客户端收到的以下JSON将是:

,text: alert('xss'),something:"

实际上是以下JSON(刚刚重新排列):

{
  message{
    from: "paul\",
    text:",text: alert('xss'),something:"",
    date:"01/01/2017"
  }
}

这可能会导致问题,具体取决于使用此JSON所做的事情,我想。有没有办法防止这些事情,或者JSON.stringfy技术是否安全,因为在将数据从JSON插入DOM时,text属性将是未定义的,因为alert(' xss')不是字符串(或不返回任何东西)?

另外,如果调用alert()之类的函数没有问题,我们可以将{ message{ from: "paul\",text:", text: alert('xss'), something:"", date:"01/01/2017" } } 变量设置为我们想要的任何内容,这肯定是有风险的。

0 个答案:

没有答案