This is the most vulnerable app in the world, it will render any input as-such on the screen. Enter the XSS payload and hit ENTER!

HTML
CSS
JavaScript
<center>
<input type="text" id="input"/>
<div id="screen"></div>
</center>

document.querySelector('#input').addEventListener('keyup', function(e) {
  if (e.keyCode === 13) {
    const tagString = document.querySelector('#input').value;
    const range = document.createRange();
    range.selectNode(document.getElementsByClassName('applet').item(0));
    const documentFragment = range.createContextualFragment(tagString);
    document.querySelector('#screen').appendChild(documentFragment);
  }
});
#input {
  font-size: 16px;
  height: 26px;
  width: 100%;
  margin-bottom: 10px;
  padding: 20px;
}
.applet-html {
  padding: 20px;
}
.applet {
  margin-bottom: 20px;
}

Takeaways and notes#

  • Never trust user input
  • If you render user input as-such, you have a full-blown XSS vulnerability
  • Eg: <script>alert(1)</script>
Tweet this | Share on LinkedIn |