-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Ignore Cloudflare Priority header #851
Conversation
With these changes, If the web request contains the new Priority header (RFC 9218), The server will ignore it and continue searching for other headers or query parameters.
+1 for this as it would enable me to use NTFY with Uptime Kuma behind cloudflare. It inherently sets the priority of alerts which don’t come through on iOS properly. |
server/util.go
Outdated
} | ||
return decoded | ||
return cloudflarePriorityIgnore(decoded) |
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.
This function is used not just by the priority, but also by other headers. So one could not use a notification title u=hello
anymore. Why not keep this logic only in the parsePrio function like it was before?
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.
Sorry sorry sorry 🤯
Sorry for the error, I was so focussed trying to solve specifically the problem with the CF priority header that I didn't think about the possibility of another header having a value starting with u=
, even knowing this function is used with with all headers.
Why not keep this logic only in the parsePrio function like it was before?
You mean this?
Lines 163 to 170 in 2305ebc
default: | |
// Ignore new HTTP Priority header (see https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-priority) | |
// Cloudflare adds this to requests when forwarding to the backend (ntfy), so we just ignore it. | |
if strings.HasPrefix(p, "u=") { | |
return 3, nil | |
} | |
return 0, errInvalidPriority | |
} |
Well, if you're referring to that part of the code, it's because at that point of execution, we have already parsed the headers and query parameters. If we find any priority header (priority, x-priority, prio, p), the others will not even be read, including the query parameters.
For instance, if a user is using the web interface to send a notification with priority 5, the request will include a query string like this:
?title=titulodeprueba&priority=5
If we send the request directly to the server, all will be ok, it will work, but if the server is behind CF, it will (in the majority of cases) have the priority:"u=*"
header, causing the priority set in the query parameter to be ignored.
Nevertheless, I am fixing this issue in my next commit.
Thank you for all your comments.
😉
- Now, only if the header being processed is the "priority" header, the cloudflarePriorityIgnore function is called, solving problems with that header injected by CF - we make the check with regex now.
Refined and merged in #895 - Sorry it took so long. Thank you for fixing this! |
Refine handling of HTTP Priority header
Part of: #351, #353, #461, ...
This PR improves the handling of the new HTTP Priority header (RFC 9218) commonly affecting ntfy instances running behind Cloudflare.
Changes:
A working instance with this fix can be tested Here
😀