我的Struts 2.x的Web應用程序。在這個應用程序中,我正在使用XMLHttpRequest
來刷新帶有表格的div。我有一個單獨的JSP頁面來呈現HTML表格。我在XMLHttpRequest
中獲得JSP頁面響應並更新對div的響應。 Veracode在innerHTML
代碼行顯示XSS問題。我如何在這裏清理HTML內容?Veracode的報告XSS問題XMLHttpResponse的Javascript
function ajaxFileUploadRefresh(){
var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("StatusDiv").innerHTML=xmlhttp.responseText; // Refreshing the Div with response. This is where Veracode shows error.
}
}
xmlhttp.open("POST","StrutsAction_methodName",true); // This action will be redirected to jsp
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(postString);
}
「我怎麼能在這裏消毒HTML內容?」 - 爲什麼需要消毒? 「StrutsAction_methodName」的URL不可信嗎?它似乎是同一個網站的一部分! – Quentin
謝謝@Quentin。可能我不應該在這裏使用淨化。但是當響應添加到div時,veracode工具向我顯示了XSS問題。 – ramanareddy438
檢測安全漏洞的工具往往是愚蠢的。他們發現潛在的問題。你絕對必須分析他們的報告,看看是否存在實際問題,不要盲目信任他們。 – Quentin