-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
Fixes wrong IP address when using a reverse proxy #2236
Conversation
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.
Changes look good to me, now we wait for at least one more core dev to approve before we merge.
Overall looks good, left a few comments. Also, I'm not seeing any failing test cases (re: PR description), so we're good on that front :D |
I think the failed test cases had to do with my environment as I've written in the description. |
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 am afraid this is not ready for production yet:
- The
X-Forwarded-For
header can contain multiple IP addresses, e.g. in setups with multiple reverse proxies / load balancers. - If I am not mistaken, the headers need to be explicitly marked as trusted. Right now, if I read the code correctly, a malicious user could provide an IP address in
X-ProxyUser-IP
and we would incorrectly use this to overwrite the value from the server inX-Forwarded-For
. - This needs tests!
Beyond that, some code-specific feedback:
- I personally, would have been fine with adding this at the highest level of middlewares, i.e. in
InstalledApp
. - If we don't add any special error handling (e.g. a message or a status code), there is no need to add
KnownError
to the new exception class.
It might be worth using a library for this, if we find a good one for PSR-7. Otherwise, a port of Symfony's "trusted proxies" concept may be an option.
@askvortsov1 @tankerkiller125 Can I ask you to follow up on this, either with a revert, an issue for beta.14 or a PR that fixes these problems? A combination of these may be helpful, too. 😜
@franzliedke the problem I had with putting the middleware at the highest level is that the extender for middleware does not have the ability to overwrite middleware in IntalledApp I don't think. |
I don't see a big need for extensibility here, personally. It's security-relevant and the middleware can be disabled by changing the config. But honestly, that is the least of my concerns, just an implementation detail. |
Considering our backlog for beta 14, it might be best to revert it, and encourage @x7airworker to open a new PR that takes into account Franz's comments above. I don't want to make this something that might hold back the release. |
I agree @askvortsov1 if you want to rollback I think that's a good decision at the moment. I would but I'm at work :( |
This reverts commit 451a557.
…2242) This reverts commit 451a557 pending further discussion of #2236 (comment)
Changes proposed in this pull request:
Two new optional config values:
reverse_proxy.enabled
will enable ip address finding of a user using a reverse proxy at\Http\Middleware\ProxyAddress
reverse_proxy.allowed
controls the allowed reverse proxy IPs used for checking.Changed
Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
to$request->getAttribute('ipAddress');
to use the new attribute in the codebase.Reviewers should focus on:
\Flarum\Foundation\InstalledApp
and im unsure if this is the correct/best position.Confirmed
Required changes: