(no-inner-html)app / components / sports.ts [717,9]:使用html()函数将字符串写入innerHTML是不安全的:$('。tubing')。html(health.title)
if (health.title == "waterS") {
let that = this;
let recordPlayersWeight = {};
this.futureParrot = [];
this.pastParrot = [];
this.peacockService.getResponse(health.url, 'get', null)
.subscribe(recordPlayersWeight => {
this.gridData = recordPlayersWeight.waterDtos;
that._recordPlayersWeightSource.recordPlayersWeight(this.gridData);
},
err => {
}
);
}
that.window = $("#TigerwatersPopup");
that.window.kendoWindow({
width: "60%",
title: false,
visible: false,
resizable: false,
actions: [],
draggable: false,
modal: true,
open: function() {
$("html, body").css("overflow", "hidden");
that.isVisible = true;
$('.tubing').html(health.title);
当您使用jQuery的.html()
功能时,可能会意外地向页面添加“不安全”元素,例如iframe标记或源标记。如果您添加的html是由恶意用户提交的(例如,作为查询的一部分或以表格形式输入的数据),则表示您为他们提供了一种攻击您的方法。这是一种代码注入攻击形式(请参阅https://en.wikipedia.org/wiki/Code_injection)。
在您的情况下,您似乎只是想将纯文本放入.tubing
元素中,因此这样做更安全
$('.tubing').text( health.title );
它的作用是“转义”任何HTML特殊字符,例如<
或,>
以使它们显示为文本而不是被视为元素。这是安全的,可以防止攻击者注入代码,并且不会触发lint规则。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句