获取输入值的DOM xss攻击

问题描述 投票:0回答:1

我有一个名为 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;
}

谁能帮我把它正确地处理一下?

javascript c# html-encode checkmark
1个回答
0
投票

我不知道这对Base attr是否有效,但在控制台中,目标字符串被正确地转义。

function escapeOutput(toOutput){
    return toOutput.replace(/\&/g, '&amp;')
        .replace(/\</g, '&lt;')
        .replace(/\>/g, '&gt;')
        .replace(/\"/g, '&quot;')
        .replace(/\'/g, '&#x27')
        .replace(/\//g, '&#x2F');
}

然后在你的代码中使用它。

gbWndPopupLinks.document.write("<base href=\"" +location.replace(/\&/g, '&amp;').replace(/\</g, '&lt;').replace(/\>/g, '&gt;').replace(/\"/g, '&quot;').replace(/\'/g, '&#x27').replace(/\//g, '&#x2F') +"\">");

或者

gbWndPopupLinks.document.write("<base href=\"" + escapeOutput(location) +"\">");

实例

你可以在Open Web Application Security Project上阅读有关安全的内容。

OWASP

OWASPxss

© www.soinside.com 2019 - 2024. All rights reserved.