Repository navigation
fix!: stop trusting client-supplied IP headers and GET _method, harden health endpoints - #11
Merged
Merged
Conversation
…n health endpoints
- Client IP is REMOTE_ADDR by default. X-Forwarded-For is read only when
REMOTE_ADDR is listed in the new trusted_proxies option (IPs and CIDR
ranges), resolved right to left skipping trusted proxies. Client-IP is
never read, invalid entries are rejected and IPv4-mapped IPv6 is handled.
- The _method override requires a real POST and reads only the POST
parameters (PSR-7 parsed body, otherwise $_POST).
- HealthRegistry accepts numeric check names, HealthEndpoints keeps the
body for invalid UTF-8 details and encodes an empty checks map as {}.
- Document the new behaviour and update the changelog.
…e PSR-7 request data - A non-array trusted_proxies option now throws instead of silently trusting nothing, and a missing key no longer warns in subclasses that redefine $configs. - ip() allow-list entries are compared with the client address in canonical form, so IPv4-mapped and upper-case or long IPv6 entries match. - With a PSR-7 server request, RequestContext reads server parameters from getServerParams() when present and the method override only from the parsed body (arrays and objects), never from $_POST. - Clarify the upgrade notes (open ip() group behind a same-host proxy), the right-to-left chain wording and the exception list.
Server parameters of some runtimes (ReactPHP) carry no HTTP_* entries, so a trusted proxy's X-Forwarded-For header was never seen and every visitor appeared as the proxy address. With a PSR-7 server request the header lines are now read through getHeader() (joined in order), falling back to HTTP_X_FORWARDED_FOR. Add a regression matrix over superglobal, FPM-style, ReactPHP-style, empty-bag and header-less PSR-7 requests for the client address and the _method override, narrow the trusted_proxies example to proxy addresses and list the new public API in the changelog.
Read the PSR-7 X-Forwarded-For header only when RequestContext derives the server parameters from the request itself; explicitly injected server parameters are used as given.
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.
What
REMOTE_ADDRby default.X-Forwarded-Foris read only whenREMOTE_ADDRis in the newtrusted_proxiesoption (IPs and CIDR ranges, IPv4/IPv6); the chain is resolved right to left, skipping trusted proxies.Client-IPis never read. Entries that are not IP addresses yield no client address; IPv4-mapped IPv6 is normalised; an invalidtrusted_proxiesentry throwsInvalidArgumentException._methodoverride works only on a realPOSTand only from the POST parameters (PSR-7 parsed body, otherwise$_POST);$_REQUESTand the query string are no longer read.TypeError; invalid UTF-8 in a check detail no longer produces an empty 503 body; an emptychecksmap is encoded as{}.port()still depends on theHostheader; unchanged in code, documented.CHANGELOG.md(Unreleased, breaking items and upgrade notes) updated. Two stale PHPStan baseline entries forRequestContextremoved.Breaking
Behind a reverse proxy, set
trusted_proxies; otherwiseip()groups see the proxy's address. Clients that sent_methodvia GET or the query string must use a POST body.Testing
composer validate --strict,php-cs-fixer fix --dry-run --diff,phpstan analyse,phpunit(207 tests) andwiki-sync.sh --check docspass locally. New regression tests fail on the previous code.