Skip to content

Correctly return IP address when using trusted header #16784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 6, 2025

Conversation

raicabogdan
Copy link
Contributor

@raicabogdan raicabogdan commented Jul 5, 2025

Hello!

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

Small description of change:

When using $this->request->getClientAddress(true); to extract IP address from X-Forwarded-For header it needs to select the first left side IP that is not private or reserved IP address.

Added support for users to add their own trustedProxies via method, accepts array of IPs or range of IPs.

$this->request->setTrustedProxies(['1.1.1.1']);

This will trigger an Exception("The forwarded proxy IP addresses are not trusted.") if users mess up their proxy setup.

Thanks

@niden niden merged commit e5e4b97 into phalcon:5.0.x Jul 6, 2025
42 checks passed
@niden
Copy link
Member

niden commented Jul 6, 2025

Thank you @raicabogdan !!

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.

2 participants