Skip to content

Commit 9f2e4d3

Browse files
committed
🔒️ fix CVE-2015-9251
1 parent f541672 commit 9f2e4d3

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/ajax/script.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ define( [
44
"../ajax"
55
], function( jQuery, document ) {
66

7+
// Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432)
8+
jQuery.ajaxPrefilter( function( s ) {
9+
if ( s.crossDomain ) {
10+
s.contents.script = false;
11+
}
12+
} );
13+
714
// Install script dataType
815
jQuery.ajaxSetup( {
916
accepts: {

test/unit/ajax.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,54 @@ QUnit.module( "ajax", {
7171
};
7272
} );
7373

74+
ajaxTest( "jQuery.ajax() - do not execute js (crossOrigin)", 2, function( assert ) {
75+
return {
76+
create: function( options ) {
77+
options.crossDomain = true;
78+
return jQuery.ajax( url( "data/script.php?header=ecma" ), options );
79+
},
80+
success: function() {
81+
assert.ok( true, "success" );
82+
},
83+
complete: function() {
84+
assert.ok( true, "complete" );
85+
}
86+
};
87+
} );
88+
89+
ajaxTest( "jQuery.ajax() - execute js for crossOrigin when dataType option is provided", 3,
90+
function( assert ) {
91+
return {
92+
create: function( options ) {
93+
options.crossDomain = true;
94+
options.dataType = "script";
95+
return jQuery.ajax( url( "data/script.php?header=ecma" ), options );
96+
},
97+
success: function() {
98+
assert.ok( true, "success" );
99+
},
100+
complete: function() {
101+
assert.ok( true, "complete" );
102+
}
103+
};
104+
}
105+
);
106+
107+
ajaxTest( "jQuery.ajax() - do not execute js (crossOrigin)", 2, function( assert ) {
108+
return {
109+
create: function( options ) {
110+
options.crossDomain = true;
111+
return jQuery.ajax( url( "data/script.php" ), options );
112+
},
113+
success: function() {
114+
assert.ok( true, "success" );
115+
},
116+
complete: function() {
117+
assert.ok( true, "complete" );
118+
}
119+
};
120+
} );
121+
74122
ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert ) {
75123
return {
76124
setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),

0 commit comments

Comments
 (0)