Ajax: Mitigate possible XSS vulnerability

Proposed by @jaubourg

Cherry-picked from b078a62013
Fixes gh-2432
Closes gh-2588
This commit is contained in:
Oleg Gaidarenko 2015-09-10 13:40:00 +03:00
parent 5da5035039
commit f60729f390
2 changed files with 55 additions and 0 deletions

View File

@ -4,6 +4,13 @@ define( [
"../ajax" "../ajax"
], function( jQuery, document ) { ], function( jQuery, document ) {
// Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432)
jQuery.ajaxPrefilter( function( s ) {
if ( s.crossDomain ) {
s.contents.script = false;
}
} );
// Install script dataType // Install script dataType
jQuery.ajaxSetup( { jQuery.ajaxSetup( {
accepts: { accepts: {

View File

@ -85,6 +85,54 @@ QUnit.module( "ajax", {
}; };
} ); } );
ajaxTest( "jQuery.ajax() - do not execute js (crossOrigin)", 2, function( assert ) {
return {
create: function( options ) {
options.crossDomain = true;
return jQuery.ajax( url( "data/script.php?header=ecma" ), options );
},
success: function() {
assert.ok( true, "success" );
},
complete: function() {
assert.ok( true, "complete" );
}
};
} );
ajaxTest( "jQuery.ajax() - execute js for crossOrigin when dataType option is provided", 3,
function( assert ) {
return {
create: function( options ) {
options.crossDomain = true;
options.dataType = "script";
return jQuery.ajax( url( "data/script.php?header=ecma" ), options );
},
success: function() {
assert.ok( true, "success" );
},
complete: function() {
assert.ok( true, "complete" );
}
};
}
);
ajaxTest( "jQuery.ajax() - do not execute js (crossOrigin)", 2, function( assert ) {
return {
create: function( options ) {
options.crossDomain = true;
return jQuery.ajax( url( "data/script.php" ), options );
},
success: function() {
assert.ok( true, "success" );
},
complete: function() {
assert.ok( true, "complete" );
}
};
} );
ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert ) { ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert ) {
return { return {
setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),