{"id":"XE-0073","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"89","source_url":"https://github.com/xeprotocol/xe/issues/89","reporter_id":2867,"title":"[Node Crash] Remote node crash via directory gossip registration with short NodePeer (unguarded [:12] slice, no recover in gossip goroutine)","area":"consensus","claimed_tier":"high","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0006","tracked":true,"internal_ref":"#1028","internal_url":"https://github.com/xeprotocol/core/issues/1028","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:20.472075+00:00","updated_at":"2026-11-16T13:42:49.539255+00:00","source_created_at":"2026-10-26T21:50:17+00:00","told_at":"2026-11-08T08:59:56+00:00","status_changed_at":"2026-10-29T14:22:09.609856+00:00","url":"https://bounty.xe.network/XE-0073","body":"Suggested severity: High (10,000 XE).\n\n## Summary\n\n`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.\n\n## Impact\n\nRemote, 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.\n\n## Steps to Reproduce (local, no real funds)\n\n1. 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).\n2. Feed it to `handleDirectoryGossip`.\n3. 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.\n\n## Recommendation\n\nUse 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.\n\nHonest 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.\n\nPayout address: to be provided on request.","patch_refs":[{"id":131,"repo":"xeprotocol/xe","kind":"pr","ref":"111","title":"fix(node,directory): prevent panic on short NodePeer in directory gossip (#89)","url":"https://github.com/xeprotocol/xe/pull/111","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"},{"id":193,"repo":"xeprotocol/xe","kind":"pr","ref":"1029","title":"","url":"https://github.com/xeprotocol/xe/pull/1029","note":"","state":"merged","author":"","added_by":"desk","created_at":"2026-10-29T14:22:09.061497+00:00"}],"thread":[{"id":23,"source":"github","source_ref":"6435944026","author":"duongynhi000005-oss","team":false,"body":"### Technical Proposal & Root Cause Analysis\n\nI've reproduced the crash and confirmed the failure mechanism reported in this issue.\n\n#### 1. Root Cause Analysis\n1. **Unguarded Slice Bounds**: In `node/node.go` (`handleDirectoryGossip`), `logging.Debugf` evaluates `reg.NodePeer[:12]`. Because Go evaluates function arguments before invocation regardless of configured log level, any directory registration with `len(NodePeer) < 12` panics with:\n   ```\n   runtime error: slice bounds out of range [:12] with length <n>\n   ```\n2. **Fatal Goroutine Termination**: The gossip consumer spawned in `node/node.go` (`n.handleDirectoryGossip(dirGossip.Subscribe(ctx))`) lacked a `recover()` block. An unhandled panic in this goroutine immediately brings down the entire node process.\n3. **Missing Length Validation**: Neither `directory.VerifyRegistration` nor `net.directoryValidator` validated `NodePeer` length (only checked `NodePeer != \"\"`), allowing maliciously crafted short peer IDs to propagate across the gossip mesh.\n\n---\n\n#### 2. Implemented Fix\n- **Safe Truncation via `shortAddr`**: Replaced direct slice `reg.NodePeer[:12]` with `shortAddr(reg.NodePeer)` in `node/node.go` (`handleDirectoryGossip`), utilizing the existing bounds-guarded helper (`shortHash`).\n- **Defensive Goroutine Recovery**: Added a deferred `recover()` block to `handleDirectoryGossip` so that any unexpected panic in gossip processing is logged as an error without terminating the node process.\n- **Payload Validation**: Added a minimum length check (`len(reg.NodePeer) >= 12`) to `directory.VerifyRegistration`.\n- **Gossip Layer Rejection**: Added `len(reg.NodePeer) < 12` rejection to `net.directoryValidator` so invalid registrations are dropped early at the pubsub layer before propagation or dispatch.\n- **Unit Tests**:\n  - `directory/verify_test.go`: Asserts rejection of short / 1-character `NodePeer` values with `node_peer too short: minimum length is 12 characters` while accepting valid peer IDs.\n  - `node/directory_gossip_test.go`: Feeds short, empty, and normal registrations into `handleDirectoryGossip` to verify panic immunity and clean handling.\n\n---\n\n#### 3. Verification & Readiness\n- Cleanly verified: `go test ./...` and `go vet ./...` pass 100% green.\n- Staged and pushed to fork branch: [`duongynhi000005-oss/xe:fix/directory-gossip-short-nodepeer-crash-89`](https://github.com/duongynhi000005-oss/xe/tree/fix/directory-gossip-short-nodepeer-crash-89) (commit `88c6be6`).\n\nPlease assign this issue to me if you'd like me to open the pull request with this fix.","created_at":"2026-10-27T07:08:57+00:00"},{"id":796,"source":"github","source_ref":"6719553630","author":"Joseph Denne","team":true,"body":"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.","created_at":"2026-11-08T08:59:56+00:00"},{"id":836,"source":"github","source_ref":"6720878573","author":"Ryanmahrez44","team":false,"body":"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.\n\n**Build tested:** `xeprotocol/xe` master HEAD `02e9641b0ac64437f57e09d63301f88cce61a802` (3 Nov 2026, \"Merge pull request #251\").\n\n**Reproduction (local, no live network):**\n\n1. Build a validly signed directory registration with a 1-character `NodePeer` (`\"a\"`) — signed with the attacker's own keypair via `directory.NewRegistration`.\n2. Feed it to `Node.handleDirectoryGossip` (the gossip handler, spawned at `node/node.go:575`).\n3. Result — the process panics:\n\n```\npanic: runtime error: slice bounds out of range [:12] with length 1\ngithub.com/xeprotocol/xe/node.(*Node).handleDirectoryGossip\n    node/node.go:2381\n```\n\n**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.\n\nHappy to provide the test file if useful.","created_at":"2026-11-08T11:24:32+00:00"}]}