Fix ConflictingHeadersException on generic reverse-proxy hosting#16
Open
back-2-95 wants to merge 1 commit into
Open
Fix ConflictingHeadersException on generic reverse-proxy hosting#16back-2-95 wants to merge 1 commit into
back-2-95 wants to merge 1 commit into
Conversation
The auto-detect branch trusted both the "Forwarded" header and the individual "X-Forwarded-*" headers at once, which Symfony explicitly disallows. Proxies like Traefik only send X-Forwarded-*, so any client sending its own "Forwarded" header straight through the proxy causes Request::getTrustedValues() to throw when the two disagree. Drop HEADER_FORWARDED from the trusted set to match what these proxies actually send.
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.
Summary
Reader.php(used when no known hosting system is detected, e.g. our own Traefik-fronted UpCloud hosts),reverse_proxy_trusted_headerstrusted bothRequest::HEADER_FORWARDEDand the individualRequest::HEADER_X_FORWARDED_*headers at the same time.Request::getTrustedValues()throwsConflictingHeadersExceptionwhenever a request carries both a trustedForwardedheader and a trustedX-Forwarded-*header whose derived values disagree.X-Forwarded-*headers, neverForwarded. Since Traefik doesn't restrict which client IPs it trusts to set forwarding headers (noforwardedHeaders.trustedIPs), any external client can send its ownForwardedheader straight through. Because Drupal trusted both header types, a mismatching client-suppliedForwardedheader crashed the request.ConflictingHeadersExceptionon essentially every request from clients sending aForwardedheader.Fix
Drop
Request::HEADER_FORWARDEDfrom the trusted header bitmask in the auto-detect branch, since it's never actually the header format these proxies use.Test plan
php -l src/Reader.phpmake test)