-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
Remote Addr are not handled the same since akrabat/ip-address-middleware >= 2.5 #2351
Comments
So I guess your point is that, after those changes in Can you provide a failing test case that proves it? This is probably the best test to extend
|
OK, I will try to setup a full test environment to add the required test but I fail to setup it (cf discussion) |
Not sure how to implement the failing test case here because my issue is not about "failing redirection", it's more about the erroneous retrieved/stored remote IP address |
The redirection is based precisely in that IP address resolution. If you add a test case there where a set of headers should resolve a specific IP address that would cause the redirect to match, but it doesn't, then you would have demonstrated the bug. If the same test passes in an older version of Shlink, I will be able to investigate the difference. |
It seems my explanation was not enough accurate : the redirection works fine. I'll dig there |
Yes, that was clear, but the logic to resolve the remote IP is the same. The same IP that is resolved for an IP-based redirection will be the one logged as the visitor IP. The test you point out is a unit test, so you won't be able to mimic the whole user journey, including the logic in The test I pointed out is an E2E test which covers the whole journey, where you set the "input" received by Shlink, with the headers your proxy is supposedly setting. With those headers your expectation is that it will resolve the visitor IP address, not the proxy one, and in that case, the visitor should be redirected to If the proxy IP address is resolved, it will redirect somewhere else, making the test fail. |
Thanks @acelaya for your guidance. |
You don't really need to check that. In the test I pointed out, you can just verify that the visitor is redirected to In the loop right before it, that test verifies that's in fact the case when that IP address is set in any of the headers that Akrabat's middleware inspects. Now, you are saying you have a reverse proxy which is setting those headers with the visitor's IP address, but you still end up with a different one resolved. If you can manage to put together a new test case there, right under the loop, where you set the headers as your proxy is setting them, and the redirect URL ends up being something other than I'm assuming what that test is missing and you are reporting here is a case in which |
Just for context. I'm requesting all this, because I'm not completely sure your assumption here is correct.
I have been using Shlink with a reverse proxy for quite some time and IP addresses have always been resolved properly (including with latest version). Also, it seems like this library already assumes the value in So the first thing is demonstrating there's in fact a bug and it's not a mis-configuration in the proxy or an incorrect expectation. |
There's some documentation on how to use a reverse proxy with Shlink here https://shlink.io/documentation/advanced/exposing-through-reverse-proxy/ Make sure you have set everything as described there. The problem may also be specific for traefik. |
Well, it WAS working fine before akrabat/ip-address-middleware#51 Its change requires now to configure TrustedProxies setting to make it to ignore the intermediary recognized IP. Here is my case :
With the recent akrabat/ip-address-middleware, Shlink gets REMOTE_ADDR as logged IP from ip-address-middleware |
Perfect! That's the scenario you need to reproduce in the E2E test I referenced. |
Yes. But I don't know how to test the IP returned from the middleware ? |
OK. My scenario is more tricky (
The middleware catches |
If you see the code snippet I referenced from Akrabat's code, you'll notice the value in However you seem to have two proxies, traerfik, then nginx. I wonder if each one is appending their IP to the forwarded header, making the actual client IP the third from the right. Have you tried if it works with just one proxy? Another option could be simply changing the order of the headers here https://github.com/shlinkio/shlink/blob/develop/config/autoload/ip-address.global.php#L18. It was set a bit randomly. |
I have two proxies and that part is not in my hand :-/ I guess my fix is better than changing the headers order in ip-address.global.php#L18. |
Again, I'm just trying to understand the problem. Stop being so defensive or I'll simply close this and move on with my life. I didn't say "you have to remove one proxy", I just asked if it works with one proxy, with the only intention to try to prove a hypothesis. Since this issue has been opened, you have been trying to enforce what you think is the solution, without a single prove that this is going to actually make a difference. You didn't provide a single reproduction, or provided a failing test to prove nothing. |
I am sorry if I look defensive. It was not intended. About the PR, it was a new one with the test as a commit added : 28e30ff And to answer your question : I really try to fit your expectation to explain which problem I encounter |
@acelaya , I apologize, my PR was not the right way to share my proposal. |
I tried this test case
With :
|
So, I took the time to put together a reproduction and see what was exactly going on and if there was some "easy" way to get this fixed: #2357 This basically proves that the library expects the list of trusted proxies to be set now, otherwise the wrong IP is resolved when using more than 1 proxy. However, it's a bit inconvenient that the way to fix this regression requires users to set-up their trusted proxies. People may not really know what that means, or may even have updated Shlink without noticing about the fix, and have a broken instance for some time because they didn't set their trusted proxies. I think the right course of action here is to try to put together a workaround in Shlink, that ensures the previous behavior is preserved, and release v4.4.3 with that fix. Then, v4.5.0 can introduce support to set your own trusted proxies, and disable the workaround if they have been provided. This would be treated as a feature. Then maybe v5.0.0 can drop the workaround entirely, but I'll make that decision when the time comes. @ymage, on a side note, in future, make sure to not try to rush things. It's super important that there's a common understanding, and you should not assume project maintainers are up to speed with you when you are reporting an issue. You should absolutely never open an unsolicited PR in a project, unless it's something blatantly obvious, but even in that case, it may be obvious only for you. Always start by opening an issue, as detailed as possible, explaining the problem, your expectations, and what ended up happening. Once the problem to be solved has been stated and everyone agrees and understands it, conversations on how to fix it can start, and that's when you can volunteer to provide the PR if you wish. |
Thank you @acelaya for your patience and for the time you spent with my issue. I think I was a bit lost because some others projects react differently and ask for a PR proposal for each bug you report. Regards. |
Shlink version
version >=4.4.0
PHP version
8.3
How do you serve Shlink
Self-hosted RoadRunner
Database engine
MySQL
Database version
11.6
Current behavior
Shlink run in docker container which is reverse-proxified with traefik/nginx.
X-Real-IP and X-Forwarded-For are both correctly set with the client address and REMOTE_ADDR is the proxy address.
When the visit is tracked, only the REMOTE_ADDR is registered, which is a 172.16.0.0/12 non routed IP address since akrabat/ip-address-middleware >= 2.5 (akrabat/ip-address-middleware#51)
Expected behavior
Shlink should allow to set trusted_proxies to akrabat/ip-address-middleware in order to get it to ignore them and retrieve the X-Real-IP header IP address
Minimum steps to reproduce
Run a shlink container behind a reverse-proxy with a private class IP address which can't override REMOTE_ADDR.
The text was updated successfully, but these errors were encountered: