Skip to content

Conversation

grongor
Copy link
Contributor

@grongor 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

@hrach
Copy link
Contributor

hrach commented Jan 31, 2016

👍

@Majkl578
Copy link
Contributor

👍 It just took almost 2 years to implement such simple thing. 😭

@enumag
Copy link
Contributor

enumag commented Jan 31, 2016

Shouldn't we do something with HTTP_X_FORWARDED_PORT as well?

@Majkl578
Copy link
Contributor

@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/?

@grongor
Copy link
Contributor Author

grongor commented Jan 31, 2016

What do you think about that master...grongor:fix-proxy-port ?

@JanTvrdik
Copy link
Contributor

Has anyone considered security implication?

@milo
Copy link
Member

milo commented Feb 1, 2016

I was thinking about security in this way. The attacker can fake the HTTP_X_FORWARDED_PROTO header content. There are only two result states: http or https. These states affect the router behaviour (automatic redirections secured vs. no-flag) and URL (http:// vs https://).

Switch from http -> https: it can lead to application problem, but not security imho
Switch from https -> http: the header can be faked only outside of an SSL/TLS session, so somewhere after the proxy. But in that case you cannot trust the proxy and security does not matter.

Any other point of view?

@grongor
Copy link
Contributor Author

grongor commented Feb 1, 2016

@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.

@JanTvrdik
Copy link
Contributor

How does Symfony and Zend handle this?

@enumag
Copy link
Contributor

enumag commented Feb 1, 2016

Symfony checks if the proxy is trusted and if so it uses these headers instead.

@JanTvrdik
Copy link
Contributor

@enumag That's what I thought.

The current trusted proxy check should be extracted and used for HTTP_X_FORWARDED_PROTO as well.

@enumag
Copy link
Contributor

enumag commented Feb 1, 2016

@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.

@Majkl578
Copy link
Contributor

Majkl578 commented Feb 1, 2016

@grongor
Copy link
Contributor Author

grongor commented Feb 1, 2016

I added the HTTP_X_FORWARDED_PORT handling and taken the $proxies into considerations when detecting scheme and port. Is that acceptable?

@grongor grongor changed the title RequestFactory: detect schema behind proxy correctly RequestFactory: fix behavior behind proxy Feb 1, 2016
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

@JanTvrdik
Copy link
Contributor

Should I point out all the issues or will @dg rewrite it anyway?

@grongor
Copy link
Contributor Author

grongor commented Feb 2, 2016

Please point out the issues, otherwise I won't learn what's wrong with this contribution :)

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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. :)

@JanTvrdik
Copy link
Contributor

Some more thoughts – I would try to remove the getSchema method entirely (inline in as it was before) and move the proxy-specific logic to where it was before.

@JanTvrdik
Copy link
Contributor

One of reasons to keep the proxy logic together is #20

Copy link
Contributor

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.
@grongor
Copy link
Contributor Author

grongor commented Feb 2, 2016

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 ;-)

Copy link
Contributor

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

Copy link
Contributor Author

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 ...

Copy link
Contributor

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!

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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).

@dg dg closed this in 805ff25 Feb 7, 2016
@dg
Copy link
Member

dg commented Feb 7, 2016

@grongor thanks, merged dadd667

dg pushed a commit that referenced this pull request Feb 8, 2016
dg pushed a commit that referenced this pull request Mar 30, 2016
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.

7 participants