0

I am writing an application where the user can add messages, they are saved in the firebase, and displayed on the page. I am using the following method to protect html injection:

function testHtml(str){
   return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

And I output the text as follows:

$("#save").click(function(){
      let text = $("#text").val(); //user input 
          text = testHtml(text);
      $("#resultDiv").append(text);
});

I want to know if this method is safe? Are there any workarounds? If so, which ones? I use this filtering method when displaying messages. Many thanks for considering my request.

doo_doo_fart_man
  • 394
  • 3
  • 11
Sergei Hronov
  • 29
  • 1
  • 6

0 Answers0