Skip to content

Commit acb7c49

Browse files
authored
Tests: Strip untypical callback parameter characters from PHP files
Only allow alphanumeric characters & underscores for callback parameters. This is only test code so we're not fixing any security issue but it happens often enough that the whole jQuery repository directory structure is deployed onto the server with PHP enabled that it makes is easy to introduce security issues if this cleanup is not done. This is a 1.x/2.x version of PR jquerygh-4871. The change doesn't require a release; it's meant at installations testing the latest state of `1.12-stable` & `2.2-stable` branches. This change also fixes testing on Travis & on Chrome/Firefox. Closes jquerygh-4875 Ref jquerygh-4764 Ref jquerygh-4871
1 parent b14ce54 commit acb7c49

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
language: node_js
2-
sudo: false
2+
os: linux
33
node_js:
4-
- "0.10"
5-
- "0.12"
64
- "4"
7-
- "5"
85
- "6"
6+
- "8"
7+
- "10"
8+
- "12"
9+
- "14"

test/data/jsonp.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22
error_reporting(0);
3+
function cleanCallback( $callback ) {
4+
return preg_replace( '/[^a-z0-9_]/i', '', $callback );
5+
}
36
$callback = $_REQUEST['callback'];
47
if ( ! $callback ) {
58
$callback = explode("?",end(explode("/",$_SERVER['REQUEST_URI'])));
69
$callback = $callback[0];
710
}
8-
$json = $_REQUEST['json'];
9-
if($json) {
10-
echo $callback . '([ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ])';
11-
} else {
12-
echo $callback . '({ "data": {"lang": "en", "length": 25} })';
13-
}
11+
$json = $_REQUEST['json'] ?
12+
'[ { "name": "John", "age": 21 }, { "name": "Peter", "age": 25 } ]' :
13+
'{ "data": { "lang": "en", "length": 25 } }';
14+
echo cleanCallback( $callback ) . '(' . $json . ')';
1415
?>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22
error_reporting(0);
3+
function cleanCallback( $callback ) {
4+
return preg_replace( '/[^a-z0-9_]/i', '', $callback );
5+
}
36
$callback = $_REQUEST['callback'];
7+
$cleanCallback = cleanCallback( $callback );
48
$json = $_REQUEST['json'];
59
$text = json_encode(file_get_contents(dirname(__FILE__)."/with_fries.xml"));
6-
echo "$callback($text)";
10+
echo "$cleanCallback($text)\n";
711
?>

test/unit/ajax.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,14 +1758,20 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
17581758
};
17591759
} );
17601760

1761-
testIframeWithCallback(
1762-
"#14379 - jQuery.ajax() on unload",
1763-
"ajax/onunload.html",
1764-
function( status, assert ) {
1765-
assert.expect( 1 );
1766-
assert.strictEqual( status, "success", "Request completed" );
1767-
}
1768-
);
1761+
// Chrome 78 dropped support for synchronous XHR requests inside of
1762+
// beforeunload, unload, pagehide, and visibilitychange event handlers.
1763+
// See https://bugs.chromium.org/p/chromium/issues/detail?id=952452
1764+
// Safari 13 did similar changes. The below check will catch them both.
1765+
if ( !/safari/i.test( navigator.userAgent ) ) {
1766+
testIframeWithCallback(
1767+
"#14379 - jQuery.ajax() on unload",
1768+
"ajax/onunload.html",
1769+
function( status, assert ) {
1770+
assert.expect( 1 );
1771+
assert.strictEqual( status, "success", "Request completed" );
1772+
}
1773+
);
1774+
}
17691775

17701776
ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, function( assert ) {
17711777
return [ {

test/unit/support.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ testIframeWithCallback(
223223
"reliableMarginRight": true
224224
};
225225
} else if ( /firefox/i.test( userAgent ) ) {
226+
version = userAgent.match( /firefox\/(\d+)/i )[ 1 ];
226227
expected = {
227228
"ajax": true,
228229
"boxSizingReliable": true,
@@ -237,7 +238,7 @@ testIframeWithCallback(
237238
"pixelMarginRight": true,
238239
"pixelPosition": true,
239240
"radioValue": true,
240-
"reliableMarginLeft": false,
241+
"reliableMarginLeft": version >= 61,
241242
"reliableMarginRight": true
242243
};
243244
} else if ( /iphone os 9_/i.test( userAgent ) ) {

0 commit comments

Comments
 (0)