document.referrerxss攻击如何防御

作者:袖梨 2026-08-28

img_6a90d58c1a6f730.webp

document.referrerxss攻击的防御方法:

可通过查看代码是否有document.write、eval、window之类能造成危害的地方,然后通过回溯变量和函数的调用过程,查看用户是否能控制输入。如果能控制输入,就看看是否能复习,能复习就说明存在DOM XSS,需要对输入的数据进行编码。

代码审计时审计的特征点有:

var elements = location.hash;elements.indexOfvar oBtn=document.getElementById("Btn");oBtn.innerHTMLoBtn.outerHTMLdocument.createElementoBtn.setAttributeoBtn.appendChilddocument.writedocument.writelneval("var x = '" + location.hash + "'");setTimeout("alert('xss')", 1000)window.setTimeoutdocument.setTimeoutwindow.setIntervaldocument.execCommand('ForeColor',false,'#BBDDCC'); document.createElementdocument.createElementNSdocument.createEventdocument.createXxx

注:当业务需要必须得将用户输入的数据放入html,那就要尽量使用安全的方法,比如innerText(),testContent()等。

相关文章

精彩推荐