Directory self-registration lets throwaway identities claim retain protection, so the PR #302 fallback still evicts legitimate representatives
Report
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.
Summary
PR #302 fixes issue #301 by protecting connected and directory-listed peers from eviction in the peer capability table. When the table is full, eviction now skips retained entries first. If every entry is retained, it falls back to evicting the oldest entry, so the table stays bounded at 4096 entries.
That fallback is reachable by an attacker, because directory membership is
free. A directory registration needs only a fresh keypair and a valid
self-signature. It needs no stake, no delegation, and no on-chain balance.
An attacker can register 4096 throwaway peer IDs into the victim node's
directory, then complete 4096 netcheck handshakes. Every throwaway entry is
then retained, the fallback evicts the oldest entry, and the oldest entry is
the legitimate representative, which was recorded first and is never
re-recorded. GetReadiness counts that representative's weight as unknown
again, and the readiness endpoint reports low numbers for features the
network actually supports. The DAO then holds off on signing the activation.
Nothing gets activated wrongly. Activation just stalls, same as in #301.
Affected code
net/features.go,(*peerCapTable).record, fallback eviction when all entries are retainednode/node.go, retain policy composition: directory membership counts as retaineddirectory/directory.go,HasNodePeerdirectory/verify.go:29,VerifyRegistration, signature check onlynode/node.go,handleDirectoryGossip, gossip registrations are stored after signature check onlynet/gossip_validate.go:153, directory gossip validator, signature check onlynode/activations.go:155-180,GetReadiness, reps without recorded capabilities fall intoUnknownWeightapi/handler.go:151,GET /network/readinessdocs/activations.md:166, activation needs readiness at or above 90% for 7 consecutive days
Root cause
The fix treats directory membership as proof that a peer ID belongs to a legitimate representative. The directory never proves that. Registration verifies only that the signature matches the key of the claimed account:
if err := core.VerifyPayloadKey(reg.PubKey, reg.Account); err != nil {
return fmt.Errorf("registration key: %w", err)
}
msg := canonicalBytes(reg.Account, reg.PubKey, reg.NodePeer, reg.Timestamp)
hash := sha256.Sum256(msg)
return core.VerifyHexSignature(reg.PubKey, reg.Signature, hash[:])
Anybody can generate a keypair, pick any peer ID as NodePeer, sign, and
register. The gossip validator accepts the same registrations, and the node
stores them in its local directory. The HTTP registration endpoint binds
loopback by default, so gossip is the remote path. The directory has no size
cap, so 4096 registrations fit.
Once the throwaways are in the directory, the retain policy returns true for each of them. The eviction scan finds no non-retained entry and the code falls back to the oldest entry:
// Fallback: if all entries are retained or no policy is set, evict oldest
if victimIdx == -1 {
victimIdx = 0
}
The legitimate representative is the oldest entry because it was recorded first and nothing re-records it. PR #302 adds no periodic re-verification, so the representative never moves to the back of the order. The first throwaway recorded after the table fills evicts it.
Measured evidence
Tested locally against the real table code and the real directory code in
package net (temporary Go test, written, run, then deleted; the repository
is untouched). The test uses the same retain composition as node.New:
retain if and only if the peer ID is in the directory.
- Register one legitimate representative in the directory and record its
capabilities with feature
messaging. - Register 4096 throwaway peer IDs in the directory, each with a fresh keypair and a real signature, and record each one.
- The legitimate representative is gone from the table. Table size is exactly 4096.
Output:
=== RUN TestZZDirSpoofRetainBypass
PROBE CONFIRMED: legit rep evicted after 4096 directory-registered
throwaways; table size 4096
--- PASS: TestZZDirSpoofRetainBypass (1.34s)
The step from an evicted table to a wrong readiness number follows from the
code in GetReadiness (node/activations.go:155-180): a representative
with no entry in the capabilities map is counted in UnknownWeight and
contributes no feature weight. That part was checked by reading the code,
not by running a live node.
Impact
The readiness numbers the DAO relies on go wrong in the under-reporting
direction, exactly as in #301. A representative that has upgraded and
advertises a feature is counted as unknown, so the feature looks less ready
than it is. The DAO procedure asks for readiness at or above 90% for 7
consecutive days before signing (docs/activations.md:166), so even a
short dip can restart that 7 day wait. The effect ends when legitimate
peers reconnect and their capabilities are recorded again, which means an
attacker who wants to hold the eviction has to keep registering and
handshaking. The failure stays on the side of caution: activation is
delayed, never wrongly granted, and no funds move.
The cost to the attacker is the same as in #301 plus a trivial step: 4096 keypairs and signatures take seconds of CPU, and 4096 handshakes take about two minutes at the configured global limit of 32 per second.
Related findings
This is a different defect from #301, which is about a table with no protection at all: plain FIFO eviction of the oldest entry. That issue says nothing about the retain policy, because the retain policy did not exist when #301 was filed. This report is about the fix itself: the retain predicate trusts a signal that any attacker can produce for free, and the documented fallback evicts the oldest retained entry.
It is also different from #156, #169, and #281, which are about directory timestamps: missing freshness bounds and far-future timestamps. Those issues say nothing about the capability table or about retain protection. The defect here needs no timestamp game. A registration with a current timestamp works.
PR #302 states the fallback in its own body: if all entries are retained, it evicts the oldest entry so capacity stays bounded. The PR does not state that directory membership is obtainable without stake. That gap is the defect.
Suggested fix
Any one of these closes the hole:
- Retain a directory peer only if its account holds delegated weight, so retention follows on-chain standing instead of a free self-signature.
- Cap the number of retained entries that are neither connected nor trusted, so throwaways can never fill the whole table as retained.
- When every entry is retained, drop the incoming entry instead of evicting the oldest retained one, so a flood cannot displace entries that are already in the table.
Method limits
- The eviction itself was reproduced in process against the real table
code and the real directory registration code. The gossip delivery of a
registration to a victim node and the wrong readiness number were traced
through the code (
handleDirectoryGossip,GetReadiness), not measured on a running node. No live node was driven and no testnet traffic was sent. - The two minute estimate for 4096 handshakes follows from the configured global limit of 32 per second with burst 128. It was not measured against a live node.
- The 7 day soak comes from the written DAO procedure in
docs/activations.md:166. Whether the DAO measures the streak from this endpoint continuously is a matter of their procedure, not of this code.
Thread
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:
-
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.
-
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.
-
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.
-
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.
-
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.
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.
Concrete differences from #301:
- 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.
- 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.
- 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. - 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.
I 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.
One 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.
Thank you for re-checking.
Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-1292 and says what differs; it is read like any other.