File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ var jQuery = function( selector, context ) {
16
16
rootjQuery ,
17
17
18
18
// A simple way to check for HTML strings or ID strings
19
- // (both of which we optimize for )
20
- quickExpr = / ^ (?: [ ^ < ] * ( < [ \w \W ] + > ) [ ^ > ] * $ | # ( [ \w \- ] * ) $ ) / ,
19
+ // Prioritize #id over <tag> to avoid XSS via location.hash (#9521 )
20
+ quickExpr = / ^ (?: [ ^ # < ] * ( < [ \w \W ] + > ) [ ^ > ] * $ | # ( [ \w \- ] * ) $ ) / ,
21
21
22
22
// Check if a string has a non-whitespace character in it
23
23
rnotwhite = / \S / ,
Original file line number Diff line number Diff line change @@ -467,6 +467,24 @@ test("isXMLDoc - HTML", function() {
467
467
document . body . removeChild ( iframe ) ;
468
468
} ) ;
469
469
470
+ test ( "XSS via location.hash" , function ( ) {
471
+ expect ( 1 ) ;
472
+
473
+ stop ( ) ;
474
+ jQuery . _check9521 = function ( x ) {
475
+ ok ( x , "script called from #id-like selector with inline handler" ) ;
476
+ jQuery ( "#check9521" ) . remove ( ) ;
477
+ delete jQuery . _check9521 ;
478
+ start ( ) ;
479
+ } ;
480
+ try {
481
+ // This throws an error because it's processed like an id
482
+ jQuery ( '#<img id="check9521" src="no-such-.gif" onerror="jQuery._check9521(false)">' ) . appendTo ( "#qunit-fixture" ) ;
483
+ } catch ( err ) {
484
+ jQuery . _check9521 ( true ) ;
485
+ } ;
486
+ } ) ;
487
+
470
488
if ( ! isLocal ) {
471
489
test ( "isXMLDoc - XML" , function ( ) {
472
490
expect ( 3 ) ;
You can’t perform that action at this time.
0 commit comments