Skip to content

Conversation

@alromh87
Copy link

There was a XSS vulnerabilty because of using innerHTML from user input making code injection available to malitious user.

I fixed by sanitizing user, message, image and by creating DOM elements instead

Message is added as plain text using .textContent, this way no text is lost in the chat.
Image is added seting src of img element
Image link is cleaned for javascript execution

Vulnerability can be tested by:

  1. Start the server
  2. Go on http://localhost:3000
  3. Create clientPoc.js with following contet:
const
    io = require("socket.io-client"),
    ioClient = io.connect("http://localhost:3000/");

ioClient.on("system", (usr,_2,_3) => console.info('system: ', usr));
ioClient.on("newMsg", (usr,msg) => console.info(usr, msg));

ioClient.on('connect', () => {
   console.log('Conectado')
   ioClient.emit('login', 'testUser"><img/src="x"/onerror="alert(\'Login: Hello from console\')">')
   ioClient.emit('postMsg', 'testMesage"><img/src="x"/onerror="alert(\'Msg: Hello from console\')">')
   ioClient.emit('postMsg', '<script>alert("Msg script")</script>')
   ioClient.emit('postMsg', 'testMesage"><img/src="x"/onerror="alert(\'Image: Hello from console\')">[emoji:5] yeah!!')
   ioClient.emit('img', 'data:image/png;base64testMesage"><img/src="x"/onerror="alert(\'Msg: Hello from console\')">[emoji:5] yeah!!')
   ioClient.emit('img', 'javascript:alert(\'Img link: Hello again\')')
   ioClient.emit('img', 'javascript:jjavascript:ajavascript:vjavascript:ajavascript:sjavascript:cjavascript:rjavascript:ijavascript:pjavascript:t://test%0Aalert(1)')
});
  1. execute clientPoc.js
node clientPoc.js
  1. Multiple messages are show triggered by XSS
  • Username XSS
    Captura de pantalla de 2020-09-05 01-07-33

  • Mesage XSS
    Captura de pantalla de 2020-09-05 01-07-43

  • Image XSS
    Captura de pantalla de 2020-09-05 01-09-38

  1. click on image link

  2. message is show in new page

  • Image link XSS

Captura de pantalla de 2020-09-05 01-06-00

After fix No code is executed for remote user, all cases are handled

Captura de pantalla de 2020-09-05 01-03-56

After fix functionality is unafected, and any text can be sent without being lost

Captura de pantalla de 2020-09-04 23-23-16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant