Preventing HTML and Script injections in Javascript

后端 未结 7 1792
粉色の甜心
粉色の甜心 2020-12-04 13:12

Assume I have a page with an input box. The user types something into the input box and hits a button. The button triggers a function that picks up the value typed into the

相关标签:
7条回答
  • 2020-12-04 13:54
    myDiv.textContent = arbitraryHtmlString 
    

    as @Dan pointed out, do not use innerHTML, even in nodes you don't append to the document because deffered callbacks and scripts are always executed. You can check this https://gomakethings.com/preventing-cross-site-scripting-attacks-when-using-innerhtml-in-vanilla-javascript/ for more info.

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