<!-- XE-0073 · [Node Crash] Remote node crash via directory gossip registration with short NodePeer (unguarded [:12] slice, no recover in gossip goroutine) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0073>. The page is the record; this is the same page for reading.*

XE-0073 · Bounty

# \[Node Crash\] Remote node crash via directory gossip registration with short NodePeer (unguarded \[:12\] slice, no recover in gossip goroutine)

Closed · duplicate
—claimed High
[xe#89](https://github.com/xeprotocol/xe/issues/89)
filed 2026-10-26 21:50 UTC
by xe:6cf52cc9

Verdict
:   Duplicate

Tier
:   —

Claimed
:   High

Area
:   Consensus

Duplicate of
:   [XE-0006](https://bounty.xe.network/XE-0006) awarded

Tracked
:   internally

Updated
:   2026-11-16 13:42 UTC

Told
:   2026-11-08 08:59 UTC

### Patches

- [xe#111](https://github.com/xeprotocol/xe/pull/111) open by arturbarszcz78
  fix(node,directory): prevent panic on short NodePeer in directory gossip (#89)
- [xe#1029](https://github.com/xeprotocol/xe/pull/1029) merged

### History

- [21861](https://bounty.xe.network/log/21861) 2026-11-08 08:59 UTC reply.mirrored
- [21860](https://bounty.xe.network/log/21860) 2026-11-08 08:59 UTC reply.sent
- [21859](https://bounty.xe.network/log/21859) 2026-11-08 08:59 UTC proposal.adopted
- [4152](https://bounty.xe.network/log/4152) 2026-11-04 09:19 UTC proposal.created
- [871](https://bounty.xe.network/log/871) 2026-10-29 14:22 UTC github.state\_pushed
- [870](https://bounty.xe.network/log/870) 2026-10-29 14:22 UTC github.labels
- [660](https://bounty.xe.network/log/660) 2026-10-29 14:22 UTC patch.linked
- [659](https://bounty.xe.network/log/659) 2026-10-29 14:22 UTC ticket.status patched → closed
- [658](https://bounty.xe.network/log/658) 2026-10-29 14:22 UTC ticket.facts area
- [626](https://bounty.xe.network/log/626) 2026-10-29 14:05 UTC github.labels
- [398](https://bounty.xe.network/log/398) 2026-10-29 14:04 UTC ticket.status accepted → patched
- [397](https://bounty.xe.network/log/397) 2026-10-29 14:04 UTC ticket.status triaging → accepted

[Full history](https://bounty.xe.network/log?ref=XE-0073) · [JSON](https://bounty.xe.network/v1/tickets/XE-0073) · [markdown](https://bounty.xe.network/XE-0073.md)

### 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)

1. 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).
2. Feed it to `handleDirectoryGossip`.
3. 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

**duongynhi000005-oss**2026-10-27 07:08 UTCgithub

### Technical Proposal \& Root Cause Analysis

I've reproduced the crash and confirmed the failure mechanism reported in this issue.

#### 1\. Root Cause Analysis

1. **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:

   ```
   runtime error: slice bounds out of range [:12] with length <n>
   ```
2. **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.
3. **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.

---

#### 2\. Implemented Fix

- **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`).
- **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.
- **Payload Validation**: Added a minimum length check (`len(reg.NodePeer) >= 12`) to `directory.VerifyRegistration`.
- **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.
- **Unit Tests**:
  - `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.
  - `node/directory_gossip_test.go`: Feeds short, empty, and normal registrations into `handleDirectoryGossip` to verify panic immunity and clean handling.

---

#### 3\. Verification \& Readiness

- Cleanly verified: `go test ./...` and `go vet ./...` pass 100% green.
- 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`).

Please assign this issue to me if you'd like me to open the pull request with this fix.

**Joseph Denne**team2026-11-08 08:59 UTCgithub

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.

**Ryanmahrez44**2026-11-08 11:24 UTCgithub

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):**

1. Build a validly signed directory registration with a 1-character `NodePeer` (`"a"`) — signed with the attacker's own keypair via `directory.NewRegistration`.
2. Feed it to `Node.handleDirectoryGossip` (the gossip handler, spawned at `node/node.go:575`).
3. 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.
