-
-
Notifications
You must be signed in to change notification settings - Fork 868
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
Prefer Cloudflare IP header instead of X-Forwarded-For #905
Comments
I understand that the X-Forwarded-For handling is rudimentary. ntfy picks the rightmost address, since that is the most secure way to pick a trustworthy address. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For for details. To implement a proper X-Forwarded-For handling, we'd need to be able to configure a list of trustworthy proxies, e.g. Adding a vendor-specific header like |
Maybe X-Real-IP could be beneficial, since it's easier to overwrite without reverse proxies adding another IP to the right. e.g.: traefik |
Hello there, I'm sorry to revive such an old topic, but this issue is open, so I would like to add something to this, as I have multiple proxies there, so I have the same issue as @ChokunPlayZ
I would like to know where did you find that the rightmost address is the most secure way and the trustworthy address ? If I'm reading right here : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For#client
So, if we get the rightmost address, we always get the proxy, not the client, because "the leftmost IP address is the address of the originating client", right ? In that case, the
Thank you, have a nice day :) |
I just ran across this issue when I was deploying ntfy on Fly.io, which uses a customer header name like Cloudflare does. Right now with behind-proxy: true, I just get the Fly.io proxy IP, not the true client ip. So I think that there are 2 issues here: picking the incorrect XFF client IP from the list and the lack of support for multiple/alternate header names. It would be great if setting behind proxy to true, would also enable the option to set which header to look at for the client IP? (cloudflare/fly.io/aws/gcp all have customer header names to store client ip securely) Example Image to help visualize the possible problem: In this diagram, picking the right most IP, would always be the first proxy, but really we should be picking n-1 if there are more than 1 IPs in the list? |
I'm working on a PR for this, here is an example running in fly.io:
|
@pixitha I have the exact problem and your changes looks promising. |
I'm also looking forward @pixitha PR merged on master ! |
💡 Idea
I think there's not many configs like mine where the setup involves multiple reverse proxy (in my case NGINX and Cloudflare)
the current "behind proxy" setting cause issue because
NGINX attach 2 IP in the forwarded for header, ntfy always prefer the wrong one (the last one)
instead there's the Cloudflare's
Cf-Connecting-Ip
which is more accurate than theX-Forwarded-For
headerit would be great if this could be added
or an alternative fix, if there is multiple IP in the
X-Forwarded-For
header always prefer the public IP over private onesbecause in my case here's how the header looks like:
X-Forwarded-For: <mypublicip>, 172.17.0.1(docker)
💻 Target components
ntfy server
The text was updated successfully, but these errors were encountered: