diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2021-04-13 22:13:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 22:13:48 +0200 |
commit | a70274632dc19ff4a64d7bb7657a2cc647ff38b9 (patch) | |
tree | 270614d4b47cdb80eb08db92dd556ff17bb6e1cc /test/data | |
parent | 50e8e84621ff7a314fca253ce73f0519322d8a4d (diff) | |
download | jquery-a70274632dc19ff4a64d7bb7657a2cc647ff38b9.tar.gz jquery-a70274632dc19ff4a64d7bb7657a2cc647ff38b9.zip |
Tests: Strip untypical callback parameter characters from mock.php
Only allow alphanumeric characters & underscores for callback parameters.
The change is done both for the PHP server as well as the Node.js-based version.
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.
Ref gh-4764
Closes gh-4871
Diffstat (limited to 'test/data')
-rw-r--r-- | test/data/mock.php | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/test/data/mock.php b/test/data/mock.php index 24302e6bc..2e90de6d3 100644 --- a/test/data/mock.php +++ b/test/data/mock.php @@ -1,7 +1,12 @@ <?php + /** * Keep in sync with /test/middleware-mockserver.js */ +function cleanCallback( $callback ) { + return preg_replace( '/[^a-z0-9_]/i', '', $callback ); +} + class MockServer { protected function contentType( $req ) { $type = $req->query['contentType']; @@ -65,7 +70,8 @@ class MockServer { array_values( $req->headers ) ); - echo $req->query['callback'] . "(" . json_encode( [ 'headers' => $headers ] ) . ")"; + echo cleanCallback( $req->query['callback'] ) . + "(" . json_encode( [ 'headers' => $headers ] ) . ")"; } else { echo 'QUnit.assert.ok( true, "mock executed" );'; } @@ -105,17 +111,17 @@ QUnit.assert.ok( true, "mock executed");'; } else { $callback = $_POST['callback']; } - if ( isset( $req->query['array'] ) ) { - echo $callback . '([ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ])'; - } else { - echo $callback . '({ "data": {"lang": "en", "length": 25} })'; - } + $json = isset( $req->query['array'] ) ? + '[ { "name": "John", "age": 21 }, { "name": "Peter", "age": 25 } ]' : + '{ "data": { "lang": "en", "length": 25 } }'; + echo cleanCallback( $callback ) . '(' . $json . ')'; } protected function xmlOverJsonp( $req ) { $callback = $_REQUEST['callback']; + $cleanCallback = cleanCallback( $callback ); $text = json_encode( file_get_contents( __DIR__ . '/with_fries.xml' ) ); - echo "$callback($text)\n"; + echo "$cleanCallback($text)\n"; } protected function error( $req ) { @@ -243,7 +249,7 @@ QUnit.assert.ok( true, "mock executed");'; } if ( isset( $req->query['callback'] ) ) { $callback = $req->query['callback']; - echo $callback . '( {"status": 404, "msg": "Not Found"} )'; + echo cleanCallback( $callback ) . '( {"status": 404, "msg": "Not Found"} )'; } else { echo 'QUnit.assert.ok( false, "Mock return erroneously executed" );'; } |