Description
Hello, this is kind of awkward to ask as the use-case is quite specific, but at the same time it should be fairly self-contained.
Rationale
The core issue is using UnifiedPush in conjunction with a Matrix Client and Server. The Matrix Client will pass a push URL to the Matrix server. However, the Matrix spec mandates some endpoints for push servers: https://spec.matrix.org/v1.2/push-gateway-api/
Basically, the spec mandates the use of the /_matrix/push/v1/notify
path.
Therefore, one has to use an intermediate gateway before forwarding requests to ntfy. When users do not use their own, clients use default ones, which led to rate-limiting: #144
Benefit to users
Currently, users can host a gateway themselves through the common-proxies project, or some other rewrite proxy.
That's one more step for users, who might feel discouraged from doing so.
Including that gateway would increase privacy, for users of the public ntfy instance, but even more so for users who host their own homeserver and ntfy instance, as push messages do not need to travel through third-party gateways.
Needed changes
The set of features to support is relatively simple:
- Answer
With
GET /_matrix/push/v1/notify
HTTP/1.1 200 OK {"unifiedpush":{"gateway":"matrix"}}
- Handle Pushes on that endpoint. From the spec:
That should be forwarded to the topic in
POST /_matrix/push/v1/notify { "notification": { "content": { "body": "I'm floating in a most peculiar way.", "msgtype": "m.text" }, "counts": { "missed_calls": 1, "unread": 2 }, "devices": [ { "app_id": "org.matrix.matrixConsole.ios", "data": {}, "pushkey": "https://ntfy.sh/exampleTopicID?up=1", "pushkey_ts": 12345678, "tweaks": { "sound": "bing" } } ], "event_id": "$3957tyerfgewrf384", "prio": "high", "room_alias": "#exampleroom:matrix.org", "room_id": "!slw48wfj34rtnrf:example.com", "room_name": "Mission Control", "sender": "@exampleuser:matrix.org", "sender_display_name": "Major Tom", "type": "m.room.message" } }
json_body["notification"]["devices"][0]["pushkey"]
. In this case,exampleTopicID?up=1
. - Answer that push with:
Technically one could reject events for some topics that have never been listened to, or were deleted from the app, but that sounds a bit alien to the way ntfy works.
HTTP/1.1 200 OK {"rejected":[]}
That's all. This should only be necessary until the Matrix Spec Change 2970 lands to delete that requirement and allow arbitrary paths, so that's your call.
Impact assessment
One more thing to expect: on the public ntfy instance, FluffyChat's and schildichat's public gateways wouldn't be used anymore, so individual Matrix servers would be subjected to rate-limiting instead, probably Matrix.org, kde.org and mozilla.org, as they are the biggest I can think of right now.
On the other hand, it makes it easier to single out abusive Matrix homeservers without locking users out. Moreover, as more clients appear (Element will soon support UP), more gateways will appear.
It might also make it easier to rate-limit matrix separately while the MSC isn't merged.