I am new to HTML. So even if you find this question silly please answer it. It will help me lot.
I got what xss attack is. OWASP says do HTML Escape Before Inserting Untrusted Data into HTML Element Content.
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
That means I should escape characters in following way:
& --> &
< --> <
> --> >
" --> "
' --> '
/ --> /
I searched lot that is there any method in HTML to apply this escaping? but couldn't find any. Please guide how can I do this in efficient way?
Adding code to explain:
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<input type="text" id="userInput"=>give me input</input>
<button onclick="test()">Submit</button>
<p id="demo"></p>
<script>
function test()
{
var userInput = document.getElementById("userInput").value;
document.write(userInput);
}
</script>
</body>
</html>
If in userinput field user insert: alert("xss");
Then pop up will be there.
I wish to avoid this pop up and store value which user has provided in var userInput. Further I am planning to display this value on UI.