Currently i'm using this method with jQuery solution, to clean string from possible XSS attacks.
sanitize:function(str) {
// return htmlentities(str,'ENT_QUOTES');
return $('<div></div>').text(str).html().replace(/"/gi,'"').replace(/'/gi,''');
}
But i have a feeling it's not safe enough. Do i miss something?
I have tried htmlentities from phpjs project here: http://phpjs.org/functions/htmlentities:425/
But it's kinda bugged and returns some additional special symbols. Maybe it's an old version?
For example:
htmlentities('test"','ENT_QUOTES');
Produces:
test&quot;
But should be:
test"
How are you handling this via javascript?