Bounty
XE-0121 · Bounty

[CLI/client] GetChain ignores HTTP status: a 429/5xx makes `xe send` sign an open block (prev=0) for an existing account — accepted as a staged fork, account conflict-locked, CLI prints 'Sent'

Triaging claimed Medium xe#197 filed 2026-10-29 16:37 UTC by hayokakoweda75

Report

Suggested severity: Medium (2,500 XE) Area: client / CLI send path (client/client.go, cmd/xe/main.go); same class in web/assets/wallet.js Repo pin: 9787859 (testnet-0005)

Summary

Client.GetChain performs http.Get and decodes the body without ever looking at resp.StatusCode. API errors are JSON (writeError → {"error":"..."}), so a 429/500/503 decodes successfully into an empty result with err == nil. cmdSend then discards the error anyway (chain, _ := c.GetChain(addr)), sets prev = "0", and core.SignBlock turns that into an open block (PubKey filled, Previous == "0").

Submitting that block for an account that already has a genesis block makes it a sibling of the account's first block (detectConflictSibling matches on Previous), so the ledger stages it as a conflict, returns success to the HTTP caller, and the CLI prints Sent … Hash: …. The transfer never happens; the account is then conflict-locked and receives from the contested source are deferred.

Code

// client/client.go:35-56 — no status check anywhere
resp, err := http.Get(url)
if err != nil {
	return nil, err
}
var result struct {
	Blocks []*core.Block `json:"blocks"`
	Total  int           `json:"total"`
}
err = json.NewDecoder(resp.Body).Decode(&result)   // 429 body decodes fine
_ = resp.Body.Close()
if err != nil {
	return nil, err
}
all = append(all, result.Blocks...)
if len(result.Blocks) == 0 || len(all) >= result.Total {
	break
}
// cmd/xe/main.go:699-708 — errors discarded, prev pinned to "0"
chain, _ := c.GetChain(addr)
bals, _ := c.GetBalances(addr)
...
prev := "0"
if len(chain) > 0 {
	prev = chain[len(chain)-1].Hash
}
// core/crypto.go:99-104 — "0" means open block
if b.Previous == "0" && b.PubKey == "" && len(b.Signatures) == 0 && ... {
	b.PubKey = kp.PubKeyHex()
}
// core/conflict.go:40-50 — any block sharing Previous with a stored block is a sibling
for _, existing := range chain.Blocks {
	if existing.Previous == b.Previous {
		return existing.Hash
	}
}
// core/ledger.go:808-818 — sibling is staged (accepted), and later blocks are refused
siblingHash := detectConflictSibling(chain, b)
if siblingHash == "" {
	conflicts, cerr := cs.GetConflictsForAccount(b.Account)
	if cerr == nil && len(conflicts) > 0 {
		return fmt.Errorf("account has unresolved conflict — block rejected pending resolution")
	}
} else {
	if l.IsFinalized(b.Account, siblingHash) { ... reject ... }
	// otherwise: SaveStagedBlock + return nil  → HTTP 201
}

PoC (run against the shipped client code)

The probe copies client/client.go byte-identically (sha256 bcf256…1161) and stubs only the two core structs:

429 rate-limited   GetChain: err=<nil> blocks=0 | GetBalances: err=<nil> bals=map[] | prev(cmdSend)="0"
503 retryable      GetChain: err=<nil> blocks=0 | ...
500 origin down    GetChain: err=<nil> blocks=0 | ...
200 empty chain    GetChain: err=<nil> blocks=0 | prev="0"

So four very different server responses produce the same client state: "this account has no blocks, safe to open".

Attack / failure path

  1. Account has a genesis block that is not yet finalized (the normal state for minutes after a faucet payout), and has submitted ≥1 block.
  2. xe send hits /accounts/{addr}/chain while the node returns 429 (read bucket: 200/s, burst 1000 per IP — easy to reach with a busy client or a shared NAT) or 5xx (deploy/restart), or the account has >1000 blocks so pagination issues several requests and one of them 429s.
  3. GetChain returns (nil, nil); cmdSend signs with prev="0" and PoW.
  4. Node: sibling detected → staged conflict → 201; CLI prints Sent <amount> <asset> to <dest> — Hash: ….
  5. Every following block from that account → account has unresolved conflict — block rejected pending resolution; receives whose source is the contested block → source send … is contested by an unresolved conflict — receive deferred.
  6. User retries (believing the first send failed) → more staged siblings, more conflicts to resolve.

Impact: false success + account freeze + delayed funds, triggered by ordinary HTTP conditions, no attacker required. Funds are recoverable only through conflict voting.

Honest limit: if the account's first block is already finalized the sibling is rejected outright (block conflicts with finalized block) and the account stays safe — the damage is concentrated in the window between first block and finality.

Same class in the web wallet

web/assets/wallet.js:481-515 (hydrateFromSnapshot reuses previous from localStorage), :684-717 (Promise.allSettled, refresh failures do not block), :843-854 (onSend signs with the stale previous) — a chain refresh failure there signs against a stale predecessor rather than opening a block, producing the same "accepted then conflicted" outcome.

Suggested fix

  • In GetChain/GetBalances: treat any resp.StatusCode >= 300 as an error and include the API error body.
  • In cmdSend: never fall back to prev = "0" on an error. Only open a block when a 200 response explicitly reports total == 0; otherwise abort before signing.
  • Same guard in the web wallet: refuse to sign when the chain refresh failed or is stale.
  • Add a regression test that a 429/500 on the chain read aborts the send instead of producing an open block.

Thread

Joseph Denneteam2026-11-08 20:17 UTCdesk

Thanks for the detailed report. We have confirmed the client-side behaviour you describe and it is being handled; part of the described consequence does not reproduce against the current tree, and we will say more on this ticket once the fix is in.