Bug #79889 [NEW]: CLI process contains $_SERVER['HTTP_*'] variables
From: ibrahim dot alexandru at gmail dot com
Operating system: macOS
PHP version: 7.4.8
Package: CGI/CLI related
Bug Type: Bug
Bug description:CLI process contains $_SERVER['HTTP_*'] variables
Description:
------------
When executing a php script through CLI that has been triggered with
shell_exec() from a script that was running under Apache, the newly
spawned cli script contains all the HTTP related variables in $_SERVER,
and it shouldn't.
In apache config I have a VirtualHost with the following:
ScriptAlias /cgi-bin/ /usr/local/Cellar/php/7.4.8/bin/
AddHandler php-cgi php
Action php-cgi /cgi-bin/php-cgi
Test script:
---------------
<?php
echo '<pre>';
echo php_sapi_name().PHP_EOL;
if (php_sapi_name() == 'cli') {
print_r($_SERVER);
} else {
echo shell_exec('/usr/local/bin/php '.__FILE__);
}
echo '</pre>';
Actual result:
--------------
cgi-fcgi
cli
Array
(
[SERVER_SIGNATURE] =>
[ORIG_PATH_TRANSLATED] => /Volumes/Macintosh
HD/Users/ibra/Documents/work/www/__work_projects/basicly/test.php
[HTTP_SEC_FETCH_DEST] => document
[HTTP_SEC_FETCH_USER] => ?1
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89
Safari/537.36
[SERVER_PORT] => 80
[HTTP_HOST] => dev.localhost
[REDIRECT_no_gzip] => 1
[REDIRECT_HANDLER] => php-cgi
[DOCUMENT_ROOT] =>
[SCRIPT_FILENAME] =>
/Users/ibra/Documents/work/www/__work_projects/basicly/test.php
[REQUEST_URI] => /basicly/test.php
[SCRIPT_NAME] =>
/Users/ibra/Documents/work/www/__work_projects/basicly/test.php
[__CF_USER_TEXT_ENCODING] => 0x46:0:0
[HTTP_CONNECTION] => keep-alive
[REMOTE_PORT] => 54901
[no_gzip] => 1
[ORIG_SCRIPT_FILENAME] => /usr/local/Cellar/php/7.4.8/bin/php-cgi
[PATH] =>
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware
Fusion.app/Contents/Public:/opt/X11/bin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS
[CONTEXT_PREFIX] => /cgi-bin/
[PWD] => /Users/ibra/Documents/work/www/__work_projects/basicly
[SERVER_ADMIN] => you@example.com
[REQUEST_SCHEME] => http
[REDIRECT_STATUS] => 200
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.9,ro;q=0.8
[ORIG_SCRIPT_NAME] => /cgi-bin/php-cgi
[HTTP_ACCEPT] =>
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
[REMOTE_ADDR] => ::1
[SHLVL] => 1
[SERVER_NAME] => dev.localhost
[SERVER_SOFTWARE] => Apache/2.4.43 (Unix) OpenSSL/1.1.1g PHP/7.4.8
[HTTP_SEC_FETCH_MODE] => navigate
[QUERY_STRING] =>
[SERVER_ADDR] => ::1
[GATEWAY_INTERFACE] => CGI/1.1
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[SERVER_PROTOCOL] => HTTP/1.1
[HTTP_ACCEPT_ENCODING] => gzip, deflate, br
[HTTP_CACHE_CONTROL] => max-age=0
[REDIRECT_URL] => /basicly/test.php
[HTTP_SEC_FETCH_SITE] => none
[REQUEST_METHOD] => GET
[HTTP_COOKIE] => iact_ECMSIMCO=b77hemh4vpum0qnoosjl39btju;
_ga=GA1.2.2114080618.1579620442;
iact_VENEDGE=020enm3i9kihfdrf16glq80s7o; TEXTEDLY_v2_lang=en;
px_anonymousId=848ea8ec-03d6-2268-1f9d-7a9efb4a9c99;
ajs_anonymous_id=%22848ea8ec-03d6-2268-1f9d-7a9efb4a9c99%22;
__stripe_mid=1dea8218-0664-49f5-b0d1-bbb7dc62fc82;
PHPSESSID=t5nfctqv6na7do971vfmae9fdj;
TEXTEDLY_v2_logged_userdata=28d4cc7b19e27ee2f1746d8b5eabb0e5;
TEXTEDLY_v2_auth=28d4cc7b19e27ee2f1746d8b5eabb0e5;
_gcl_au=1.1.523438538.1588778051; TEXTEDLY_v2-toggle=false;
_delighted_web={%22C1ilulsh64lroAwc%22:{%22_delighted_fst%22:{%22t%22:%221595244303260%22}}};
intercom-session-goeihfsj=aGg4dW80aGFUZVpvK1F4RUJQTUhVenNUcXpOWlZzVy93NW1sNzU5MjBuNXZKSWU3K0xpT21VS2p0QStYdlJCTy0tM2dRM0RPeFh1TXdkeHZYSlpNYVJZQT09--98d794fd0e98a6363dc84f7356776271e8223b9f;
XDEBUG_SESSION=PHPSTORM
[ORIG_PATH_INFO] => /basicly/test.php
[CONTEXT_DOCUMENT_ROOT] => /usr/local/Cellar/php/7.4.8/bin/
[_] => /usr/local/bin/php
[PHP_SELF] =>
/Users/ibra/Documents/work/www/__work_projects/basicly/test.php
[PATH_TRANSLATED] =>
/Users/ibra/Documents/work/www/__work_projects/basicly/test.php
[REQUEST_TIME_FLOAT] => 1595512781.5624
[REQUEST_TIME] => 1595512781
[argv] => Array
(
[0] =>
/Users/ibra/Documents/work/www/__work_projects/basicly/test.php
)
[argc] => 1
)
--
Edit bug report at https://bugs.php.net/bug.php?id=79889&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79889&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79889&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79889&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79889&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79889&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79889&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79889&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79889&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79889&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79889&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79889&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79889&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79889&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79889&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79889&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79889&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79889&r=mysqlcfg
Thread (6 messages)
- ibrahim dot alexandru at gmail dot com