模擬被攻擊的時候
在輸入框裏寫
<script>alert('hello,我要攻擊你了!');</script>
在datagrid-scrollview.js中添加以下代碼
//防止標籤注入,將標籤進行轉義
$.extend($.fn.datagrid.defaults, {
onLoadSuccess: function () {
$(this).datagrid("clearSelections");
$(".datagrid-header-check :checkbox").attr("checked", false);
//$(this).data("isReload") &&
if ($(this).datagrid("getRows").length == 0) {
var msg = $("<div style='display:none;margin-top:20px;padding:10px;border:1px solid #AAAAA;background-color:yellow'>搜索無結果!</div>");
msg.insertAfter($(this));
msg.show(200);
setTimeout(function () {
msg.hide(200);
}, 3000);
}
//$(this).data("isReload", true);
},
onUnselect: function (rowIndex, rowData) {
$(".datagrid-header-check :checkbox").attr("checked", false);
},
onSelect: function () {
var tThis = $(this);
if (tThis.datagrid("getRows").length == tThis.datagrid("getSelections").length) {
$(".datagrid-header-check :checkbox").attr("checked", true);
}
return true;
},
loadFilter: function (data) {
//過濾放行部分代碼
if(typeof(data.rows[0])!="undefined"){ //判斷第一行數據是否包含
if((data.rows[0]).hasOwnProperty("worksheetTypeColumn_custom")){
return data;
}
}
for (var i = 0; i < data.rows.length; i++) {
for (var att in data.rows[i]) {
if (typeof (data.rows[i][att]) == "string") {
data.rows[i][att] = data.rows[i][att].replace(/</g, "<").replace(/>/g, ">");
}
}
}
return data;
}
});
被放行的代碼
攻擊失效被轉成普通文本,沒有彈窗了