Skip to content

Commit bc143ff

Browse files
author
Pat Patterson
committed
Guard remaining array dereferences with isset
1 parent f388155 commit bc143ff

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

proxy.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@
187187
$status = array();
188188

189189
if ( $url_query_param != null ) {
190-
$url = $_GET[$url_query_param];
190+
$url = isset($_GET[$url_query_param]) ? $_GET[$url_query_param] : null;
191191
} else if ( $url_header != null ) {
192-
$url = $_SERVER[$url_header];
192+
$url = isset($_SERVER[$url_header]) ? $_SERVER[$url_header] : null;
193193
} else {
194194
$url = null;
195195
}
@@ -218,7 +218,8 @@
218218
if ( isset( $cors_allow_headers ) ) {
219219
header( 'Access-Control-Allow-Headers: '.strtolower($cors_allow_headers) );
220220
}
221-
if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) {
221+
if ( isset($_SERVER['REQUEST_METHOD']) &&
222+
($_SERVER['REQUEST_METHOD'] == 'OPTIONS') ) {
222223
// We're done - don't proxy CORS OPTIONS request
223224
exit();
224225
}
@@ -227,7 +228,8 @@
227228
$ch = curl_init( $url );
228229

229230
// Pass on request method, regardless of what it is
230-
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD'] );
231+
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST,
232+
isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET' );
231233

232234
// Pass on content, regardless of request method
233235
if ( isset($_SERVER['CONTENT_LENGTH'] ) && $_SERVER['CONTENT_LENGTH'] > 0 ) {
@@ -239,7 +241,7 @@
239241
foreach ( $_COOKIE as $key => $value ) {
240242
$cookie[] = $key . '=' . $value;
241243
}
242-
if ( $_GET['send_session'] ) {
244+
if ( isset($_GET['send_session']) ) {
243245
$cookie[] = SID;
244246
}
245247
$cookie = implode( '; ', $cookie );
@@ -262,7 +264,7 @@
262264
}
263265
if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
264266
array_push($headers, $_SERVER['HTTP_X_FORWARDED_FOR'].", ".$_SERVER['HTTP_X_USER_AGENT'] );
265-
} else {
267+
} else if (isset($_SERVER['REMOTE_ADDR'])) {
266268
array_push($headers, "X-Forwarded-For: ".$_SERVER['REMOTE_ADDR'] );
267269
}
268270

@@ -290,9 +292,9 @@
290292
}
291293

292294
// Split header text into an array.
293-
$header_text = preg_split( '/[\r\n]+/', $header );
295+
$header_text = isset($header) ? preg_split( '/[\r\n]+/', $header ) : array();
294296

295-
if ( $_GET['mode'] == 'native' ) {
297+
if ( isset($_GET['mode']) && $_GET['mode'] == 'native' ) {
296298
if ( !$enable_native ) {
297299
$contents = 'ERROR: invalid mode';
298300
$status['http_code'] = 400;
@@ -325,7 +327,7 @@
325327
$data = array();
326328

327329
// Propagate all HTTP headers into the JSON data object.
328-
if ( $_GET['full_headers'] ) {
330+
if ( isset($_GET['full_headers']) ) {
329331
$data['headers'] = array();
330332

331333
foreach ( $header_text as $header ) {
@@ -337,7 +339,7 @@
337339
}
338340

339341
// Propagate all cURL request / response info to the JSON data object.
340-
if ( $_GET['full_status'] ) {
342+
if ( isset($_GET['full_status']) ) {
341343
$data['status'] = $status;
342344
} else {
343345
$data['status'] = array();
@@ -349,11 +351,12 @@
349351
$data['contents'] = $decoded_json ? $decoded_json : $contents;
350352

351353
// Generate appropriate content-type header.
352-
$is_xhr = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
354+
$is_xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
355+
(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
353356
header( 'Content-type: application/' . ( $is_xhr ? 'json' : 'x-javascript' ) );
354357

355358
// Get JSONP callback.
356-
$jsonp_callback = $enable_jsonp && isset($_GET['callback']) ? $_GET['callback'] : null;
359+
$jsonp_callback = ($enable_jsonp && isset($_GET['callback'])) ? $_GET['callback'] : null;
357360

358361
// Generate JSON/JSONP string
359362
$json = json_encode( $data );

0 commit comments

Comments
 (0)