[Node Crash] Remote node crash via directory gossip registration with short NodePeer (unguarded [:12] slice, no recover in gossip goroutine)
Report
Suggested severity: High (10,000 XE).
Summary
node/node.go:2381 evaluates reg.NodePeer[:12] as a Debugf argument in handleDirectoryGossip. Go evaluates arguments before the call regardless of log level, so any registration with len(NodePeer) < 12 panics with slice bounds out of range. The gossip goroutine (node/node.go:575) has no recover, so the panic kills the entire node process. Nothing on the path enforces a minimum length: the gossip directoryValidator (net/gossip_validate.go) only rejects empty fields and verifies the signature, and directory/verify.go only checks NodePeer != "". The sibling helpers shortAddr/shortHash (node/node.go:2350) do have guards — line 2381 just does not use them. The HTTP POST /directory/register path does not trigger this (no [:12] log there); only the gossip path does.
Impact
Remote, unauthenticated, ~zero-cost node crash: an attacker generates one keypair, self-signs a registration for their own account with NodePeer = "a" (1 character), and publishes it to the gossip topic. Any node whose gossip handler processes the message crashes. Because validated gossip messages propagate across the mesh, a single message can crash many nodes.
Steps to Reproduce (local, no real funds)
- Create a keypair and a directory registration for the attacker's own account with NodePeer = "a", signed with the attacker's key (valid signature, passes the gossip validator).
- Feed it to
handleDirectoryGossip. - Observed: panic
runtime error: slice bounds out of range [:12] with length 1, killing the handler goroutine's process (no recover). Control: a registration with a normal-length NodePeer is processed without panic.
Recommendation
Use the guarded truncation helper (as shortHash does) for NodePeer, or reject registrations with len(NodePeer) < 12 in VerifyRegistration, and add a recover to gossip handler goroutines as defense in depth.
Honest caveat: impact is availability (DoS), not fund theft. Tier High is suggested based on ~zero attacker cost, no authentication, and gossip propagation to many nodes; a Medium assessment for single-node DoS would be understood.
Payout address: to be provided on request.
Thread
Technical Proposal & Root Cause Analysis
I've reproduced the crash and confirmed the failure mechanism reported in this issue.
1. Root Cause Analysis
- Unguarded Slice Bounds: In
node/node.go(handleDirectoryGossip),logging.Debugfevaluatesreg.NodePeer[:12]. Because Go evaluates function arguments before invocation regardless of configured log level, any directory registration withlen(NodePeer) < 12panics with:runtime error: slice bounds out of range [:12] with length <n> - Fatal Goroutine Termination: The gossip consumer spawned in
node/node.go(n.handleDirectoryGossip(dirGossip.Subscribe(ctx))) lacked arecover()block. An unhandled panic in this goroutine immediately brings down the entire node process. - Missing Length Validation: Neither
directory.VerifyRegistrationnornet.directoryValidatorvalidatedNodePeerlength (only checkedNodePeer != ""), allowing maliciously crafted short peer IDs to propagate across the gossip mesh.
2. Implemented Fix
- Safe Truncation via
shortAddr: Replaced direct slicereg.NodePeer[:12]withshortAddr(reg.NodePeer)innode/node.go(handleDirectoryGossip), utilizing the existing bounds-guarded helper (shortHash). - Defensive Goroutine Recovery: Added a deferred
recover()block tohandleDirectoryGossipso that any unexpected panic in gossip processing is logged as an error without terminating the node process. - Payload Validation: Added a minimum length check (
len(reg.NodePeer) >= 12) todirectory.VerifyRegistration. - Gossip Layer Rejection: Added
len(reg.NodePeer) < 12rejection tonet.directoryValidatorso invalid registrations are dropped early at the pubsub layer before propagation or dispatch. - Unit Tests:
directory/verify_test.go: Asserts rejection of short / 1-characterNodePeervalues withnode_peer too short: minimum length is 12 characterswhile accepting valid peer IDs.node/directory_gossip_test.go: Feeds short, empty, and normal registrations intohandleDirectoryGossipto verify panic immunity and clean handling.
3. Verification & Readiness
- Cleanly verified:
go test ./...andgo vet ./...pass 100% green. - Staged and pushed to fork branch:
duongynhi000005-oss/xe:fix/directory-gossip-short-nodepeer-crash-89(commit88c6be6).
Please assign this issue to me if you'd like me to open the pull request with this fix.
Thanks. This is the same finding as #15, which was filed first: the unguarded [:12] slice on a short NodePeer in the directory registration path, reachable over gossip as well as HTTP. #15 is patched, and the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe the gossip path survives that fix, reply with a reproduction against the current build and we will reopen.
Hi Joseph — thanks for the review. I reproduced the crash against the current public build, so the gossip path appears to survive the #15 fix. Requesting reopen.
Build tested: xeprotocol/xe master HEAD 02e9641b0ac64437f57e09d63301f88cce61a802 (3 Nov 2026, "Merge pull request #251").
Reproduction (local, no live network):
- Build a validly signed directory registration with a 1-character
NodePeer("a") — signed with the attacker's own keypair viadirectory.NewRegistration. - Feed it to
Node.handleDirectoryGossip(the gossip handler, spawned atnode/node.go:575). - Result — the process panics:
panic: runtime error: slice bounds out of range [:12] with length 1
github.com/xeprotocol/xe/node.(*Node).handleDirectoryGossip
node/node.go:2381
Why it survives the #15 fix: at this HEAD, node/node.go:2381 still evaluates reg.NodePeer[:12] as a Debugf argument (Go evaluates arguments before the call, regardless of log level); directory/verify.go:36 (VerifyRegistration) and net/gossip_validate.go:149 (directoryValidator) still only reject an empty NodePeer — there is no minimum-length check anywhere in the tree; and the gossip goroutine spawned at node/node.go:575 still has no recover, so the panic kills the whole node process. A control registration with a 64-character NodePeer is processed without panic. The diff between the audit-time HEAD (9787859) and this HEAD touches only web/assets/dao.js — no Go change.
Happy to provide the test file if useful.