I am currently using this method with a jQuery solution to clear a line of possible XSS attacks.
sanitize:function(str) {
return $('<div></div>').text(str).html().replace(/"/gi,'"').replace(/'/gi,''');
}
But I have a feeling that it’s not safe enough. Did I miss something?
I tried htmlentities from phpjs project here:
http://phpjs.org/functions/htmlentities:425/
But it seems to be listening and returns some additional special characters. Maybe this is an old version?
For instance:
htmlentities('test"','ENT_QUOTES');
It produces:
test&quot;
But it should be:
test"
How do you handle this through javascript?
source
share