We have strictlty disable the dangerous tag script, and its alternate variant SCRIPT. Rest assured, there is going to be no hacking.

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) {
    let tagString = document.querySelector('#input').value;
    tagString = tagString.replace(/<script>|<SCRIPT>/g, '').replace(/<\/script>|<\/SCRIPT>/g, '');
    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#

  • script and SCRIPT maybe blocked, how about ScRipT?
  • Eg: <ScRipT>alert(1)</ScRipT>
Tweet this | Share on LinkedIn |