Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.#26973
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
andrerom left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍 Seems to be same logic as inHttpCache::forward()
nicolas-grekas commentedApr 18, 2018
Can you add a test case please? |
kmadejski commentedApr 18, 2018
@nicolas-grekas sure, added in3b3d590 |
stof commentedApr 18, 2018
I see a big issue with this change: the local IP will stay trusted even after the end of handling this sub-request |
kmadejski commentedApr 18, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@stof you are right, local IP will be trusted for all subrequest within the master request, but I don't see any problem regarding that. Could you please explain or describe some use-case where it might be an issue? |
nicolas-grekas commentedApr 20, 2018
instead of trying to answer this question, would it be possible to restore the list to the previous state? |
kmadejski commentedApr 20, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@nicolas-grekas probably yes, but I think that it might be tricky. At first, it would be necessary to change this line:https://github.com/kmadejski/symfony/blob/3b3d5903109feadbdf4b40fb9f11929cdcc617ac/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php#L79 and store Secondly, we would have to set some flag because Of course, if you think that it's a good idea then I can try to do the change as described. |
andrerom commentedApr 20, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
When not using Symfony proxy (so Varnish, Fastly, Nginx cache, ..) naming ;) |
kmadejski commentedApr 26, 2018
@nicolas-grekas I see that you've changed the status of this PR, should I assume that you prefer the way of trying to restore the list of trusted proxies back to the previous state? |
nicolas-grekas commentedApr 29, 2018
The best would be to not alter the global state at all. |
andrerom commentedApr 29, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
true.
Alternatively, could we skip setting it? Tried to check blame a few rounds back for why ip is set to localhost in the first place, but seems to have been added when logic was moved in#6459. So not sure why it's done like that, but back then localhost seems to have been considered trusted:https://github.com/symfony/symfony/pull/6459/files#diff-5a6abcbb3081371c8f5e3b9434c1ec18R87 |
kmadejski commentedMay 14, 2018
@nicolas-grekas I did as you propose and it seems to be a pretty good solution which solves our issue. See changes in434a6a1. |
| $server['REMOTE_ADDR'] ='127.0.0.1'; | ||
| $trustedProxies = Request::getTrustedProxies(); | ||
| $server['REMOTE_ADDR'] =isset($trustedProxies[0]) ?$trustedProxies[0] :'127.0.0.1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should this rather pick the last/closest one?(unsure if it makes a difference tough)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not sure if there is any significant difference,@nicolas-grekas what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
just to be bullet proof:$trustedProxies ? reset($trustedProxies) : '127.0.0.1';
then the first LGTM
kmadejskiMay 15, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@nicolas-grekas changed in4fb6e03.
434a6a1 to954c024Compare954c024 to4fb6e03Comparekmadejski commentedMay 15, 2018
@nicolas-grekas JFYI: I've pushed again last commit with force to restart AppVeyor build which has been failed for the unknown reason previously. |
4fb6e03 to18f55feComparefabpot commentedMay 27, 2018
Thank you@kmadejski. |
…ineFragmentRenderer. (kmadejski)This PR was squashed before being merged into the 2.8 branch (closes#26973).Discussion----------[HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.| Q | A| ------------- | ---| Branch? | 2.7 and up| Bug fix? | improvement| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | ---| License | MIT| Doc PR | ---SubRequest used in `InlineFragmentRendered` explicitly sets `$server['REMOTE_ADDR']` to `127.0.0.1`. Therefore, it's required to configure `127.0.0.1` address in TRUSTED_PROXIES environment variable. Without that, `Request::isFromTrustedProxy()` will return false.The current behavior might be a little bit problematic, for instance, in case where images are rendered through subrequests. These might end-up with an incorrect schema in URL (`http` instead of `https`).Commits-------18f55fe [HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.
cybernet commentedJun 25, 2018
1.1.1.1 is actually a valid IP. is that a good ideea ? |
andrerom commentedJun 25, 2018
@cybernet that is the test code, or are you talking about something else? |
artursvonda commentedJul 12, 2018
Came across issue with this fix. We specify range (xxx.xxx.xxx.xxx/8) for trusted IPs which cause this solution to fail. Might not be the best practice, but it should not cause the request to fail. |
kmadejski commentedJul 13, 2018
@artursvonda it seems that you are right. As a workaround, for now, you can simply set @nicolas-grekas I think that dealing with getting the first valid IP within given CIDR is too much for If you agree then I will create a new PR with the proposed change. |
Uh oh!
There was an error while loading.Please reload this page.
SubRequest used in
InlineFragmentRenderedexplicitly sets$server['REMOTE_ADDR']to127.0.0.1. Therefore, it's required to configure127.0.0.1address in TRUSTED_PROXIES environment variable. Without that,Request::isFromTrustedProxy()will return false.The current behavior might be a little bit problematic, for instance, in case where images are rendered through subrequests. These might end-up with an incorrect schema in URL (
httpinstead ofhttps).