Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Process] Stop leaking CGI/FastCGI request-context vars to subprocesses#64347

Merged
nicolas-grekas merged 1 commit into
symfony:6.4symfony/symfony:6.4from
nicolas-grekas:process-strip-cgi-env-varsnicolas-grekas/symfony:process-strip-cgi-env-varsCopy head branch name to clipboard
May 23, 2026
Merged

[Process] Stop leaking CGI/FastCGI request-context vars to subprocesses#64347
nicolas-grekas merged 1 commit into
symfony:6.4symfony/symfony:6.4from
nicolas-grekas:process-strip-cgi-env-varsnicolas-grekas/symfony:process-strip-cgi-env-varsCopy head branch name to clipboard

Conversation

@nicolas-grekas
Copy link
Copy Markdown
Member

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #64327
License MIT

Some SAPIs (notably PHP-FPM and CGI, via cgi_php_import_environment_variables) expose request-scoped CGI/FastCGI vars (QUERY_STRING, HTTP_*, REQUEST_*, etc.) through $_SERVER, $_ENV and getenv(), even though they aren't real OS env vars. Process::getDefaultEnv() then propagated them to subprocesses, where they would confuse runtimes: e.g. $_SERVER['QUERY_STRING'] leaking into a bin/console subprocess made SymfonyRuntime treat it as a web request, drop argv processing and strip the command name and options.

This PR strips the standard CGI variable names (RFC 3875 + PHP/FPM additions) and the HTTP_/ORIG_/REDIRECT_ prefixes from the default env. Custom fastcgi_param entries and user-set $_ENV vars are unaffected.

A companion PR for Runtime against 5.4 (#64346) makes SymfonyRuntime trust argv on CLI-like SAPIs as defense in depth.

Some SAPIs (notably PHP-FPM and CGI, via cgi_php_import_environment_variables)
expose request-scoped CGI/FastCGI vars (QUERY_STRING, HTTP_*, REQUEST_*, etc.)
through $_SERVER, $_ENV and getenv(), even though they aren't real OS env
vars. Process::getDefaultEnv() then propagated them to subprocesses, where
they would confuse runtimes: e.g. $_SERVER['QUERY_STRING'] leaking into a
bin/console subprocess made SymfonyRuntime treat it as a web request, drop
argv processing and strip the command name and options.

Strip the standard CGI variable names (RFC 3875 + PHP/FPM additions) and
the HTTP_/ORIG_/REDIRECT_ prefixes from the default env. Custom
fastcgi_param entries and user-set $_ENV vars are unaffected.
@nicolas-grekas nicolas-grekas force-pushed the process-strip-cgi-env-vars branch from e9534c6 to 020da5f Compare May 23, 2026 13:47
nicolas-grekas added a commit that referenced this pull request May 23, 2026
…rgs (nicolas-grekas)

This PR was merged into the 5.4 branch.

Discussion
----------

[Runtime] Trust argv on CLI-like SAPIs to fix subprocess args

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #64327
| License       | MIT

`$_SERVER['QUERY_STRING']` can leak into CLI subprocesses (notably when spawned from PHP-FPM, where the SAPI exposes FastCGI request-context vars through `getenv()` and `$_ENV` that then propagate via `Process`). The `QUERY_STRING` gate added for CVE-2024-50340 was therefore tripped in CLI subprocesses, dropping argv processing and stripping command names and options.

This PR trusts argv when `PHP_SAPI` is `cli`/`phpdbg`/`embed`: in CLI SAPIs argv is the real OS argv, never derived from `QUERY_STRING` (that's a web-SAPI-only behavior of `register_argc_argv`), so the gate is unnecessary there. The gate still applies on actual web SAPIs.

The two phpt tests that simulated the CVE attack from cli SAPI by mocking `$_SERVER` no longer represent a real attack vector under this model and are removed; the protection on real web SAPIs is unchanged.

A companion PR for `Process` against 6.4 (#64347) plugs the actual env leak as defense in depth.

Commits
-------

b2a338e [Runtime] Trust argv on CLI-like SAPIs to fix subprocess args
@nicolas-grekas nicolas-grekas merged commit 1d0723b into symfony:6.4 May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.