0

在这种情况下:

var count = $(count_el).data("count");  
$(target).html("你好"+count);

是不是说只有data('count')在url里能改一下才能用这个dom xss?
之类<script>codes</script>

4

1 回答 1

0

jQuery.data存储元素或对象本身的信息(如果它是元素,它首先从data-*标签中提取数据)。

$el = $("<div data-count='1'></div>")
$el.data('count') // 1
$el.data()        // {"count":1}

但是,如果您担心 XSS 并且以某种方式将恶意 HTML 嵌入到数据标签中,您可以使用.text()而不是.html()

$parent = $("<div></div>");
$child  = $("<div data-count='<script>alert(\"malicious code\");</script>'></div>");
count   = $child.data('count')
$parent.html(count) // this will run the embedded script
$parent.text(count) // this will not
于 2013-05-02T04:07:08.130 回答