I am creating a website, and I have a section where the user can provide input via a form. The input is sanitized using this:
str.replace(/[\x26\x0A<>'"]/g,function(r){return"&#"+r.charCodeAt(0)+";"})
After that, the data is placed between <p>
tags. So something like this:
<p id="foo">Random message</p>
Is my replacement function good enough to prevent an XSS attack?
`), but if you used `textContent` the newline is ignored. – GKFX Mar 22 '20 at 20:44