Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Make sure to sanitize the content before inserting if you use this approach.

> Warning: This is a security risk if the string to be inserted might contain potentially malicious content. When inserting user-supplied data you should always consider using a sanitizer library, in order to sanitize the content before it is inserted.

https://developer.mozilla.org/en-US/docs/Web/API/Element/inn...



Anything with user input I just use innerText.

Or a simple escapeHTML function within the innerHTML - but I prefer innerText in a separate pass, as using escapeHTML as a pattern gives an opportunity to forget to use it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: