-
-
Notifications
You must be signed in to change notification settings - Fork 88
RequestFactory: fix behavior behind proxy #81
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
Conversation
grongor
commented
Jan 31, 2016
- bugfix
- issues - https + nginx proxy #4
- documentation - not needed
- BC break - may break some edge-case server proxies, most servers should stay intact
👍 |
👍 It just took almost 2 years to implement such simple thing. 😭 |
Shouldn't we do something with HTTP_X_FORWARDED_PORT as well? |
@enumag I was thinking exactly the same thing. How will Nette\Http\Url and/or routers work now when https mode is enabled over port 80? Wouldn't this generate nonsense like https://example.com:80/? |
What do you think about that master...grongor:fix-proxy-port ? |
Has anyone considered security implication? |
I was thinking about security in this way. The attacker can fake the Switch from Any other point of view? |
@JanTvrdik @milo Yes, I was thinking about it the same way. If the proxy is able to mess with your headers then you can't trust it anyway - no matter what we put at server side. There might be a problem with misconfiguration of the proxy but we can't really predict that. |
How does Symfony and Zend handle this? |
@enumag That's what I thought. The current trusted proxy check should be extracted and used for HTTP_X_FORWARDED_PROTO as well. |
@JanTvrdik Well it seems that by default the trustedProxies array in symfony is empty. But I'm not sure if there are some added automatically elsewhere. |
Symfony configures trusted proxies using kernel parameter: https://github.com/symfony/symfony/blob/83b53f4a89fa2f436ba0f8d88b0714aa534b2cd2/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php#L53 |
I added the |
src/Http/RequestFactory.php
Outdated
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'd put these outside of the foreach.
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.
Well, I can do that but I will have to copy the $usingTrustedProxy === true
condition ... do you think that removing one indention is worth it?
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 just think that any logic that only happens once should be outside of a loop if possible.
Also you can skip the === true
part.
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.
That makes sense, alright :) Yeah I will, I was just trying to be clear for the purpose of comment :)
Should I point out all the issues or will @dg rewrite it anyway? |
Please point out the issues, otherwise I won't learn what's wrong with this contribution :) |
src/Http/RequestFactory.php
Outdated
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.
There should be space after (bool)
, the count
call should be removed.
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.
****, you are right, I again blindly copied the code from @Majkl578 :D
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.
Sorry, count was a leftover, originally I had it like count(...) !== 0;
but then I changed my mind. :)
Some more thoughts – I would try to remove the |
One of reasons to keep the proxy logic together is #20 |
src/Http/RequestFactory.php
Outdated
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.
There should be two empty lines between two methods.
Correctly detect scheme and port if the server is behind a trusted proxy.
Thanks @JanTvrdik - I updated the code according to you suggestions and it's much easier :-) I also got rid of the "smart" scheme/port alignment. I hope I didn't miss something again ;-) |
src/Http/RequestFactory.php
Outdated
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.
do a space after the casting
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 tried so hard ... it's hard to notice these things when all other projects I'm working on use exactly opposite standards ...
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.
still, you did an awesome work! thank you!
src/Http/RequestFactory.php
Outdated
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.
This $remoteAddr !== NULL
is redundant, it should go outside the callback.
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.
Why change isset
to !empty
? Isset worked OK for years, is faster to execute, can be in PHP 7 rewritten with ??
and does not consider 0
as empty.
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.
Because I don't think that having an empty host or address makes sense. Is that wrong assumption?
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.
Having invalid value like '0' or '1' here makes no sense either and it's not checked anyway, maybe it could be.
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.
That's true but I guess that we don't want to check webserver settings there. I just though that this is a little bit better (to ignore empty header rather the somehow try to use it).