Secure Node.js chat (avoid XSS)

前端 未结 2 669
醉话见心
醉话见心 2021-02-09 19:34

I\'m building a simple little chat with Node.js and socket.io

When a user types his message, it is broadcasted to all other users.

Server sends the message :

2条回答
  •  渐次进展
    2021-02-09 20:34

    Don't use .html() because that's basically eval on steroids - capable of causing the interpretation of a good variety of languages.

    Text is always interpreted as text though:

    $('#messages').append($("
    ", { text: data.message }));

提交回复
热议问题