If I have a text area that can display user entered input. How should I encode it to prevent any security issues?
For instance suppose I have this:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<form>
<textarea></textarea><script>alert('Hello');</script></textarea>
</form>
</body>
</html>
How should I encode the contents of the textarea so that it shows the </textarea><script>
as text rather than running it?
I'm using ASP.Net, but I'm really after a general answer for HTML.
This is different to "Rendering HTML inside textarea" as I don't want to render HTML inside the textarea where as with that question they did.