[relay] Wake-up: a push endpoint per mailbox, and a constant wake to it when a blob arrives #20
Reference in New Issue
Block a user
Delete Branch "feature/wake-up"
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?
Wake-up: a push endpoint per mailbox, and a constant wake to it when a blob arrives. For Amicitia F25b (a closed Android app hears that something arrived, through UnifiedPush). Analysis:
.agents/features/wake-up.md. Protocol change, recorded with its date indocs/PROTOCOL.md§5, §6, §7 and §8.PUT /v0/mailboxes/{id}/push {endpoint}/DELETE …/push, with the fetch token. The endpoint:https://, a host, no user info, no fragment, at most 1 000 bytes;http://only to loopback, and only on a relay started with--push-loopback(tests).waketo the endpoint, in the background, at most once a minute per mailbox (remembered in memory only), with no mailbox id, no size, no time. It connects only to global addresses (its own resolver drops every non-global one, IPv4-mapped/NAT64/6to4 forms included), follows no redirect, gives up after 10 s, has at most 16 wakes on their way. A 404/410 from the push server removes the endpoint, unless a newer one was set since.pushrow made concrete:push (mailbox_id, endpoint).Transport::set_push,Client::inboxes()(each contact's inbox and each open welcome mailbox),Client::set_push(mailbox, endpoint). One endpoint per mailbox, so the relay cannot link a person's mailboxes by endpoint.services.tabellarius.wake(default on, decided by default); the systemd sandbox allowed localhost only, which would have dropped every wake silently. With it on, every non-global range stays denied by systemd as well.ureq3 with rustls (ring, Mozilla roots), from the local cargo cache — the same crate Amicitia already uses for its relay calls.Adversarial self-review — wake-up
Evidence
cargo test --workspace-D warnings(workspace, all targets),cargo fmt --checkscripts/check-deps.shscripts/test-hooks.shmutate_wake.py)Debugshowing the capability URL; welcome mailboxes not listed;set_pushon someone else's mailboxWhat the wake carries (tested)
A canary blob is posted; the push server sees only the endpoint's own path,
TTL,Urgency,Content-Type, ureq'sUser-Agent, and the bodywake. The test searches the whole request for the mailbox id, both tokens, the blob's hash and the canary: none is there, and noAuthorizationheader.Findings
W1–W7 are on their lines.
Not verified
nix flake checkandtest.nixneed Nix, not on this machine; the VM test is unrun since F23). In particular, that nscd resolves for the sandboxed relay, and thatring's build inside the Nix sandbox is reproducible.Verdict
Merging.
@@ -526,0 +526,4 @@/// The mailboxes this client fetches: each contact's inbox (a blocked contact's too, which/// nothing reaches) and each open invite's welcome mailbox. For wake-ups (`PROTOCOL.md` §6): an/// app registers one push endpoint per mailbox, so the relay cannot link them by endpoint.pub fn inboxes(&self) -> Vec<MailboxId> {W6 — privacy (linking). One endpoint per mailbox, so the relay cannot link a person's mailboxes by a shared endpoint; but it sees each endpoint's host. On ntfy.sh that says little; on a person's own push server it links all their mailboxes, and timing already partly does (CLAUDE.md §4, Metadata by timing). Amicitia must say so where wake-ups are turned on. A blocked contact's inbox stays listed, so turning wake-ups off clears it too.
@@ -102,0 +120,4 @@let now = (s.clock)();s.store.post(&id, &token, &body, now)?;// Only after the blob is stored under a valid post token; the 201 does not wait for the wake.if let Ok(Some(endpoint)) = s.store.push_endpoint(&id) {W5 — correctness. The wake comes only after
store.postsucceeded: a stranger, the owner's own fetch token, an over-quota (507) or an oversized post wakes nobody (planted bug "a refused post wakes" caught). The 201 does not wait for the wake (spawned).@@ -0,0 +49,4 @@pub fn new(allow_loopback: bool) -> Self {let config = Config::builder().timeout_global(Some(WAKE_TIMEOUT)).max_redirects(0)W2 — security. No redirect is followed: a redirect would reach an address the resolver never judged by the endpoint's host. Test: a push server answering 303 to another path on itself sees nothing there (the first version of this test used 307 on a POST, which ureq would not have followed anyway, so the planted bug was missed; fixed).
@@ -0,0 +77,4 @@if !self.due(id, now) {return false;}let Ok(slot) = Arc::clone(&self.slots).try_acquire_owned() else {W3 — availability. At most 16 wakes in flight, 10 s each. Anyone can make a mailbox (no account), point it at a tarpit that never answers, and post to it once a minute; 16 such mailboxes hold every slot, and other people's wakes are dropped. Nothing leaks and nothing is lost (the app fetches everything when opened), but wakes can be starved. Recorded as a gap: a per-address cap, or a shorter timeout for a host that timed out before. An operator under such abuse can turn wakes off (
wake = false).@@ -0,0 +113,4 @@.header("TTL", "86400").header("Urgency", "normal").header("Content-Type", "application/octet-stream").send(WAKE_BODY);W4 — privacy. The body is a public constant and the headers are fixed: nothing of the mailbox, the blob, its size or its sender. The push server learns that this relay's address woke one of its capability URLs, and when — the cost the person accepts by choosing a distributor. Not Web Push encrypted (RFC 8291): nothing to hide in a constant, but see the analysis's gap W1 for distributors that need VAPID.
@@ -0,0 +150,4 @@}/// Whether the relay may connect to this address: global unicast only (loopback when allowed).pub fn reachable(ip: IpAddr, allow_loopback: bool) -> bool {W1 — security (SSRF). The relay resolves the endpoint's host itself and keeps only global addresses; ureq connects to exactly the list this resolver returns, so DNS rebinding between check and connect has no gap. IPv4-mapped, IPv4-compatible, NAT64, 6to4 and Teredo forms are refused or judged as the IPv4 inside. With no redirects (W2), the relay cannot be steered at its own network by a mailbox owner.
@@ -84,2 +97,3 @@# allowed, so localhost (Caddy) stays reachable.IPAddressAllow = "localhost";RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];IPAddressDeny =W7 — found in review: the deploy would have dropped every wake. The sandbox allowed localhost only. Now, with
wakeon (default), global addresses are allowed and every non-global range is still denied by systemd — a second wall behind W1 — andAF_UNIXlets glibc ask nscd for names. Unrun here: no Nix on this machine.Merged into
mainwith--no-ffas1d7f08927d(remote hash verified).Pull request closed