Skip to content

Commit 17479f8

Browse files
authored
handle apache DocumentRoot cyrillic encoding
When DocumentRoot contains cyrillic characters like DocumentRoot /home/hans/web/cyrillicрф.ratma.net/public_html and PHP is invoked with SetHandler (*PS not applicable to ProxySetMatch, the problem occurs with SetHandler specifically) like DocumentRoot /home/hans/web/cyrillicрф.ratma.net/public_html <FilesMatch \.php$> SetHandler "proxy:unix:/run/php/php8.3-fpm-cyrillicрф.ratma.net.sock" </FilesMatch> then apache will url-encode the cyrillic characters before sending it to fpm, so env_script_filename will contain /home/hans/web/cyrillic%D1%80%D1%84.ratma.net/public_html/index.php and we need to url-decode it to /home/hans/web/cyrillicрф.ratma.net/public_html/index.php otherwise we hit that zlog(ZLOG_DEBUG, "Primary script unknown"); SG(sapi_headers).http_response_code = 404; PUTS("File not found.\n"); error code path.
1 parent c5d9c7d commit 17479f8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

sapi/fpm/fpm/fpm_main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,17 @@ static void init_request_info(void)
10351035
/* Copy path portion in place to avoid memory leak. Note
10361036
* that this also affects what script_path_translated points
10371037
* to. */
1038-
memmove(env_script_filename, p, strlen(p) + 1);
1038+
size_t plen = strlen(p);
1039+
memmove(env_script_filename, p, plen + 1);
10391040
apache_was_here = 1;
1041+
// If DocumentRoot contains cyrillic characters and PHP is invoked with SetHandler (not applicable to ProxySetMatch),
1042+
// then the cyrillic characters are urlencoded by apache, and we need to decode them, for example with
1043+
// DocumentRoot /home/hans/web/cyrillicрф.ratma.net/public_html
1044+
// env_script_filename contains /home/hans/web/cyrillic%D1%80%D1%84.ratma.net/public_html/index.php.
1045+
// and we must decode it to /home/hans/web/cyrillicрф.ratma.net/public_html/index.php.
1046+
if(memchr(env_script_filename, '%', plen) != NULL){
1047+
plen = php_url_decode(env_script_filename, plen);
1048+
}
10401049
}
10411050
/* ignore query string if sent by Apache (RewriteRule) */
10421051
p = strchr(env_script_filename, '?');

0 commit comments

Comments
 (0)