Repository navigation
fix(nginx): PATH_TRANSLATED only when there is path info to translate (#49) - #50
Merged
Merged
Conversation
sylvesterdamgaard
force-pushed
the
fix/path-translated-fix-pathinfo
branch
from
October 21, 2026 12:15
b16a108 to
1e3d981
Compare
With cgi.fix_pathinfo=0 in a mounted php.ini, every PHP request returned
403:
NOTICE: Access to the script '/var/www/html/public' has been denied
(see security.limit_extensions)
The template sent PATH_TRANSLATED unconditionally as the script root plus
$fastcgi_path_info. That path info is empty on EVERY request here: the
PHP location is `~ \.php$`, which cannot match a URI with anything after
the .php, so fastcgi_split_path_info never has anything to split and
frameworks are reached through try_files as /index.php with a query
string. The value was therefore the web root directory - and with
cgi.fix_pathinfo=0 PHP-FPM takes the script from PATH_TRANSLATED rather
than SCRIPT_FILENAME, finds a directory, and limit_extensions refuses it.
So the param was never right, not merely wrong under that ini. It
predates the $realpath_root change and was equally broken with
$document_root.
Now built through a map and sent `if_not_empty`: omitted when there is no
path info, still correct if the location pattern is ever widened. Applied
to the template and both baked fallback configs.
test-nginx-template.sh grew a case that mounts cgi.fix_pathinfo=0 and
asserts a 200, no denial in the php-fpm log, and that PATH_TRANSLATED is
absent rather than empty. The last assertion is guarded on PHP having
answered at all - a 403 has no JSON body, so an unguarded probe reads as
"not sent" and passes on exactly the broken image it exists to catch.
Verified: 3 failures on the published image, 0 after. security (27),
app-processes (11) and plain-php (18) unchanged.
Closes #49
sylvesterdamgaard
force-pushed
the
fix/path-translated-fix-pathinfo
branch
from
October 21, 2026 14:25
1e3d981 to
f039353
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
cgi.fix_pathinfo=0in a mounted php.ini, every PHP request returned 403:Reproduced against the published
8.5-bookwormbefore changing anything, and the log confirms the cause exactly as reported.Why it was always wrong, not just under that ini
The template sent
PATH_TRANSLATEDunconditionally as the script root plus$fastcgi_path_info. Checking what that path info actually is turned up the real shape of the bug:The PHP location is
~ \.php$, which cannot match a URI with anything after the.php. Sofastcgi_split_path_infonever has anything to split, path info is empty on every request, and frameworks are reached throughtry_filesas/index.phpwith a query string instead.PATH_TRANSLATEDwas therefore always the web root directory — and withcgi.fix_pathinfo=0, PHP-FPM takes the script fromPATH_TRANSLATEDrather thanSCRIPT_FILENAME, finds a directory, andsecurity.limit_extensionsrefuses it.It predates the
$realpath_rootchange and was equally broken with$document_root, as the issue says.The fix
The issue offered two options — drop the param, or only send it when path info is non-empty. This does the second, which satisfies both: the param is omitted today (where path info can never be non-empty) and stays correct if that location pattern is ever widened.
(Map values may contain variables since nginx 1.11.0; this image ships 1.22.) Applied to the template and to both baked fallback configs, which had the same line.
Verification
test-nginx-template.shThe new Test 6 mounts
cgi.fix_pathinfo=0and asserts three things: a 200, nohas been deniedin the php-fpm log, and thatPATH_TRANSLATEDis absent rather than empty.That last assertion is guarded on PHP having answered at all — my first version of it passed on the broken image, because a 403 has no JSON body and the empty probe read as "not sent". Worth knowing if you write a similar check.
Also unchanged on this branch:
security(27),app-processes(11),plain-php(18).Timing
This touches the nginx template, so it would ride along with today's PHP security rebuild if merged first. It is small and verified both ways, but the conservative order is to let that rebuild go out on known-good code and merge this after. Your call — say the word and I'll merge.
Closes #49