{"id":"XE-0121","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"197","source_url":"https://github.com/xeprotocol/xe/issues/197","reporter_id":39,"title":"[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'","area":"sdk-docs-web","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T16:39:13.168968+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":"2026-10-29T16:37:30+00:00","told_at":"2026-11-08T20:18:50.520977+00:00","status_changed_at":"2026-11-08T20:18:37.199887+00:00","url":"https://bounty.xe.network/XE-0121","body":"**Suggested severity: Medium (2,500 XE)**\n**Area:** client / CLI send path (`client/client.go`, `cmd/xe/main.go`); same class in `web/assets/wallet.js`\n**Repo pin:** 9787859 (testnet-0005)\n\n## Summary\n\n`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\"`).\n\nSubmitting 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.\n\n## Code\n\n```go\n// client/client.go:35-56 — no status check anywhere\nresp, err := http.Get(url)\nif err != nil {\n\treturn nil, err\n}\nvar result struct {\n\tBlocks []*core.Block `json:\"blocks\"`\n\tTotal  int           `json:\"total\"`\n}\nerr = json.NewDecoder(resp.Body).Decode(&result)   // 429 body decodes fine\n_ = resp.Body.Close()\nif err != nil {\n\treturn nil, err\n}\nall = append(all, result.Blocks...)\nif len(result.Blocks) == 0 || len(all) >= result.Total {\n\tbreak\n}\n```\n\n```go\n// cmd/xe/main.go:699-708 — errors discarded, prev pinned to \"0\"\nchain, _ := c.GetChain(addr)\nbals, _ := c.GetBalances(addr)\n...\nprev := \"0\"\nif len(chain) > 0 {\n\tprev = chain[len(chain)-1].Hash\n}\n```\n\n```go\n// core/crypto.go:99-104 — \"0\" means open block\nif b.Previous == \"0\" && b.PubKey == \"\" && len(b.Signatures) == 0 && ... {\n\tb.PubKey = kp.PubKeyHex()\n}\n```\n\n```go\n// core/conflict.go:40-50 — any block sharing Previous with a stored block is a sibling\nfor _, existing := range chain.Blocks {\n\tif existing.Previous == b.Previous {\n\t\treturn existing.Hash\n\t}\n}\n```\n\n```go\n// core/ledger.go:808-818 — sibling is staged (accepted), and later blocks are refused\nsiblingHash := detectConflictSibling(chain, b)\nif siblingHash == \"\" {\n\tconflicts, cerr := cs.GetConflictsForAccount(b.Account)\n\tif cerr == nil && len(conflicts) > 0 {\n\t\treturn fmt.Errorf(\"account has unresolved conflict — block rejected pending resolution\")\n\t}\n} else {\n\tif l.IsFinalized(b.Account, siblingHash) { ... reject ... }\n\t// otherwise: SaveStagedBlock + return nil  → HTTP 201\n}\n```\n\n## PoC (run against the shipped client code)\n\nThe probe copies `client/client.go` byte-identically (sha256 `bcf256…1161`) and stubs only the two `core` structs:\n\n```\n429 rate-limited   GetChain: err=<nil> blocks=0 | GetBalances: err=<nil> bals=map[] | prev(cmdSend)=\"0\"\n503 retryable      GetChain: err=<nil> blocks=0 | ...\n500 origin down    GetChain: err=<nil> blocks=0 | ...\n200 empty chain    GetChain: err=<nil> blocks=0 | prev=\"0\"\n```\n\nSo four very different server responses produce the same client state: \"this account has no blocks, safe to open\".\n\n## Attack / failure path\n\n1. Account has a genesis block that is not yet finalized (the normal state for minutes after a faucet payout), and has submitted ≥1 block.\n2. `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.\n3. `GetChain` returns `(nil, nil)`; `cmdSend` signs with `prev=\"0\"` and PoW.\n4. Node: sibling detected → staged conflict → **201**; CLI prints `Sent <amount> <asset> to <dest> — Hash: …`.\n5. 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`.\n6. User retries (believing the first send failed) → more staged siblings, more conflicts to resolve.\n\nImpact: false success + account freeze + delayed funds, triggered by ordinary HTTP conditions, no attacker required. Funds are recoverable only through conflict voting.\n\nHonest 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.\n\n## Same class in the web wallet\n\n`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.\n\n## Suggested fix\n\n- In `GetChain`/`GetBalances`: treat any `resp.StatusCode >= 300` as an error and include the API error body.\n- 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.\n- Same guard in the web wallet: refuse to sign when the chain refresh failed or is stale.\n- Add a regression test that a 429/500 on the chain read aborts the send instead of producing an open block.\n","patch_refs":[{"id":203,"repo":"xeprotocol/xe","kind":"pr","ref":"203","title":"fix(client,cli,web): check HTTP status and abort send on error (fixes #197)","url":"https://github.com/xeprotocol/xe/pull/203","note":"","state":"open","author":"NePreby","added_by":"desk","created_at":"2026-10-29T16:53:41.307308+00:00"}],"thread":[{"id":1600,"source":"desk","source_ref":"reply:719","author":"Joseph Denne","team":true,"body":"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.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}