Search code examples
javascriptnode.jshtml

Prevent user from injecting javascript/markup into element


I'm attempting to write a chat server and I've come across the issue that if someone puts markup in their messages e.g. <strong>blah</strong> then the message will send with bold text. Someone could take it further by putting scripts in their message. I'm not sure how I can avoid this.


Solution

  • You need to filter your input to take out unwanted tags. There really isn"t much else to it.