I have looked everywhere, but cannot find a simple library or tool for this.
I would like to sanitise comments on my website.
Currently, I can inject HTML, CSS and pretty much whatever I want through comments.
<div id="commentsSection">
<div class="submitCommentForm">
<textarea id="commentsInput" required minlength="10" maxlength="150">
</textarea>
<div id="submitComment">SUBMIT</div>
</div>
<div id="commentsBox"></div>
</div>
What is the best available method ?
Because JavaScript can be disabled, sanitation is not an operation for the frontend; this task should be performed on the backend. Best practice says...
You are encouraged to validate data input on the frontend, notifying the user that certain characters are not permitted when trying to submit invalid data. In the event that JavaScript then gets disabled, your backend will still know what to with the malformed data.