{"id":"XE-13270","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"397","source_url":"https://github.com/xeprotocol/xe/issues/397","reporter_id":1496,"title":"[Medium] xe chat send trusts server-advertised PoW difficulty with no bound and no timeout — malicious node pins operator CPU forever","area":"sdk-docs-web","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0703","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:06.288399+00:00","updated_at":"2026-11-20T00:07:02.774043+00:00","source_created_at":"2026-11-11T15:41:47+00:00","told_at":"2026-11-20T00:05:13+00:00","status_changed_at":"2026-11-20T00:04:41.173178+00:00","url":"https://bounty.xe.network/XE-13270","body":"Repo: https://github.com/xeprotocol/xe @ 89a542e\nSuggested severity: Medium\nPayout XE address: da2ad2483b592cb5a35224cec5529bf0c48f4770ed6fe40a455c312b5c1dcbcf\n\n# `xe chat send` trusts server-advertised chat PoW difficulty with no bound and no timeout — malicious/compromised node pins the operator's CPU forever\n\n- **Lokasi:**\n  - `client/chat.go:29-37` — `(*Client).ChatPoWDifficulty()` (parse hex dari JSON `/node`, tanpa validasi rentang)\n  - `cmd/xe/chat.go:110-124` — `chatSend()` meneruskan difficulty itu ke `chat.NewEnvelope`\n  - `chat/envelope.go:78-80` — `NewEnvelope(..., difficulty)` memanggil `core.ComputePoWConcurrent(idBytes, difficulty, runtime.NumCPU())`\n  - `core/pow.go:56-60,72-74` — `ComputePoWConcurrent` memakai `context.Background()` (tanpa timeout); `ValidatePoW` (`core/pow.go:41-43`) menerima bila `powHash >= difficulty`\n  - `cmd/xe/main.go:219-224` — `nodeURL()` default `https://ldn.core.test.network` (node publik, bukan localhost)\n- **HEAD:** `89a542e`\n- **Tier yang disarankan:** Medium (DoS CPU lokal terhadap operator; butuh node yang dikendalikan penyerang / terkompromi)\n- **Cek duplikat:** `grep -i \"difficulty|ComputePoW|pow.*spin|pow.*hang\" tickets.md` — satu-satunya yang terkait adalah **XE-1850** (\"`solvePow` accepts out-of-range difficulty and short hashes, returning nonces that fail `validatePow` — and hangs forever on a negative difficulty\").\n  - XE-1850 menyasar **TS SDK** (`solvePow`, camelCase, `sdk/`) dan difficulty negatif.\n  - Temuan ini menyasar **jalur Go yang berbeda**: CLI `xe chat send` → `client.ChatPoWDifficulty()` → `chat.NewEnvelope` → `core.ComputePoWConcurrent`, dengan pemicu difficulty uint64 mendekati 2^64-1 yang diiklankan node remote lewat endpoint `/node` yang tidak terautentikasi, tanpa timeout/cancel di sisi pemanggil. Tidak ada tiket untuk jalur Go ini.\n\n## Root cause\n\n```go\n// client/chat.go:29-37\nfunc (c *Client) ChatPoWDifficulty() (uint64, error) {\n\tinfo, err := c.NodeInfo()\n\t...\n\ts, _ := info[\"chat_pow_difficulty\"].(string)\n\tif s == \"\" {\n\t\treturn 0, fmt.Errorf(\"node advertises no chat_pow_difficulty\")\n\t}\n\treturn strconv.ParseUint(s, 16, 64) // <-- nilai apa pun 0..2^64-1 diterima\n}\n\n// cmd/xe/chat.go:116-123\ndifficulty, err := c.ChatPoWDifficulty()\n...\nenv, err := chat.NewEnvelope(kp.Address(), to, message, kp, difficulty)\n\n// chat/envelope.go:78-80\nif difficulty > 0 {\n\tenv.PoWNonce = core.ComputePoWConcurrent(idBytes, difficulty, runtime.NumCPU())\n}\n\n// core/pow.go:56-60\nfunc ComputePoWConcurrent(blockHash []byte, difficulty uint64, numWorkers int) uint64 {\n\tnonce, _ := ComputePoWWithContext(context.Background(), blockHash, difficulty, numWorkers)\n\treturn nonce\n}\n```\n\n`ValidatePoW` mensyaratkan `powHash(nonce, id) >= difficulty`, dengan `powHash` berupa 8 byte blake2b yang praktis uniform atas `[0, 2^64)`. Peluang satu nonce lolos ≈ `(2^64 - difficulty) / 2^64`. Untuk difficulty default `0xffffc00000000000` peluangnya ~2^-14 (milis/detik). Untuk difficulty `0xFFFFFFFFFFFFFF00` peluangnya ~2^-56 — ekspektasi ~7×10^16 percobaan, alias tidak pernah selesai. Tidak ada validasi `difficulty <= <maks>` di `client`, `cmd/xe`, `chat`, maupun `node` (di `node/node.go:217-220` `chatDifficulty` dari konfigurasi juga tidak divalidasi), dan tidak ada timeout/context pada pemanggilan PoW di jalur chat — `Ctrl-C` adalah satu-satunya jalan keluar, sementara semua core CPU tersedot penuh.\n\nRantai kepercayaan: default `XE_NODE` adalah node core publik (`https://ldn.core.test.network`), dan `/node` tidak terautentikasi. Node yang jahat/terkompromi, atau MITM bila pengguna memakai `XE_NODE=http://...`, cukup mengiklankan `\"chat_pow_difficulty\":\"ffffffffffffffff\"` untuk membuat setiap `xe chat send` menggantung selamanya dengan CPU 100% di semua core — sebelum pesan apa pun terkirim. (Jalur penandatanganan blok tidak terkena: `cmd/xe/main.go` memakai konstanta `core.DefaultDifficulty` di semua tempat.)\n\n## PoC (terverifikasi, `go test`, lalu file test dihapus)\n\n1. Difficulty dari server diterima apa adanya (test sementara `client/chatdiff_poc_test.go`, server `httptest` mengembalikan `{\"chat_pow_difficulty\":\"ffffffffffffffff\"}`):\n\n```\n=== RUN   TestPoCChatDifficultyFromServerUnvalidated\n    server-advertised difficulty accepted as-is: 0xffffffffffffffff (no bound, no timeout downstream)\n--- PASS (0.01s)\n```\n\n2. PoW pada difficulty ekstrem tidak pernah kembali, sementara difficulty default kembali (test sementara `core/pow_poc_test.go`):\n\n```\n=== RUN   TestPoCComputePoWExtremeDifficultyHangs\n    default difficulty 0xfffff80000000000: nonce 12740108599032212017 in 2.588026385s\n    extreme difficulty 0xffffffffffffffff00: no nonce in 10s (expected ~2^56 tries); a caller with no timeout hangs indefinitely\n--- PASS (12.66s)\n```\n\nReproduksi manual: jalankan node (atau mock HTTP) yang menjawab `GET /node` dengan `\"chat_pow_difficulty\":\"ffffffffffffffff\"`, lalu `XE_NODE=<node itu> xe chat send <alamat> halo` — proses akan memakan semua CPU tanpa pernah selesai / tanpa timeout.\n\n## Perbaikan yang disarankan\n\n- Di `client.ChatPoWDifficulty()` (atau `chat.NewEnvelope`): tolak difficulty di luar rentang yang wajar, mis. `difficulty <= chat.DefaultPoWDifficulty` atau batas atas eksplisit; kembalikan error, jangan lanjut ke PoW.\n- Beri timeout pada `ComputePoWConcurrent` di jalur chat (mis. `ComputePoWWithContext` dengan timeout beberapa detik dan error bila gagal), dan/atau validasi `chatDifficulty` saat node start (`node/node.go:217-220`).\n","patch_refs":[{"id":551,"repo":"xeprotocol/xe","kind":"pr","ref":"412","title":"fix(chat): enforce difficulty upper bound and timeout on PoW computation (Fixes #397)","url":"https://github.com/xeprotocol/xe/pull/412","note":"","state":"closed","author":"kleitonbernardino-lab","added_by":"desk","created_at":"2026-11-14T20:42:20.042109+00:00"},{"id":738,"repo":"xeprotocol/xe","kind":"pr","ref":"887","title":"fix(xe): medium--xe-chat-send-trusts-s (fixes #397)","url":"https://github.com/xeprotocol/xe/pull/887","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-19T19:57:29.806934+00:00"}],"thread":[{"id":3132,"source":"github","source_ref":"6807474784","author":"kleitonbernardino-lab","team":false,"body":"Opened pull request #412 addressing this vulnerability:\n\n1. **Upper Bound & Timeout Constants (`chat/envelope.go`)**:\n   - Established `MaxPoWDifficulty uint64 = 0xffffff0000000000` to bound acceptable proof-of-work difficulty.\n   - Introduced `DefaultPoWTimeout = 30 * time.Second` and `ErrDifficultyTooHigh`.\n   - Added `NewEnvelopeWithContext(ctx, ...)` with timeout cancellation, and bounded `NewEnvelope(...)`.\n   - Added difficulty upper bound validation to `VerifyFull(difficulty)`.\n\n2. **Client Validation (`client/chat.go`)**:\n   - `ChatPoWDifficulty()` now verifies the node-advertised difficulty against `chat.MaxPoWDifficulty` and fails fast with a descriptive error before any computation begins.\n\n3. **CLI Context Awareness (`cmd/xe/chat.go`)**:\n   - Bounded `chatSend` to a 30-second context timeout calling `chat.NewEnvelopeWithContext`.\n\n4. **Node Preflight Validation (`node/node.go`)**:\n   - Validates `chatDifficulty <= chat.MaxPoWDifficulty` during node initialization.\n\n5. **Unit Tests**:\n   - Added comprehensive tests in `chat/envelope_test.go` and `client/chat_test.go` verifying boundary conditions, timeout cancellation, and server advertisement parsing.","created_at":"2026-11-11T21:29:46+00:00"},{"id":12853,"source":"github","source_ref":"7025805161","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0703, 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-13270 and says what differs; it is read like any other.","created_at":"2026-11-20T00:05:13+00:00"}]}