🌐 AI搜索 & 代理 主页
Skip to content

Commit cc8bbd3

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 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. Ref jquerygh-4764 Ref jquerygh-4871
1 parent b14ce54 commit cc8bbd3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

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
?>

0 commit comments

Comments
 (0)