簡體   English   中英

JavaScript文件中反映的XSS跨站點腳本

[英]XSS Cross Site Scripting Reflected in JavaScript file

我的JS文件具有以下代碼

function changeLanguage(newLang) {
    var winLoc = String(this.window.location);
    var pos = winLoc.indexOf("lang=");
    var spacer = '?';
    if(pos >0) {
        var curLang = winLoc.substring(pos+5,pos+7);
        winLoc = winLoc.replace('lang=' + curLang, 'lang='+newLang);

    } else {
        if(winLoc.indexOf("?") > 0) {
            spacer = '&';
        }

        winLoc = winLoc + spacer + 'lang=' + newLang;
    }

    this.window.location = winLoc;  //here is the issue


}

通過HP Fortify Tool掃描代碼時,在突出顯示的行上遇到XSS跨站點腳本問題。

我在這里可以做什么,以便HP Fortify不會將其視為漏洞? 提前致謝

使用location.assign分配位置 在分配腳本之前,它將腳本的來源與所需的URL進行比較。
從上面的鏈接:

如果由於安全沖突而無法進行分配,則拋出SECURITY_ERROR類型的DOMException 如果調用該方法的腳本的來源與Location對象最初描述的頁面的來源不同(通常是在腳本托管在其他域上時),則會發生這種情況。

您也可以使用location.replace防止當前頁面保存在會話歷史記錄中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM