From b04b09ef563e46c1d594affeed71a4c35c91656b Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Thu, 4 Jan 2024 14:51:20 +0000 Subject: [PATCH] Fix GH-12996: Incorrect SCRIPT_NAME with Apache ProxyPassMatch when plus in path Closes GH-13072 --- NEWS | 4 ++ sapi/fpm/fpm/fpm_main.c | 2 +- ...v-pif-apache-pp-sn-strip-encoded-plus.phpt | 54 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 sapi/fpm/tests/fcgi-env-pif-apache-pp-sn-strip-encoded-plus.phpt diff --git a/NEWS b/NEWS index a75aaddfe6d..bd3224b031d 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ PHP NEWS . Fixed timer leak in zend-max-execution-timers builds. (withinboredom) . Fixed bug GH-12349 (linking failure on ARM with mold). (Jan Palus) +- FPM: + . Fixed bug GH-12996 (Incorrect SCRIPT_NAME with Apache ProxyPassMatch when + plus in path). (Jakub Zelenka) + - Phar: . Fixed bug #71465 (PHAR doesn't know about litespeed). (nielsdos) diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index b3ae2f69cc5..94a9ca6c7e6 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1165,7 +1165,7 @@ static void init_request_info(void) size_t decoded_path_info_len = 0; if (strchr(path_info, '%')) { decoded_path_info = estrdup(path_info); - decoded_path_info_len = php_url_decode(decoded_path_info, strlen(path_info)); + decoded_path_info_len = php_raw_url_decode(decoded_path_info, strlen(path_info)); } size_t snlen = strlen(env_script_name); size_t env_script_file_info_start = 0; diff --git a/sapi/fpm/tests/fcgi-env-pif-apache-pp-sn-strip-encoded-plus.phpt b/sapi/fpm/tests/fcgi-env-pif-apache-pp-sn-strip-encoded-plus.phpt new file mode 100644 index 00000000000..4bef11ec668 --- /dev/null +++ b/sapi/fpm/tests/fcgi-env-pif-apache-pp-sn-strip-encoded-plus.phpt @@ -0,0 +1,54 @@ +--TEST-- +FPM: FastCGI env var path info fix for Apache ProxyPass SCRIPT_NAME encoded path and plush sign (GH-12996) +--SKIPIF-- + +--FILE-- +createSourceFileAndScriptName(); +$tester->start(); +$tester->expectLogStartNotices(); +$tester + ->request( + uri: $scriptName . '/1%202', + scriptFilename: "proxy:fcgi://" . $tester->getAddr() . $sourceFilePath . '/1%20+2', + scriptName: $scriptName . '/1 +2' + ) + ->expectBody([$scriptName, $scriptName . '/1 +2', $sourceFilePath, '/1%20+2', $scriptName . '/1%20+2']); +$tester->terminate(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +