我有一个名为 eHelpDhtm.js当我在扫描整个项目时,通过 对号我可以看到与DOM XSS攻击有关的漏洞。
我得到了以下DOM XSS攻击的问题。
User Guide/Help/eHelpDhtm.js的PopupMenu_InvokeReady方法获取了用户输入的 位置 元素。这个元素的值就会在没有经过正确的过滤或验证的情况下流经客户端代码,并最终在用户指南/\Help/eHlpDhtm.js的PopupMenu_InvokeReady中显示给用户,这可能会启用DOM XSS攻击。
下面的方法中的错误行是
gbWndPopupLinks.document.write("<base href=\"" + location +"\">");
下面是代码。
function PopupMenu_InvokeReady()
{
if (gbWndPopupLinks != null) {
gbWndPopupLinks.document.open("text/html");
gbWndPopupLinks.document.write("<html><head>");
if (gbBsNS2) {
gbWndPopupLinks.document.write("<base href=\"" + location +"\">");
} else {
gbWndPopupLinks.document.write("<");
gbWndPopupLinks.document.write("script>");
gbWndPopupLinks.document.write("function gotoUrl(aUrl) {opener.window.location=aUrl; close();}");
gbWndPopupLinks.document.write("<");
gbWndPopupLinks.document.write("/script>");
}
// Close the temporary
if (!gbBsNS3 && gbWndTemp != null) {
gbWndTemp.close();
}else {
gbWndPopupLinks.focus();
}
return true;
}
return false;
}
谁能帮我把它正确地处理一下?
我不知道这对Base attr是否有效,但在控制台中,目标字符串被正确地转义。
function escapeOutput(toOutput){
return toOutput.replace(/\&/g, '&')
.replace(/\</g, '<')
.replace(/\>/g, '>')
.replace(/\"/g, '"')
.replace(/\'/g, ''')
.replace(/\//g, '/');
}
然后在你的代码中使用它。
gbWndPopupLinks.document.write("<base href=\"" +location.replace(/\&/g, '&').replace(/\</g, '<').replace(/\>/g, '>').replace(/\"/g, '"').replace(/\'/g, ''').replace(/\//g, '/') +"\">");
或者
gbWndPopupLinks.document.write("<base href=\"" + escapeOutput(location) +"\">");
你可以在Open Web Application Security Project上阅读有关安全的内容。