I am creating a simple little chat with Node.js and socket.io
When a user enters his message, he is broadcast to all other users.
The server sends a message:
io.sockets.emit('fromServerToClient', { "message": message });
The client displays it:
socket.on('fromServerToClient', function (data) { $('#messages').append(data.message + '<br />'); });
But when you send something like <script>alert(1);</script> , it runs in every client browser.
This is a serious security flaw, and I want to avoid it as much as possible. I have seen people avoid the characters &, <, > and " , but I don't think that is enough!
How can I be 100% sure that I do not have an XSS vulnerability in chat?
By the way, I always specify the encoding to avoid UTF-7 attacks.
Thank you for your help.
mimipc
source share