]> source.dussan.org Git - jquery.git/commitdiff
Tests: Strip untypical callback parameter characters from PHP files 1.12-stable 5007/head
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Thu, 29 Apr 2021 16:27:58 +0000 (18:27 +0200)
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Thu, 29 Apr 2021 16:38:11 +0000 (18:38 +0200)
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 acb7c49c8d42f601fa347661b1118959079f6b52)

.travis.yml
test/data/jsonp.php
test/data/with_fries_over_jsonp.php
test/unit/ajax.js
test/unit/support.js

index 34f4d9aecee4afdedea5bf7a789a689365e82ab1..be62086021dfa5dee048ff9a0bb3c0c855956626 100644 (file)
@@ -1,8 +1,9 @@
 language: node_js
-sudo: false
+os: linux
 node_js:
-- "0.10"
-- "0.12"
 - "4"
-- "5"
 - "6"
+- "8"
+- "10"
+- "12"
+- "14"
index 6c13d72e9d2971b5ec8e70bfc94b45ad4f92f030..51eee1c6f50a62abaf2b13efab1e4a20443f3f7a 100644 (file)
@@ -1,14 +1,15 @@
 <?php
 error_reporting(0);
+function cleanCallback( $callback ) {
+       return preg_replace( '/[^a-z0-9_]/i', '', $callback );
+}
 $callback = $_REQUEST['callback'];
 if ( ! $callback ) {
        $callback = explode("?",end(explode("/",$_SERVER['REQUEST_URI'])));
        $callback = $callback[0];
 }
-$json = $_REQUEST['json'];
-if($json) {
-       echo $callback . '([ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ])';
-} else {
-       echo $callback . '({ "data": {"lang": "en", "length": 25} })';
-}
+$json = $_REQUEST['json'] ?
+       '[ { "name": "John", "age": 21 }, { "name": "Peter", "age": 25 } ]' :
+       '{ "data": { "lang": "en", "length": 25 } }';
+echo cleanCallback( $callback ) . '(' . $json . ')';
 ?>
index 456aeb3bdf235b10b03a5d98b7bb3fc272d59ac6..7de47d12528a45ab74b4b2633531186405c7aa71 100644 (file)
@@ -1,7 +1,11 @@
 <?php
 error_reporting(0);
+function cleanCallback( $callback ) {
+       return preg_replace( '/[^a-z0-9_]/i', '', $callback );
+}
 $callback = $_REQUEST['callback'];
+$cleanCallback = cleanCallback( $callback );
 $json = $_REQUEST['json'];
 $text = json_encode(file_get_contents(dirname(__FILE__)."/with_fries.xml"));
-echo "$callback($text)";
+echo "$cleanCallback($text)\n";
 ?>
index 19c0b7b4f336f08a4ecd2230f97be7e1535f95a3..efe54ba6cf6dc5c2fd71e61fddf720abe07ef2c6 100644 (file)
@@ -1519,14 +1519,20 @@ QUnit.module( "ajax", {
                };
        } );
 
-       testIframeWithCallback(
-               "#14379 - jQuery.ajax() on unload",
-               "ajax/onunload.html",
-               function( status, assert ) {
-                       assert.expect( 1 );
-                       assert.strictEqual( status, "success", "Request completed" );
-               }
-       );
+       // Chrome 78 dropped support for synchronous XHR requests inside of
+       // beforeunload, unload, pagehide, and visibilitychange event handlers.
+       // See https://bugs.chromium.org/p/chromium/issues/detail?id=952452
+       // Safari 13 did similar changes. The below check will catch them both.
+       if ( !/safari/i.test( navigator.userAgent ) ) {
+               testIframeWithCallback(
+                       "#14379 - jQuery.ajax() on unload",
+                       "ajax/onunload.html",
+                       function( status, assert ) {
+                               assert.expect( 1 );
+                               assert.strictEqual( status, "success", "Request completed" );
+                       }
+               );
+       }
 
        // BrowserStack PATCH support sometimes breaks so on TestSwarm run the test in IE only.
        // Unfortunately, all IE versions gets special treatment in request object creation
index b490190e86ebbdf2b343621af81d2bb9fb41c544..0461f4c43b6743fd55726b2cef21a12f2c2d2ffc 100644 (file)
@@ -577,6 +577,7 @@ testIframeWithCallback(
                        "tbody": true
                };
        } else if ( /firefox/i.test( userAgent ) ) {
+               version = userAgent.match( /firefox\/(\d+)/i )[ 1 ];
                expected = {
                        "ajax": true,
                        "appendChecked": true,
@@ -610,7 +611,7 @@ testIframeWithCallback(
                        "radioValue": true,
                        "reliableHiddenOffsets": true,
                        "reliableMarginRight": true,
-                       "reliableMarginLeft": false,
+                       "reliableMarginLeft": version >= 61,
                        "shrinkWrapBlocks": false,
                        "style": true,
                        "submit": true,