Skip to content

fastcgi: let configured env variables override request headers - #8358

Merged
francislavoie merged 1 commit into
caddyserver:masterfrom
dunglas:fastcgi-env-precedence
Nov 4, 2026
Merged

francislavoie merged 1 commit into
caddyserver:masterfrom
dunglas:fastcgi-env-precedence

Conversation

@dunglas

@dunglas dunglas commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Security fix. A client could override any HTTP_* variable set with the env subdirective of the FastCGI transport (and php_fastcgi).

buildEnv applied the configured variables first, then copied the request headers as HTTP_*, so a header with a matching name won. For instance:

php_fastcgi unix//run/php/php-fpm.sock {
	env HTTP_X_AUTH_USER {http.auth.user.id}
	env HTTP_X_FORWARDED_PROTO https
}

A client sending X-Auth-User: admin chose the user the PHP application saw, bypassing authentication done by Caddy, and X-Forwarded-Proto: http replaced the pinned scheme. Only HTTP_* names are affected, since only those can come from headers. The behavior dates back to the FastCGI transport's introduction in 026df7c5.

This applies the configured variables last, so the operator's value always wins. FrankenPHP already gives its prepared environment the last word: php/frankenphp@d25d295f

Behavior change: a configuration relying on a request header replacing an env value (a default the client may override) no longer works. Such a fallback can be written with a placeholder, e.g. env HTTP_X_FOO {http.request.header.X-Foo}.

This issue was not reported through a security advisory; it was found while porting FrankenPHP fixes to Caddy.

Assistance Disclosure

Claude Code (Claude Opus 5.5) found this issue while comparing the Caddy and FrankenPHP FastCGI environments, and wrote the fix and the test. I reviewed and tested the result.

@francislavoie francislavoie added the bug 🐞 Something isn't working label Nov 4, 2026
@francislavoie francislavoie added this to the v2.11.9 milestone Nov 4, 2026
@steadytao

Copy link
Copy Markdown
Member

Rebase does need to retain the Host-header guard. Plus this is GHSA-q34h-28rj-5hjm

buildEnv applied the env subdirective before copying request headers,
so a client header replaced any HTTP_* variable the operator set. With
"env HTTP_X_AUTH_USER {http.auth.user.id}", a client sending
"X-Auth-User: admin" chose the value the backend saw.

Apply the configured variables last, as FrankenPHP does for its
prepared environment.
@dunglas
dunglas force-pushed the fastcgi-env-precedence branch from 3032467 to cc66625 Compare November 4, 2026 20:29
@steadytao

Copy link
Copy Markdown
Member

@francislavoie will let you cut. Please use that GHSA rather than a new one 🫡

@francislavoie
francislavoie merged commit 70dca34 into caddyserver:master Nov 4, 2026
27 checks passed
francislavoie pushed a commit that referenced this pull request Nov 5, 2026
@github-actions github-actions Bot mentioned this pull request Nov 5, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants