【发布时间】:2019-05-10 18:15:12
【问题描述】:
function viewAcc() {
var errorMsg = "";
var result = true;
$(".errorView").hide();
var accNum = document.getElementById('custAccNum').value;
var accType = document.getElementById('custAccType').value;
$("#overlayPopup").show();
$.ajax({
url : '<attribute:resourceURL/>',
data : {
"custNo" : accNum ,
"custType" : accType
},
success : function(data) {
if (data == 'CUS_ACC') {
window.location = "/cust/account/c";
} else {
$("#overlayPopup").hide();
//display warning
$(".errorView").show();
$(".errorView").html(data); // <--- XSS line
e.preventDefault();
}
},
cache : false,
dataType : 'text',
error : function(error, textStatus, errorThrown) {
alert('error in ajax call: ' + textStatus);
console.log('error in ajax call: ' + textStatus);
window.location = "/cust/account/c/lookup";
},
timeout : ajaxTimeOutMilliSeconds
});
}
所以 veracode 指出我在$(".errorView").html(data); 上有问题
我该如何解决?如果我只是将它变成文本,它会像 html 一样显示在客户端上吗?
【问题讨论】:
-
找到一种不需要 .html() 的方法。这可以通过让服务器返回文本,然后客户端将该文本包装在 html 中来完成。
-
你的意思是把
data变成文字?但是数据不是已经是文本了吗? -
不知道,你告诉我。它可以是文本、xml、json,很多东西都可以用字符串来表示。如果它只是没有 html、没有 html 实体等的文本,你可以换成没有缺点的 .text。
-
` $(".errorView").text(data);` 你指的是这个吗?
标签: javascript ajax xss