@@ -607,36 +607,40 @@ $(function () {
607
607
assert . expect ( 1 )
608
608
var done = assert . async ( )
609
609
610
- var $toggleBtn = $ ( '<button data-toggle="modal" data-target="<div id="modal-test"><div class="contents"<div<div id="close" data-dismiss="modal"/></div></div>"/>' )
611
- . appendTo ( '#qunit-fixture' )
610
+ try {
611
+ var $toggleBtn = $ ( '<button data-toggle="modal" data-target="<div id="modal-test"><div class="contents"<div<div id="close" data-dismiss="modal"/></div></div>"/>' )
612
+ . appendTo ( '#qunit-fixture' )
612
613
613
- $toggleBtn . trigger ( 'click' )
614
- setTimeout ( function ( ) {
614
+ $toggleBtn . trigger ( 'click' )
615
+ } catch ( e ) {
615
616
assert . strictEqual ( $ ( '#modal-test' ) . length , 0 , 'target has not been parsed and added to the document' )
616
617
done ( )
617
- } , 1 )
618
+ }
618
619
} )
619
620
620
621
QUnit . test ( 'should not execute js from target' , function ( assert ) {
621
622
assert . expect ( 0 )
622
623
var done = assert . async ( )
623
624
624
- // This toggle button contains XSS payload in its data-target
625
- // Note: it uses the onerror handler of an img element to execute the js, because a simple script element does not work here
626
- // a script element works in manual tests though, so here it is likely blocked by the qunit framework
627
- var $toggleBtn = $ ( '<button data-toggle="modal" data-target="<div><image src="missing.png" onerror="$('#qunit-fixture button.control').trigger('click')"></div>"/>' )
628
- . appendTo ( '#qunit-fixture' )
629
- // The XSS payload above does not have a closure over this function and cannot access the assert object directly
630
- // However, it can send a click event to the following control button, which will then fail the assert
631
- $ ( '<button>' )
632
- . addClass ( 'control' )
633
- . on ( 'click' , function ( ) {
634
- assert . notOk ( true , 'XSS payload is not executed as js' )
635
- } )
636
- . appendTo ( '#qunit-fixture' )
637
-
638
- $toggleBtn . trigger ( 'click' )
639
- setTimeout ( done , 500 )
625
+ try {
626
+ // This toggle button contains XSS payload in its data-target
627
+ // Note: it uses the onerror handler of an img element to execute the js, because a simple script element does not work here
628
+ // a script element works in manual tests though, so here it is likely blocked by the qunit framework
629
+ var $toggleBtn = $ ( '<button data-toggle="modal" data-target="<div><image src="missing.png" onerror="$('#qunit-fixture button.control').trigger('click')"></div>"/>' )
630
+ . appendTo ( '#qunit-fixture' )
631
+ // The XSS payload above does not have a closure over this function and cannot access the assert object directly
632
+ // However, it can send a click event to the following control button, which will then fail the assert
633
+ $ ( '<button>' )
634
+ . addClass ( 'control' )
635
+ . on ( 'click' , function ( ) {
636
+ assert . notOk ( true , 'XSS payload is not executed as js' )
637
+ } )
638
+ . appendTo ( '#qunit-fixture' )
639
+
640
+ $toggleBtn . trigger ( 'click' )
641
+ } catch ( e ) {
642
+ done ( )
643
+ }
640
644
} )
641
645
642
646
QUnit . test ( 'should not try to open a modal which is already visible' , function ( assert ) {
0 commit comments