Skip to content

[13.x] Fix TrustProxies at:* when multiple proxies are used#60726

Open
mattford wants to merge 1 commit into
laravel:13.xfrom
mattford:bug/60725
Open

[13.x] Fix TrustProxies at:* when multiple proxies are used#60726
mattford wants to merge 1 commit into
laravel:13.xfrom
mattford:bug/60725

Conversation

@mattford

Copy link
Copy Markdown

Update TrustProxies to add all intermediate IP addresses to trusted list

Currently, only the remote address is trusted when using TrustProxies:*. If there are multiple proxies this results in the most recent proxy being treated as the original client IP.

There are tests for this however they were incorrect, treating the last IP in the X-Forwarded-For or Forwarded header list as the original, however it should be the first one (https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For)

Symfony doesn't support wildcards in trusted proxies so to get around this, this patch gathers all IP addresses in the forwarded for or forwarded header + the remote address, and adds them all to the trusted list

Resolves #60725

Update TrustProxies to add all intermediate IP addresses to trusted list
@github-actions

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@mattford mattford marked this pull request as ready for review July 10, 2026 10:43
@mattford mattford changed the title Correct ordering of forwarded IP addresses in test [13.x] Fix TrustProxies at:* when multiple proxies are used Jul 10, 2026
Comment on lines +123 to +127
$trustedIps = collect($this->gatherProxyIpAddresses($request))
->concat([$request->server->get('REMOTE_ADDR')])
->unique()
->values()
->all();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem efficient at all, especially considering this is a middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TrustProxies with at: * does not work correctly when request has passed through multiple proxies

2 participants