Skip to content

RequestFactory: fix behavior behind proxy#81

Closed
grongor wants to merge 4 commits intonette:masterfrom
grongor:fix-proxy-https
Closed

RequestFactory: fix behavior behind proxy#81
grongor wants to merge 4 commits intonette:masterfrom
grongor:fix-proxy-https

Conversation

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

hrach commented Jan 31, 2016

👍

@Majkl578
Copy link
Copy Markdown
Contributor

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

@enumag
Copy link
Copy Markdown
Contributor

enumag commented Jan 31, 2016

Shouldn't we do something with HTTP_X_FORWARDED_PORT as well?

@Majkl578
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

grongor commented Jan 31, 2016

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

@JanTvrdik
Copy link
Copy Markdown
Contributor

Has anyone considered security implication?

@milo
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

How does Symfony and Zend handle this?

@enumag
Copy link
Copy Markdown
Contributor

enumag commented Feb 1, 2016

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

@JanTvrdik
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Majkl578 commented Feb 1, 2016

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

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

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

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

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