{"id":"XE-0107","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"177","source_url":"https://github.com/xeprotocol/xe/issues/177","reporter_id":37,"title":"net/sync: a nil block element in a SyncResponse panics the node; no recover() on the sync path (High)","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0002","tracked":true,"internal_ref":"#1064","internal_url":"https://github.com/xeprotocol/core/issues/1064","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:27.871122+00:00","updated_at":"2026-11-14T22:53:19.106291+00:00","source_created_at":"2026-10-29T08:30:52+00:00","told_at":"2026-11-14T22:52:13+00:00","status_changed_at":"2026-11-08T20:32:04.478904+00:00","url":"https://bounty.xe.network/XE-0107","body":"# Nil block element in a sync response panics the node; no `recover()` on the sync path\n\n## Summary\n\nAny peer that connects to a node can kill it with a 22-byte payload. The sync client\ndecodes a `SyncResponse` whose `Blocks` field is `[]*core.Block`, so a JSON `null`\nelement becomes a nil pointer, and `net/sync.go:592` dereferences it before any\nsignature, PoW or account check runs. The panic escapes the goroutine because the\nsync stream handler and `spawnGate.spawn` have no `recover()`, so the process dies\nwith SIGSEGV. I reproduced this three times against a node running the pinned\nrevision, with a control test showing that a well-formed response leaves the node\nalive.\n\n## Details\n\n- Type: nil pointer dereference, uncaught exception (CWE-248, CWE-476)\n- Asset: `test.network`, P2P port 9000, protocol `/xe/sync/1.0.0`\n- Endpoint: `net/sync.go:592` in `requestSync`\n- Auth required: none. No account, signature, lease, balance or PoW.\n- Source revision: `xeprotocol/xe` @ `978785929bc17a2f4ab30c383e5fc9cf4d634512`\n- Severity claimed: High. The programme's High tier covers \"Targeted DoS ... sustained\n  degradation a single client can cause\". I am not claiming Severe: what I proved is a\n  single-node crash with a crash-loop path, not a network-wide finality stall.\n\n## Root cause\n\n`net/messages.go:21-26` declares the response type with a pointer slice:\n\n```go\ntype SyncResponse struct {\n    Blocks   []*core.Block `json:\"blocks\"`\n    HasMore  bool          `json:\"has_more\"`\n    Cursor   string        `json:\"cursor\"`\n    Rejected []string      `json:\"rejected,omitempty\"`\n}\n```\n\nA JSON element of `null` decodes to a nil pointer. Three sinks dereference it with no\nguard:\n\n| Location | Code |\n|---|---|\n| `net/sync.go:592` | `if quarantine.contains(b.Hash)` |\n| `net/sync.go:604` | `ledger.AddSyncedBlock(b)`, which reaches `core/ledger.go:740` (`bc := *b`) |\n| `statechain/sync.go:178` | `chain.AddBlock(b)`, which reaches `HashBlock(nil)` |\n\nFive of the seven wire-block consumers in the codebase already guard against nil. The\ntwo sync sinks do not:\n\n| Site | Nil guard |\n|---|---|\n| `net/gossip_validate.go:70` (blockValidator) | yes |\n| `net/gossip_validate.go:107` (voteValidator) | yes |\n| `net/gossip_validate.go:131` (stateChainValidator) | yes |\n| `net/gossip_validate.go:186` (marketplaceValidator) | yes |\n| `net/blocksync.go:80` | yes, `if b == nil \\|\\| !want[b.Hash]` |\n| `net/sync.go:592` | no |\n| `statechain/sync.go:178` | no |\n\nThe message handler has a `recover()` at `net/msg.go:69-73`. The sync stream handler\n(`net/sync.go:311-318`) and `spawnGate.spawn` (`net/sync.go:403-406`) do not, so a\npanic on that path terminates the process instead of one stream.\n\n## Steps to reproduce\n\nEnvironment: 29 October 2026, Go 1.25.0 linux/arm64, node built from the pinned\nrevision with `go build -ldflags \"-X main.version=1.0.0\" -o xe-node ./cmd/xe`.\n\nThe PoC runs two libp2p hosts. The victim uses the production `xenet.SetupSync`. The\nattacker answers any sync request with a nil block element.\n\n1. Start the victim node with the production sync setup.\n2. Connect the attacker peer to the victim.\n3. The victim's `ConnectedF` notification fires and dials the attacker back, which\n   starts a sync round.\n4. The attacker replies with `{\"blocks\":[null],\"has_more\":false,\"cursor\":\"\"}`.\n5. The victim panics.\n\nObserved output, identical across three consecutive runs:\n\n```\nvictim node id=12*7zgQ1T\nattacker peer id=12*gbh77t\nattacker connected to victim, waiting for ConnectedF dial-back\nattacker: replying with nil block element\npanic: runtime error: invalid memory address or nil pointer dereference\n[signal SIGSEGV: segmentation violation code=0x1 addr=0x138 pc=0x9c384c]\n\ngithub.com/xeprotocol/xe/net.requestSync(...)\n\tnet/sync.go:592 +0x71c\ngithub.com/xeprotocol/xe/net.SetupSync.func2.1()\n\tnet/sync.go:326 +0x8c\ngithub.com/xeprotocol/xe/net.(*spawnGate).spawn.func1()\n\tnet/sync.go:405 +0x50\ncreated by github.com/xeprotocol/xe/net.(*spawnGate).spawn\n\tnet/sync.go:403 +0x174\n```\n\nExit code 2, SIGSEGV address `0x138`, same stack frames, same line numbers, all three\nruns.\n\nControl test: the same PoC with the attacker replying `{\"blocks\":[],\"has_more\":false}`\nleaves the node running with no errors. The nil element is the specific cause.\n\n## Reachability\n\nThe server-side handler `handleSyncStream` never parses a `SyncResponse`; it only emits\nblocks from its own ledger, so it cannot be the entry point. The vulnerable parse is in\n`requestSync`, the client side, which runs from `ConnectedF`. Any peer that merely\nconnects to a node makes that node dial it back and start a sync round, so the victim\nnever chooses the peer it syncs against. This makes the bug easier to reach than a\nserver-side handler would be.\n\n## Impact\n\nShown:\n\n- One 22-byte payload from any peer terminates the node process. No account,\n  signature, lease, balance or PoW is needed.\n- `deploy/xe-node.service:24` sets `Restart=always` with `RestartSec=5s`, and\n  `net/sync.go:27` sets `syncCooldown = 5 * time.Second`. A peer that reconnects every\n  5 seconds restarts the node as fast as the supervisor restarts it, so the node never\n  reaches the point of serving sync.\n- `deploy/monitoring/alerts.yml:97` notes that a restart rebuilds the weights, so the\n  node loses accumulated state on each cycle.\n\nNot shown:\n\n- No network-wide finality stall was demonstrated. I am not claiming the Severe tier.\n- No funds, keys or ledger state were affected. The panic happens before any signature\n  is persisted.\n\n## Remediation\n\nGuard every wire-sourced block pointer, matching the sibling handler:\n\n```go\nfor _, b := range resp.Blocks {\n    if b == nil {\n        continue\n    }\n    ...\n}\n```\n\nApply at `net/sync.go:592`, `net/sync.go:604` (or inside `AddSyncedBlock`), and\n`statechain/sync.go:178`. Adding a `recover()` to the sync stream handler, as\n`net/msg.go:69` does for the message handler, would contain any future panic on that\npath, but the nil guard is the fix.\n\n## Notes\n\n- Tested on testnet only. No funds were moved and no other node was attacked; the node\n  that crashed was my own, and the crash path is the production sync code.\n- The PoC is deterministic: one run succeeds, three consecutive runs produce identical\n  exit codes and stack traces, and the control survives.\n","patch_refs":[{"id":176,"repo":"xeprotocol/xe","kind":"pr","ref":"179","title":"fix(net,statechain): prevent nil pointer dereference on null block elements in sync and add panic recovery (fixes #177)","url":"https://github.com/xeprotocol/xe/pull/179","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"},{"id":180,"repo":"xeprotocol/xe","kind":"pr","ref":"182","title":"net, statechain: drop nil blocks, add recover guards, and fuse slow empty-page DoS (#177)","url":"https://github.com/xeprotocol/xe/pull/182","note":"","state":"open","author":"fangjian-bit","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":50,"source":"github","source_ref":"6492923526","author":"fangjian-bit","team":false,"body":"Submitted architectural fix and comprehensive regression test suite in #182.\n\nResolves the unauthenticated DoS crash by introducing zero-allocation in-place nil block filtering (`dropNilBlocks`) with aggregated warning rate-limits, defensive `applySyncedBlocks` checks, and panic recovery guards across `spawnGate.spawn`, libp2p stream handlers, and sync worker goroutines. Verified on native Linux Go 1.27.3 with full test suite passing in 0.067s.","created_at":"2026-10-29T09:24:19+00:00"},{"id":3614,"source":"github","source_ref":"6885468474","author":"XE desk","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0002, 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-0107 and says what differs; it is read like any other.","created_at":"2026-11-14T22:52:13+00:00"}]}