{"id":"XE-1292","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"304","source_url":"https://github.com/xeprotocol/xe/issues/304","reporter_id":7,"title":"Directory self-registration lets throwaway identities claim retain protection, so the PR #302 fallback still evicts legitimate representatives","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"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-11-08T03:44:33.504720+00:00","updated_at":"2026-11-14T22:51:20.725977+00:00","source_created_at":"2026-11-08T03:43:08+00:00","told_at":"2026-11-14T22:50:41+00:00","status_changed_at":"2026-11-08T20:32:00.179966+00:00","url":"https://bounty.xe.network/XE-1292","body":"Code version: the retain policy and fallback below exist in PR #302 (open, unmerged at time of writing, commit 015ccbf); HEAD still has the plain FIFO table described in #301.\n\n## Summary\n\nPR #302 fixes issue #301 by protecting connected and directory-listed peers\nfrom eviction in the peer capability table. When the table is full, eviction\nnow skips retained entries first. If every entry is retained, it falls back\nto evicting the oldest entry, so the table stays bounded at 4096 entries.\n\nThat fallback is reachable by an attacker, because directory membership is\nfree. A directory registration needs only a fresh keypair and a valid\nself-signature. It needs no stake, no delegation, and no on-chain balance.\nAn attacker can register 4096 throwaway peer IDs into the victim node's\ndirectory, then complete 4096 netcheck handshakes. Every throwaway entry is\nthen retained, the fallback evicts the oldest entry, and the oldest entry is\nthe legitimate representative, which was recorded first and is never\nre-recorded. `GetReadiness` counts that representative's weight as unknown\nagain, and the readiness endpoint reports low numbers for features the\nnetwork actually supports. The DAO then holds off on signing the activation.\nNothing gets activated wrongly. Activation just stalls, same as in #301.\n\n## Affected code\n\n- `net/features.go`, `(*peerCapTable).record`, fallback eviction when all\n  entries are retained\n- `node/node.go`, retain policy composition: directory membership counts as\n  retained\n- `directory/directory.go`, `HasNodePeer`\n- `directory/verify.go:29`, `VerifyRegistration`, signature check only\n- `node/node.go`, `handleDirectoryGossip`, gossip registrations are stored\n  after signature check only\n- `net/gossip_validate.go:153`, directory gossip validator, signature check\n  only\n- `node/activations.go:155-180`, `GetReadiness`, reps without recorded\n  capabilities fall into `UnknownWeight`\n- `api/handler.go:151`, `GET /network/readiness`\n- `docs/activations.md:166`, activation needs readiness at or above 90%\n  for 7 consecutive days\n\n## Root cause\n\nThe fix treats directory membership as proof that a peer ID belongs to a\nlegitimate representative. The directory never proves that. Registration\nverifies only that the signature matches the key of the claimed account:\n\n```go\nif err := core.VerifyPayloadKey(reg.PubKey, reg.Account); err != nil {\n    return fmt.Errorf(\"registration key: %w\", err)\n}\nmsg := canonicalBytes(reg.Account, reg.PubKey, reg.NodePeer, reg.Timestamp)\nhash := sha256.Sum256(msg)\nreturn core.VerifyHexSignature(reg.PubKey, reg.Signature, hash[:])\n```\n\nAnybody can generate a keypair, pick any peer ID as `NodePeer`, sign, and\nregister. The gossip validator accepts the same registrations, and the node\nstores them in its local directory. The HTTP registration endpoint binds\nloopback by default, so gossip is the remote path. The directory has no size\ncap, so 4096 registrations fit.\n\nOnce the throwaways are in the directory, the retain policy returns true for\neach of them. The eviction scan finds no non-retained entry and the code\nfalls back to the oldest entry:\n\n```go\n// Fallback: if all entries are retained or no policy is set, evict oldest\nif victimIdx == -1 {\n    victimIdx = 0\n}\n```\n\nThe legitimate representative is the oldest entry because it was recorded\nfirst and nothing re-records it. PR #302 adds no periodic re-verification,\nso the representative never moves to the back of the order. The first\nthrowaway recorded after the table fills evicts it.\n\n## Measured evidence\n\nTested locally against the real table code and the real directory code in\npackage `net` (temporary Go test, written, run, then deleted; the repository\nis untouched). The test uses the same retain composition as `node.New`:\nretain if and only if the peer ID is in the directory.\n\n- Register one legitimate representative in the directory and record its\n  capabilities with feature `messaging`.\n- Register 4096 throwaway peer IDs in the directory, each with a fresh\n  keypair and a real signature, and record each one.\n- The legitimate representative is gone from the table. Table size is\n  exactly 4096.\n\nOutput:\n\n```text\n=== RUN   TestZZDirSpoofRetainBypass\n    PROBE CONFIRMED: legit rep evicted after 4096 directory-registered\n    throwaways; table size 4096\n--- PASS: TestZZDirSpoofRetainBypass (1.34s)\n```\n\nThe step from an evicted table to a wrong readiness number follows from the\ncode in `GetReadiness` (`node/activations.go:155-180`): a representative\nwith no entry in the capabilities map is counted in `UnknownWeight` and\ncontributes no feature weight. That part was checked by reading the code,\nnot by running a live node.\n\n## Impact\n\nThe readiness numbers the DAO relies on go wrong in the under-reporting\ndirection, exactly as in #301. A representative that has upgraded and\nadvertises a feature is counted as unknown, so the feature looks less ready\nthan it is. The DAO procedure asks for readiness at or above 90% for 7\nconsecutive days before signing (`docs/activations.md:166`), so even a\nshort dip can restart that 7 day wait. The effect ends when legitimate\npeers reconnect and their capabilities are recorded again, which means an\nattacker who wants to hold the eviction has to keep registering and\nhandshaking. The failure stays on the side of caution: activation is\ndelayed, never wrongly granted, and no funds move.\n\nThe cost to the attacker is the same as in #301 plus a trivial step:\n4096 keypairs and signatures take seconds of CPU, and 4096 handshakes take\nabout two minutes at the configured global limit of 32 per second.\n\n## Related findings\n\nThis is a different defect from #301, which is about a table with no\nprotection at all: plain FIFO eviction of the oldest entry. That issue says\nnothing about the retain policy, because the retain policy did not exist\nwhen #301 was filed. This report is about the fix itself: the retain\npredicate trusts a signal that any attacker can produce for free, and the\ndocumented fallback evicts the oldest retained entry.\n\nIt is also different from #156, #169, and #281, which are about directory\ntimestamps: missing freshness bounds and far-future timestamps. Those\nissues say nothing about the capability table or about retain protection.\nThe defect here needs no timestamp game. A registration with a current\ntimestamp works.\n\nPR #302 states the fallback in its own body: if all entries are retained,\nit evicts the oldest entry so capacity stays bounded. The PR does not state\nthat directory membership is obtainable without stake. That gap is the\ndefect.\n\n## Suggested fix\n\nAny one of these closes the hole:\n\n- Retain a directory peer only if its account holds delegated weight, so\n  retention follows on-chain standing instead of a free self-signature.\n- Cap the number of retained entries that are neither connected nor\n  trusted, so throwaways can never fill the whole table as retained.\n- When every entry is retained, drop the incoming entry instead of\n  evicting the oldest retained one, so a flood cannot displace entries\n  that are already in the table.\n\n## Method limits\n\n- The eviction itself was reproduced in process against the real table\n  code and the real directory registration code. The gossip delivery of a\n  registration to a victim node and the wrong readiness number were traced\n  through the code (`handleDirectoryGossip`, `GetReadiness`), not measured\n  on a running node. No live node was driven and no testnet traffic was\n  sent.\n- The two minute estimate for 4096 handshakes follows from the configured\n  global limit of 32 per second with burst 128. It was not measured\n  against a live node.\n- The 7 day soak comes from the written DAO procedure in\n  `docs/activations.md:166`. Whether the DAO measures the streak from this\n  endpoint continuously is a matter of their procedure, not of this code.","patch_refs":[{"id":350,"repo":"xeprotocol/xe","kind":"pr","ref":"305","title":"fix(net, node): gate directory retain protection on delegated weight and drop newcomers when full","url":"https://github.com/xeprotocol/xe/pull/305","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-08T03:48:43.906722+00:00"}],"thread":[{"id":797,"source":"github","source_ref":"6719572472","author":"rusdiwireng","team":false,"body":"Thanks for the fix in PR #305 — I reviewed it locally against the PR code, and the attack as filed is closed: free throwaways without weight no longer evict a recorded legitimate representative. Five legs are still open:\n\n1. Pre-fill lockout (the substantial one). The new drop-newcomer fallback (net/features.go:84-87) protects representatives already in the table, but it creates a first-come-first-served window: 4096 weighted throwaways (1 unit each) fill the table first, and a legitimate representative (weight 50,000) arriving later is dropped as the newcomer. Verified with a local probe against the PR code: legitInTable=false, the representative's weight counted as UnknownWeight=50,000, readiness messaging 0/1000. Preconditions: the attacker must win the race before legitimate representatives record their capabilities (the main window is a fresh or restarted node with an empty table) and hold at least 4096 dust units (recoverable, not burned) plus 4096 directory registrations and 4096 handshakes. The lockout lasts while the attacker refreshes directory registrations every 30 minutes (the TTL); table entries only leave through ban or remove, not disconnect. There is no slot reservation for delegated representatives and no admission priority based on weight, so a representative with weight 50,000 loses to a 1-unit throwaway that arrived first. Re-recording a representative already in the table is safe; only the first arrival while the table is full is at risk. A fix that closes it: reserve slots for delegated representatives, or evict newcomer-versus-oldest by lowest weight, or set a meaningful minimum weight threshold.\n\n2. The weight threshold is > 0 with no minimum. A throwaway with 1 unit of dust (self-delegated) claims retain protection — 4096/4096 in the same local probe. Consider a meaningful minimum threshold or a cap on retained non-connected entries.\n\n3. The directory is still uncapped. Register is unchanged, so an attacker can freely bloat the directory with throwaway registrations. Retain is now gated, but the directory itself has no quota. Observation, not a separate claim.\n\n4. Ledger == nil fail-open in IsDelegatedRepPeer (node.go:2463-2465): if n.Ledger is nil, every directory peer is retained, which is the pre-#305 behavior. Not reachable through New() — the ledger is always set (node.go:256) before the Node is built — so only a manually constructed Node (for example in tests) could hit it. Observation only.\n\n5. The second eligibility check bypasses the allowlist. GetVoteWeight (the first check) respects the sys.representatives allowlist; GetAllVoteWeights (the second check, repeligibility.go:130) does not, so a representative not on the allowlist can still get retain through the second check. This is stated in the PR body itself. Observation only.","created_at":"2026-11-08T09:01:59+00:00"},{"id":1542,"source":"github","source_ref":"6730863931","author":"rusdiwireng","team":false,"body":"Hi, thanks for triaging. I am writing to ask for a re-check of the duplicate closure on this issue, because #304 reports a defect that only exists in the fix for #301, not in the code #301 reported against.\n\nConcrete differences from #301:\n\n1. **Different precondition, which did not exist when #301 was filed.** #301 was filed against HEAD, where the peer capability table is plain FIFO with no retain policy at all. #304 was filed about two hours later, after PR #302 existed, and its attack only works on PR #302's code: the retain policy plus the all-retained fallback that evicts the oldest entry. Without PR #302, #304's attack is meaningless — a throwaway without retain protection is evicted by ordinary FIFO first, which is exactly what #302 changed.\n2. **Different mechanism.** #301: flood netcheck handshakes, FIFO pushes old entries out. #304: register 4096 throwaway peer IDs in the directory for free (fresh keypair + valid self-signature, no stake, no delegation, no balance), so every throwaway claims retain protection and the #302 fallback evicts the legitimate representative. The directory is the attack surface here, not the handshake flood alone. #301 says nothing about the directory or about retain protection, because neither existed in the code it reported against.\n3. **Different fix, already recognised as such.** PR #302 (\"Fixes #301\") introduces retain protection with an evict-oldest fallback. PR #305 (\"Fixes #304\") gates directory retain on delegated weight and changes the all-retained fallback to drop-newcomer. PR #305's own body reproduces \"the exact attack from Issue #304\" in a dedicated test (`TestReadiness_DirectorySelfRegistrationThrowawaysCannotEvictDelegatedRep`). The fix author treated #304 as a distinct issue requiring a distinct fix; #302 alone does not close it.\n4. **Different timing and filing order.** #301 (01:42Z) predates PR #302 (01:54Z); #304 (03:43Z) postdates it. #304 is a follow-up on the fix, in the usual sense: the fix introduced a new reachable fallback, and this report shows how to reach it.\n\nI agree the end effect is the same (readiness under-reports, DAO activation stalls). But the effect is reached through a different precondition, a different code path, and a different fix — that is what distinguishes a follow-up finding from a duplicate report.\n\nOne honest caveat on my side: I cannot see the duplicate target, since no public issue covers directory self-registration claiming retain protection (the directory issues #156/#169/#281 are about registration timestamps, not retain). If this was closed as a duplicate of a desk entry that already described this exact retain bypass, please point me to it and I will withdraw this appeal. If it was closed as a duplicate of #301, I ask that the closure be reconsidered on the four points above.\n\nThank you for re-checking.","created_at":"2026-11-09T02:34:20+00:00"},{"id":3414,"source":"github","source_ref":"6885450633","author":"XE desk","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, 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, file a new report that links https://bounty.xe.network/XE-1292 and says what differs; it is read like any other.","created_at":"2026-11-14T22:50:41+00:00"}]}