[10.x] Update TrustProxies
to rely on $headers
if properly set
#47844
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.
Right now the
match
statement inTrustProxies::getTrustedHeaderNames
only handles single headers. This means that if you setTrustProxies::$headers
to something likeRequest::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT
it will ignore that and instead fall back on the default (which is to trust all headers).There is a test for this, but the test was using the default values for
TrustProxies::$headers
, so it was passing because of the fallback, not because the it was working as expected.The solution is to only rely on the
match()
statement ifTrustProxies::$headers
is not an integer. That way if someone has configured it correctly using bitmasks, it will respect the configuration, and only use string matching if the headers attribute is misconfigured.This is a security issue and should be merged asap. Currently, anyone with custom
TrustProxies
headers that don't match the middleware defaults or the ELB/Traefik presets are impacted by this issue.Until this PR is merged, anyone who is impacted can temporarily patch the bug by replacing the
getTrustedHeaderNames
method inTrustProxies
with the following (this assumes thatTrustProxies::$headers
is properly set using theRequest::HEADER_X_*
constants):