2013-05-02 68 views
0

在這種情況下:我該如何使用這個dom xss?

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

這是否意味着,只有當我們可以在URL改變data('count')可我們使用這個DOM XSS?
<script>codes</script>

+0

您無法使用URL更改數據。它被設置在JS的某處,試圖找到它。 – Andrey 2013-05-02 04:00:16

回答

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 
+0

我知道如何預防,我只是好奇如何在這種情況下創建一個簡單的XSS攻擊 – Lanston 2013-05-02 04:51:14

+0

我不知道你在找什麼,你在哪裏閱讀或看到[.data()]( http://api.jquery.com/data/)與URL有關? – potatosalad 2013-05-02 05:01:43