Skip to content

fix(nginx): PATH_TRANSLATED only when there is path info to translate (#49) - #50

Merged
sylvesterdamgaard merged 1 commit into
mainfrom
fix/path-translated-fix-pathinfo
Oct 21, 2026
Merged

sylvesterdamgaard merged 1 commit into
mainfrom
fix/path-translated-fix-pathinfo

Conversation

@sylvesterdamgaard

Copy link
Copy Markdown
Contributor

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)

Reproduced against the published 8.5-bookworm before 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_TRANSLATED unconditionally as the script root plus $fastcgi_path_info. Checking what that path info actually is turned up the real shape of the bug:

/index.php/a/b  ->  pi=   (empty)

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, path info is empty on every request, and frameworks are reached through try_files as /index.php with a query string instead. PATH_TRANSLATED was therefore always 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 security.limit_extensions refuses it.

It predates the $realpath_root change 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 $fastcgi_path_info $cbox_path_translated {
    ""      "";
    default ${NGINX_SCRIPT_ROOT}$fastcgi_path_info;
}
...
fastcgi_param PATH_TRANSLATED $cbox_path_translated if_not_empty;

(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

published 8.5-bookworm this branch
test-nginx-template.sh 13 pass, 3 fail 16 pass, 0 fail

The new Test 6 mounts cgi.fix_pathinfo=0 and asserts three things: a 200, no has been denied in the php-fpm log, and that PATH_TRANSLATED is 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

@sylvesterdamgaard
sylvesterdamgaard force-pushed the fix/path-translated-fix-pathinfo branch from b16a108 to 1e3d981 Compare October 21, 2026 12:15
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
sylvesterdamgaard force-pushed the fix/path-translated-fix-pathinfo branch from 1e3d981 to f039353 Compare October 21, 2026 14:25
@sylvesterdamgaard
sylvesterdamgaard merged commit 4569054 into main Oct 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default template + cgi.fix_pathinfo=0: every PHP request is 403 because PATH_TRANSLATED is the web root

1 participant