mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 08:26:00 +02:00
[GH-ISSUE #905] Prefer Cloudflare IP header instead of X-Forwarded-For #639
Labels
No labels
ai-generated
android-app
android-app
android-app
🪲 bug
build
build
dependencies
docs
enhancement
enhancement
🔥 HOT
in-progress 🏃
ios
prio:low
prio:low
pull-request
question
🔒 security
server
server
unified-push
web-app
website
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ntfy#639
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ChokunPlayZ on GitHub (Oct 1, 2023).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/905
💡 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-Ipwhich is more accurate than theX-Forwarded-Forheaderit would be great if this could be added
or an alternative fix, if there is multiple IP in the
X-Forwarded-Forheader 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
@binwiederhier commented on GitHub (Nov 18, 2023):
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.
proxies: 172.17.0.1. These proxies would be ignored in the selection of the IP address.Adding a vendor-specific header like
Cf-Connecting-Ipdoesn't seem like a great idea, IMHO.@hipur commented on GitHub (Nov 8, 2024):
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
@ojio-san commented on GitHub (Dec 29, 2024):
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
@binwiederhier
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
This means that the rightmost IP address is the IP address of the most recent proxy and the leftmost IP address is the address of the originating clientSo, 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
visitor_ipis always the last proxy IP and not the client IP; I don't think that's the expected behaviour.Thank you, have a nice day :)
@pixitha commented on GitHub (Jan 2, 2025):
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)
OR
if you could configured a trusted proxy subnet or IP so that looking at the XFF IP list, you could know to ignore the far right address if its "internal" (This is what Apache Tomcat does)
Example Image to help visualize the possible problem:

ref: https://www.stackhawk.com/blog/do-you-trust-your-x-forwarded-for-header/
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?
@pixitha commented on GitHub (Jan 6, 2025):
I'm working on a PR for this, here is an example running in fly.io:
@sr7142x commented on GitHub (Jan 21, 2025):
@pixitha I have the exact problem and your changes looks promising.
@ojio-san commented on GitHub (Jan 29, 2025):
I'm also looking forward @pixitha PR merged on master !
@binwiederhier : is it possible to check https://github.com/binwiederhier/ntfy/pull/1252 ?
Thank you :)
@ojio-san commented on GitHub (Nov 20, 2025):
It's a bit late, but it's working fine for me with this
Thank you
@binwiederhier commented on GitHub (Nov 20, 2025):
Yes, this has been released a while ago. https://docs.ntfy.sh/config/#behind-a-proxy-tls-etc