{"id":"XE-0100","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"169","source_url":"https://github.com/xeprotocol/xe/issues/169","reporter_id":32,"title":"Directory registrations have no freshness check: far-future timestamps are immortal","area":null,"claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0097","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:26.746764+00:00","updated_at":"2026-11-10T00:11:33.601407+00:00","source_created_at":"2026-10-29T04:37:30+00:00","told_at":"2026-11-05T22:19:47+00:00","status_changed_at":"2026-11-05T22:19:43.343278+00:00","url":"https://bounty.xe.network/XE-0100","body":"# Directory registrations have no freshness check: far-future timestamps are immortal\n\n## Summary\n\n`directory/verify.go` checks fields, key derivation, and signature but\nnever timestamp freshness — unlike chat, which enforces a 5-minute skew\nwindow. `directory.go` expires entries only on `now − ts > TTL`, so a\nfuture timestamp never expires and never prunes; the monotonic rule then\nrejects all later normal re-registrations for that account while the API\nstill answers `ok: true`. `Directory.Remove` is never called anywhere in\nthe codebase, so no operator remedy exists at any layer.\n\n## Impact\n\nTwo honest halves, kept separate:\n\n- Mass immortal self-registrations are a Track-2 memory-growth vector:\n  the directory map is uncapped, measured at ~498 bytes per entry, so\n  ~50 MB per 100,000 immortal entries per node, multiplied by gossip\n  fan-out. Growth is per distinct account — each entry needs its own\n  valid keypair and signature, which is cheap ed25519 key generation\n  but not per-message.\n- Victim self-lock via clock skew is an accidental footgun, not an\n  attacker primitive: forging a victim's entry requires the victim's key\n  (proven below — both forgery shapes are rejected), so an attacker\n  cannot lock someone else out this way. A victim whose clock jumps\n  forward can, however, lock itself out of its own directory entry with\n  no remedy.\n\nSuggested program tier: **Medium** (validation gap).\n\n## Root cause\n\n- `directory/verify.go` `VerifyRegistration` (function body ~lines 31-57):\n  checks only missing fields, `core.VerifyPayloadKey` (the pubkey must\n  derive the account), and the ed25519 signature over canonical bytes\n  (account + pubkey + nodepeer + timestamp). No time comparison anywhere\n  in the function.\n- `directory/directory.go` expiry logic (Lookup/List/Prune region):\n  `Lookup` keeps an entry when `time.Since(time.Unix(0, reg.Timestamp))\n  > d.ttl` is false — negative for a future timestamp, so the entry is\n  kept; `Prune` removes only when `now - reg.Timestamp > ttl` — negative\n  for future timestamps, so 0 are pruned.\n- `directory/directory.go` monotonic rule in `Register`: `if ok &&\n  existing.Timestamp >= reg.Timestamp { return nil }` — a later normal\n  re-registration is silently dropped with a nil error.\n- `api/directory.go` `handleDirectoryRegister` maps a nil `Register`\n  error to HTTP 200 `{\"ok\": true}` — so the silent drop is confirmed to\n  the caller as success. This was verified literally, not figuratively.\n- `Directory.Remove` (defined at `directory.go:68`) has zero callers in\n  production code and zero in tests, and `api/directory.go` exposes only\n  Register/List/Lookup — no delete endpoint.\n- Contrast that proves the omission: `chat/envelope.go:19`\n  `MaxEnvelopeSkew = 5 * time.Minute`, enforced in both directions at\n  `envelope.go:92`. Directory has no equivalent.\n- Gossip amplification, traced in code: `node/node.go` `selfRegister`\n  (2359-2374: local Register + `DirGossip.Publish`) →\n  `net/gossip.go` `DirectoryGossip.Publish` (421-426: bare JSON marshal,\n  no validation) → `Subscribe` (429-461: only checks Account/Signature\n  non-empty, never calls `VerifyRegistration`) →\n  `node/node.go` `handleDirectoryGossip` (2376-2384: `Directory.Register`\n  on receipt). Strongest link: `directoryReRegisterLoop` (2399-2423)\n  re-publishes the victim's own stored entry every TTL/2 — since a\n  future entry never expires, the victim's node re-seeds the immortal\n  entry to peers forever.\n\n## Proof of concept\n\nTarget: `xeprotocol/xe` @ `978785929bc17a2f4ab30c383e5fc9cf4d634512`\n(2026-10-15). Harness rebuilt from the dossier steps for re-validation\n(the original scratch harness was deleted after use); it uses real\nkeypairs via `core.GenerateKeyPair` plus `directory.NewRegistration`,\nthe same path as production `selfRegister`. The repository itself is not\nmodified.\n\nAttached PoC: `pocs/f07-reval-test.go.txt`, byte-identical copy of the\nrunnable source.\n\nRun (Go 1.25.14):\n\n```\nexport PATH=\"$HOME/.local/go/bin:$PATH\"\nGOPROXY=off go test ./directory/ -run 'TestF07' -count=1 -vet=off -v\n```\n\nObserved output (verbatim, re-validation run 2026-10-29):\n\n```\n=== RUN   TestF07Reval\n    f07_reval_test.go:36: lookup after future register: ok=true ts=+100y\n    f07_reval_test.go:42: prune: pruned=0\n    f07_reval_test.go:56: re-register: err=nil (API would answer ok:true), stored ts STILL +100y (silently dropped)\n--- PASS: TestF07Reval (0.02s)\n=== RUN   TestF07GossipReceiverMirror\n    f07_reval_test.go:85: peer retains future entry, rejects fresh re-registration (monotonic rule)\n--- PASS: TestF07GossipReceiverMirror (0.00s)\n=== RUN   TestF07ForgedVictimRejected\n    f07_reval_test.go:100: forged key binding rejected: registration key: public key does not derive account c002b07b…\n    f07_reval_test.go:110: forged victim signature rejected: signature verification failed\n--- PASS: TestF07ForgedVictimRejected (0.02s)\n=== RUN   TestF07MemoryShape\n    f07_reval_test.go:139: map uncapped: len=100000 after 100000 inserts; heap delta/entry=498 bytes\n--- PASS: TestF07MemoryShape (2.97s)\nPASS\n```\n\n## Reproduction steps\n\n1. Register a directory entry with ts = now + 100 years (valid key and\n   signature).\n2. Observe: the entry never expires, never prunes.\n3. Re-register normally → silently dropped, while the API still answers\n   `ok: true`.\n\n## Recommended fix\n\nReject timestamps beyond a small future skew (mirror chat's 5-minute\nrule) and wire an operator removal path.\n\n## Severity\n\n- CVSS 3.1: 6.5 — `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L`\n- CWE-20 (Improper Input Validation)\n\n## Caveats\n\n- Gossip amplification rests on the traced loop plus the\n  receiver-executed mirror test above, not on a live two-node run:\n  delivery is generic pubsub and the security-relevant receiver behavior\n  (retain + reject fresh) is fully executed, but two live nodes were not\n  paired for this report.\n- The memory figure is a measured storage shape (bulk map insert of\n  realistic entries); the per-entry validity requirement (own keypair +\n  signature) is proven separately by the forgery-rejection test, not\n  inside the bulk insert.\n- The victim self-lock half is a footgun, not an attacker primitive, and\n  is not claimed otherwise: both forgery shapes (wrong key binding,\n  wrong signature) are rejected verbatim above.\n- No public prior report of the chat/directory mechanisms was found\n  (dedup query Q5 recorded in the audit's DEDUP-BASELINE.md).\n- This reproduction runs against the repository code at the stated HEAD. No\n  testnet transactions were sent as part of this report.\n\nPayout address (XE): eff2c51dd8457df740b919226cd9b37a2944e5abea7501094db80234f87f010e\n\nBest,\nChaplin\n\n[f07-reval-test.go.txt](https://github.com/user-attachments/files/34112499/f07-reval-test.go.txt)","patch_refs":[{"id":187,"repo":"xeprotocol/xe","kind":"pr","ref":"193","title":"fix(directory): enforce timestamp freshness skew window and add operator removal (fixes #169)","url":"https://github.com/xeprotocol/xe/pull/193","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":494,"source":"github","source_ref":"6671031153","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0097, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, reply with what differs and we will look again.","created_at":"2026-11-05T22:19:47+00:00"}]}