Created
April 19, 2017 02:30
-
-
Save mashingan/2d301b684c9d24444b5516025ef36205 to your computer and use it in GitHub Desktop.
decode html front-end http://jsfiddle.net/k65s3/ http://stackoverflow.com/a/7394787/938089
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input { | |
width: 100%; | |
display: block; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Note: &nbsp; is used to make sure that the value of the input is instead of a space. --> | |
<form id="form"> | |
<input type="text" id="input" placeholder="input" value="Entity:&nbsp; | |
Bad attempt at XSS:<script>alert('new\nline?')</script><br>"> | |
<input type="submit" value="alert(input)"> | |
In the above example, "&nbsp;" should be replaced with a space, and the rest of the text should be displayed as-is. See http://stackoverflow.com/a/7394787/938089. | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function decodeHtml(html) { | |
var txt = document.createElement("textarea"); | |
txt.innerHTML = html; | |
return txt.value; | |
} | |
document.getElementById('form').onsubmit = function(e) { | |
e.preventDefault(); | |
var input = document.getElementById('input').value; | |
var output = decodeHtml(input); | |
alert(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment