Skip to content

fix all CVEs in 1.5.2 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: 1.5.2-branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/jslint-check.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var JSLINT = require("./lib/jslint").JSLINT,
print = require("sys").print,
print = console.log,
src = require("fs").readFileSync("dist/jquery.js", "utf8");

JSLINT(src, { evil: true, forin: true, maxerr: 100 });
Expand All @@ -21,7 +21,7 @@ var e = JSLINT.errors, found = 0, w;
for ( var i = 0; i < e.length; i++ ) {
w = e[i];

if ( !ok[ w.reason ] ) {
if ( w && !ok[ w.reason ] ) {
found++;
print( "\n" + w.evidence + "\n" );
print( " Problem at line " + w.line + " character " + w.character + ": " + w.reason );
Expand Down
2 changes: 1 addition & 1 deletion build/post-compile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

var print = require("sys").print,
var print = console.log,
src = require("fs").readFileSync(process.argv[2], "utf8");

// Previously done in sed but reimplemented here due to portability issues
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "jquery",
"version" : "1.5.2",
"version" : "1.5.3-sec",
"main" : "./jquery.js",
"dependencies": {
}
Expand Down
30 changes: 16 additions & 14 deletions jquery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery JavaScript Library v1.5.2
* jQuery JavaScript Library v1.5.3-sec
* http://jquery.com/
*
* Copyright 2011, John Resig
Expand All @@ -11,7 +11,7 @@
* Copyright 2011, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses.
*
* Date: Thu Mar 31 15:28:23 2011 -0400
* Date: Thu Feb 15 18:40:42 2024 -0600
*/
(function( window, undefined ) {

Expand All @@ -35,8 +35,9 @@ var jQuery = function( selector, context ) {
rootjQuery,

// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
// Strict HTML recognition (#11290: must start with <)
quickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,

// Check if a string has a non-whitespace character in it
rnotwhite = /\S/,
Expand Down Expand Up @@ -196,7 +197,7 @@ jQuery.fn = jQuery.prototype = {
selector: "",

// The current version of jQuery being used
jquery: "1.5.2",
jquery: "1.5.3-sec",

// The default length of a jQuery object is 0
length: 0,
Expand Down Expand Up @@ -340,8 +341,9 @@ jQuery.extend = jQuery.fn.extend = function() {
src = target[ name ];
copy = options[ name ];

// Prevent Object.prototype pollution
// Prevent never-ending loop
if ( target === copy ) {
if ( name === "__proto__" || target === copy ) {
continue;
}

Expand Down Expand Up @@ -5035,15 +5037,13 @@ function winnow( elements, qualifier, keep ) {

var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rleadingWhitespace = /^\s+/,
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
rtagName = /<([\w:]+)/,
rtbody = /<tbody/i,
rhtml = /<|&#?\w+;/,
rnocache = /<(?:script|object|embed|option|style)/i,
// checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
wrapMap = {
option: [ 1, "<select multiple='multiple'>", "</select>" ],
legend: [ 1, "<fieldset>", "</fieldset>" ],
thead: [ 1, "<table>", "</table>" ],
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
Expand All @@ -5053,7 +5053,6 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
_default: [ 0, "", "" ]
};

wrapMap.optgroup = wrapMap.option;
wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
wrapMap.th = wrapMap.td;

Expand Down Expand Up @@ -5236,8 +5235,6 @@ jQuery.fn.extend({
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {

value = value.replace(rxhtmlTag, "<$1></$2>");

try {
for ( var i = 0, l = this.length; i < l; i++ ) {
// Remove element nodes and prevent memory leaks
Expand Down Expand Up @@ -5607,8 +5604,6 @@ jQuery.extend({
elem = context.createTextNode( elem );

} else if ( typeof elem === "string" ) {
// Fix "XHTML"-style tags in all browsers
elem = elem.replace(rxhtmlTag, "<$1></$2>");

// Trim whitespace, otherwise indexOf won't work as expected
var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
Expand Down Expand Up @@ -6111,7 +6106,7 @@ var r20 = /%20/g,
rnoContent = /^(?:GET|HEAD)$/,
rprotocol = /^\/\//,
rquery = /\?/,
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*< *\/ *script *>?/gi,
rselectTextarea = /^(?:select|textarea)/i,
rspacesAjax = /\s+/,
rts = /([?&])_=[^&]*/,
Expand Down Expand Up @@ -7162,6 +7157,13 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {



// 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
jQuery.ajaxSetup({
accepts: {
Expand Down
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var r20 = /%20/g,
rnoContent = /^(?:GET|HEAD)$/,
rprotocol = /^\/\//,
rquery = /\?/,
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*< *\/ *script *>?/gi,
rselectTextarea = /^(?:select|textarea)/i,
rspacesAjax = /\s+/,
rts = /([?&])_=[^&]*/,
Expand Down
7 changes: 7 additions & 0 deletions src/ajax/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
(function( jQuery ) {

// 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
jQuery.ajaxSetup({
accepts: {
Expand Down
8 changes: 5 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ var jQuery = function( selector, context ) {
rootjQuery,

// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
// Strict HTML recognition (#11290: must start with <)
quickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,

// Check if a string has a non-whitespace character in it
rnotwhite = /\S/,
Expand Down Expand Up @@ -321,8 +322,9 @@ jQuery.extend = jQuery.fn.extend = function() {
src = target[ name ];
copy = options[ name ];

// Prevent Object.prototype pollution
// Prevent never-ending loop
if ( target === copy ) {
if ( name === "__proto__" || target === copy ) {
continue;
}

Expand Down
7 changes: 0 additions & 7 deletions src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rleadingWhitespace = /^\s+/,
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
rtagName = /<([\w:]+)/,
rtbody = /<tbody/i,
rhtml = /<|&#?\w+;/,
rnocache = /<(?:script|object|embed|option|style)/i,
// checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
wrapMap = {
option: [ 1, "<select multiple='multiple'>", "</select>" ],
legend: [ 1, "<fieldset>", "</fieldset>" ],
thead: [ 1, "<table>", "</table>" ],
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
Expand All @@ -20,7 +18,6 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
_default: [ 0, "", "" ]
};

wrapMap.optgroup = wrapMap.option;
wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
wrapMap.th = wrapMap.td;

Expand Down Expand Up @@ -203,8 +200,6 @@ jQuery.fn.extend({
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {

value = value.replace(rxhtmlTag, "<$1></$2>");

try {
for ( var i = 0, l = this.length; i < l; i++ ) {
// Remove element nodes and prevent memory leaks
Expand Down Expand Up @@ -574,8 +569,6 @@ jQuery.extend({
elem = context.createTextNode( elem );

} else if ( typeof elem === "string" ) {
// Fix "XHTML"-style tags in all browsers
elem = elem.replace(rxhtmlTag, "<$1></$2>");

// Trim whitespace, otherwise indexOf won't work as expected
var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
Expand Down
63 changes: 63 additions & 0 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,69 @@ test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
}, 13);
});

test("jQuery.ajax() - do not execute js (crossOrigin)", function() {
expect(2);

var base = window.location.href.replace(/[^\/]*$/, "");

stop();

jQuery.ajax({
url: base + "data/script.php?header=ecma",
crossDomain: true,
success: function(data){
ok( true, "success" );
start();
},
complete: function() {
ok( true, "complete" );
}
});
});

test( "jQuery.ajax() - execute js for crossOrigin when dataType option is provided",
function() {
expect(3);

var base = window.location.href.replace(/[^\/]*$/, "");

stop();

jQuery.ajax({
url: base + "data/script.php?header=ecma",
crossDomain: true,
dataType: "script",
success: function(data){
ok( true, "success" );
start();
},
complete: function() {
ok( true, "complete" );
}
});
}
);

test("jQuery.ajax() - do not execute js (crossOrigin)", function() {
expect(2);

var base = window.location.href.replace(/[^\/]*$/, "");

stop();

jQuery.ajax({
url: base + "data/script.php",
crossDomain: true,
success: function(data){
ok( true, "success" );
start();
},
complete: function() {
ok( true, "complete" );
}
});
});

test("jQuery.ajax() - success callbacks (late binding)", function() {
expect( 8 );

Expand Down
32 changes: 31 additions & 1 deletion test/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test("jQuery()", function() {
var img = jQuery("<img/>");
equals( img.length, 1, "Correct number of elements generated for img" );
equals( img.parent().length, 0, "Make sure that the generated HTML has no parent." );
var div = jQuery("<div/><hr/><code/><b/>");
var div = jQuery("<div></div><hr><code></code><b></b>");
equals( div.length, 4, "Correct number of elements generated for div hr code b" );
equals( div.parent().length, 0, "Make sure that the generated HTML has no parent." );

Expand Down Expand Up @@ -510,6 +510,36 @@ test("jQuery('html', context)", function() {
equals($span.length, 1, "Verify a span created with a div context works, #1763");
});

test("XSS via location.hash", function() {
expect(1);

stop();
jQuery._check9521 = function(x){
ok( x, "script called from #id-like selector with inline handler" );
jQuery("#check9521").remove();
delete jQuery._check9521;
};

var $eCheck9521 = jQuery( '#<img id="check9521" src="no-such-.gif" onerror="jQuery._check9521(false)"' );

if($eCheck9521.length) {
$eCheck9521.appendTo("#main");
}
else {
jQuery._check9521(true);
}

start();

});

test( "jQuery.extend( true, ... ) Object.prototype pollution", function( assert ) {
expect( 1 );

jQuery.extend( true, {}, JSON.parse( "{\"__proto__\": {\"devMode\": true}}" ) );
ok( !( "devMode" in {} ), "Object.prototype not polluted" );
} );

if ( !isLocal ) {
test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
expect(2);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test("css(String|Hash)", function() {
equals( div.css("width"), "4px", "Width on disconnected node." );
equals( div.css("height"), "4px", "Height on disconnected node." );

var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'></textarea><div style='height:20px;'></div></div>").appendTo("body");

equals( div2.find("input").css("height"), "20px", "Height on hidden input." );
equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
Expand Down
2 changes: 1 addition & 1 deletion test/unit/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ var testHtml = function(valueObj) {
}
ok( pass, "Set HTML" );

div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') );
div = jQuery("<div>").html( valueObj("<div id='parent_1'><div id='child_1'></div></div><div id='parent_2'></div>") );

equals( div.children().length, 2, "Make sure two child nodes exist." );
equals( div.children().children().length, 1, "Make sure that a grandchild exists." );
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.2
1.5.3-sec