Skip to content

[HttpFoundation] Add PRIVATE_SUBNETS as a shortcut for private IP address ranges to Request::setTrustedProxies() #58154

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 1 commit into from
Sep 3, 2024

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Sep 3, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

Let's save some memory allocations and callbacks when we can.

Tweaks #33574 and #52924

@carsonbot carsonbot added this to the 7.2 milestone Sep 3, 2024
@nicolas-grekas nicolas-grekas force-pushed the hk-trusted-proxies branch 2 times, most recently from 9033e91 to dbe2679 Compare September 3, 2024 08:41
@nicolas-grekas nicolas-grekas changed the title [HttpFoundation] µ-optimize Request::setTrustedProxies() [HttpFoundation] Add PRIVATE_SUBNETS as a shortcut for private IP address ranges to Request::setTrustedProxies() Sep 3, 2024
Copy link
Member Author

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

While reading the code around, I realized that private_ranges for trusted proxies works only for explicit static configuration, aka env vars are not supported.
I fixed this by adding support for the PRIVATE_SUBNETS special value in setTrustedProxies, next to the already supported REMOTE_ADDR. Note the name and casing change, which look desired to me for consistency with REMOTE_ADDR. private_ranges is also supported for legacy reasons.

…ddress ranges to `Request::setTrustedProxies()`
}
}

if (false !== ($i = array_search('PRIVATE_SUBNETS', $proxies, true)) || false !== ($i = array_search('private_ranges', $proxies, true))) {
Copy link
Member

Choose a reason for hiding this comment

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

should private_ranges be deprecated in favor of PRIVATE_SUBNETS or no ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it's worth the trouble for the community.

@nicolas-grekas nicolas-grekas merged commit 4a7a68e into symfony:7.2 Sep 3, 2024
8 of 10 checks passed
@nicolas-grekas nicolas-grekas deleted the hk-trusted-proxies branch September 3, 2024 13:12
@fabpot fabpot mentioned this pull request Oct 27, 2024
@ValentinRgt
Copy link

Hi, this improvement be retroactive up to and including 6.4, 7.0 and 7.1?

@xabbuh
Copy link
Member

xabbuh commented Nov 12, 2024

New features are not backported to already released Symfony versions. You will have to upgrade to 7.2 to be able to use it.

@faizanakram99
Copy link
Contributor

While reading the code around, I realized that private_ranges for trusted proxies works only for explicit static configuration, aka env vars are not supported. I fixed this by adding support for the PRIVATE_SUBNETS special value in setTrustedProxies, next to the already supported REMOTE_ADDR. Note the name and casing change, which look desired to me for consistency with REMOTE_ADDR. private_ranges is also supported for legacy reasons.

@nicolas-grekas sorry for the ping, will PRIVATE_SUBNETS and REMOTE_ADDR work with the new env vars SYMFONY_TRUSTED_PROXIES?

@nicolas-grekas
Copy link
Member Author

They should yes.

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

Successfully merging this pull request may close these issues.

7 participants