Is createTextNode completely safe from HTML injection & XSS?

后端 未结 1 1909
野趣味
野趣味 2021-01-17 10:31

I\'m working on a single page webapp. I\'m doing the rendering by directly creating DOM nodes. In particular, all user-supplied data is added to the page by creating text no

相关标签:
1条回答
  • 2021-01-17 10:51

    It creates a plain text node, so yes, as far as it goes.

    It is possible to create an XSS problem by using an unsafe method to get the data from whatever channel it is being input into to createTextNode though.

    e.g. The following would be unsafe:

    document.createTextNode('<?php echo $_GET['xss']; ?>');
    

    … but the danger is from the PHP echo, not the JavaScript createTextNode.

    0 讨论(0)
提交回复
热议问题