Skip to content

Never let PHP-FPM guess the script to run - #72

Merged
kdambekalns merged 1 commit into
mainfrom
bugfix/fpm-no-script-guessing
Nov 13, 2026
Merged

kdambekalns merged 1 commit into
mainfrom
bugfix/fpm-no-script-guessing

Conversation

@kdambekalns

Copy link
Copy Markdown
Member

cgi.fix_pathinfo = 0 makes PHP-FPM run exactly the script named in SCRIPT_FILENAME. With the default of 1, it walked back a path like /upload.phar/x.php until it found an existing file and ran that one, uploaded files included.

security.limit_extensions = .php restricts PHP-FPM to .php files. The default also allows .phar, which is not on the upload blacklist of Flow. The status path used by the FPM exporter is answered before that check and keeps working.

cgi.fix_pathinfo = 0 makes PHP-FPM run exactly the script named in
SCRIPT_FILENAME. With the default of 1, it walked back a path like
/upload.phar/x.php until it found an existing file and ran that one,
uploaded files included.

security.limit_extensions = .php restricts PHP-FPM to .php files. The
default also allows .phar, which is not on the upload blacklist of Flow.
The status path used by the FPM exporter is answered before that check
and keeps working.
@kdambekalns kdambekalns self-assigned this Nov 13, 2026
@kdambekalns

Copy link
Copy Markdown
Member Author

Defense in depth for the unauthenticated upload in Neos/Flow (GHSA-7wrr-qcrp-4hhf): with PHP-FPM's defaults, a request like /_Resources/Persistent/<sha1>/poc.phar/x.php made PHP-FPM walk back the path and run the uploaded poc.phar. The web server side is fixed in flownative/docker-nginx#44; this closes it in PHP-FPM as well, for any web server in front of it.

  • cgi.fix_pathinfo = 0 in php.ini: PHP-FPM runs exactly the script named in SCRIPT_FILENAME and no longer walks back the path.
  • security.limit_extensions = .php in the pool: the default also allows .phar, which Flow's upload blocklist does not cover.

Tested with beach-php:8.5 and these two files:

  • Behind the unfixed nginx:5.1.0, poc.phar/x.php returns a 404 instead of running the upload. A real .php file below /_Resources/ is still run, that part needs the Nginx fix.
  • Under FPM, ini_get('cgi.fix_pathinfo') is 0, and other.php/x.php is no longer resolved to other.php ("No input file specified.").
  • The FPM exporter of beach-php still reads /php-fpm-status: the status path is answered before the extension check.
  • Together with the Nginx fix, its tests 4-php-fpm.sh and 7-php-resources.sh pass.

Requires SCRIPT_FILENAME to be exact, which Nginx sets as $document_root$fastcgi_script_name. A web server which relies on PHP guessing the script from a longer path stops working with this.

@kdambekalns kdambekalns left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kdambekalns
kdambekalns merged commit 82ed0d4 into main Nov 13, 2026
8 checks passed
@kdambekalns
kdambekalns deleted the bugfix/fpm-no-script-guessing branch November 13, 2026 14:04
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.

1 participant