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 ) {
1616 rootjQuery ,
1717
1818 // 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 \- ] * ) $ ) / ,
2121
2222 // Check if a string has a non-whitespace character in it
2323 rnotwhite = / \S / ,
Original file line number Diff line number Diff line change @@ -467,6 +467,24 @@ test("isXMLDoc - HTML", function() {
467467 document . body . removeChild ( iframe ) ;
468468} ) ;
469469
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+
470488if ( ! isLocal ) {
471489test ( "isXMLDoc - XML" , function ( ) {
472490 expect ( 3 ) ;
You can’t perform that action at this time.
0 commit comments