Skip to content

Commit 8cac759

Browse files
committed
Fixed bug #65641 PHP-FPM incorrectly defines the SCRIPT_NAME variable when using Apache
ProxyPass is unable to provide correct PATH_INFO as it is not aware of file path (while SetHandler is). As we can extract PATH_INFO from PATH_TRANSLATED, we also need to check if present in SCRIPT_NAME and remove it. After applying this patch. With mod_php _SERVER["REQUEST_URI"] /info.php/foo/bar?q=1 _SERVER["SCRIPT_NAME"] /info.php _SERVER["PATH_INFO"] /foor/bar _SERVER["PHP_SELF"] /info.php/foo/bar _SERVER["QUERY_STRING"] q=1 With mod_proxy_fcgi + SetHandler _SERVER["REQUEST_URI"] /info.php/foo/bar?q=1 _SERVER["SCRIPT_NAME"] /info.php _SERVER["PATH_INFO"] /foo/bar _SERVER["PHP_SELF"] /info.php/foo/bar _SERVER["QUERY_STRING"] q=1 With mod_proxy_fcgi + ProxyPass _SERVER["REQUEST_URI"] /info.php/foo/bar?q=1 _SERVER["SCRIPT_NAME"] /info.php _SERVER["PATH_INFO"] /foo/bar _SERVER["PHP_SELF"] /info.php/foo/bar _SERVER["QUERY_STRING"] q=1
1 parent 24b41a2 commit 8cac759

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sapi/fpm/fpm/fpm_main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,17 @@ static void init_request_info(TSRMLS_D)
12311231
SG(request_info).request_uri = orig_script_name;
12321232
}
12331233
path_info[0] = old;
1234+
} else if (apache_was_here && env_script_name) {
1235+
/* Using mod_proxy_fcgi and ProxyPass, apache cannot set PATH_INFO
1236+
* As we can extract PATH_INFO from PATH_TRANSLATED
1237+
* it is probably also in SCRIPT_NAME and need to be removed
1238+
*/
1239+
int snlen = strlen(env_script_name);
1240+
if (snlen>slen && !strcmp(env_script_name+snlen-slen, path_info)) {
1241+
_sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC);
1242+
env_script_name[snlen-slen] = 0;
1243+
SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC);
1244+
}
12341245
}
12351246
env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC);
12361247
}

0 commit comments

Comments
 (0)