Skip to content

Commit 90a3c43

Browse files
committed
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 gh-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 gh-4875 Ref gh-4764 Ref gh-4871 (cherry picked from acb7c49)
1 parent e09907c commit 90a3c43

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
@@ -1519,14 +1519,20 @@ QUnit.module( "ajax", {
15191519
};
15201520
} );
15211521

1522-
testIframeWithCallback(
1523-
"#14379 - jQuery.ajax() on unload",
1524-
"ajax/onunload.html",
1525-
function( status, assert ) {
1526-
assert.expect( 1 );
1527-
assert.strictEqual( status, "success", "Request completed" );
1528-
}
1529-
);
1522+
// Chrome 78 dropped support for synchronous XHR requests inside of
1523+
// beforeunload, unload, pagehide, and visibilitychange event handlers.
1524+
// See https://bugs.chromium.org/p/chromium/issues/detail?id=952452
1525+
// Safari 13 did similar changes. The below check will catch them both.
1526+
if ( !/safari/i.test( navigator.userAgent ) ) {
1527+
testIframeWithCallback(
1528+
"#14379 - jQuery.ajax() on unload",
1529+
"ajax/onunload.html",
1530+
function( status, assert ) {
1531+
assert.expect( 1 );
1532+
assert.strictEqual( status, "success", "Request completed" );
1533+
}
1534+
);
1535+
}
15301536

15311537
// BrowserStack PATCH support sometimes breaks so on TestSwarm run the test in IE only.
15321538
// Unfortunately, all IE versions gets special treatment in request object creation

test/unit/support.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ testIframeWithCallback(
577577
"tbody": true
578578
};
579579
} else if ( /firefox/i.test( userAgent ) ) {
580+
version = userAgent.match( /firefox\/(\d+)/i )[ 1 ];
580581
expected = {
581582
"ajax": true,
582583
"appendChecked": true,
@@ -610,7 +611,7 @@ testIframeWithCallback(
610611
"radioValue": true,
611612
"reliableHiddenOffsets": true,
612613
"reliableMarginRight": true,
613-
"reliableMarginLeft": false,
614+
"reliableMarginLeft": version >= 61,
614615
"shrinkWrapBlocks": false,
615616
"style": true,
616617
"submit": true,

0 commit comments

Comments
 (0)