[Medium] xe chat send trusts server-advertised PoW difficulty with no bound and no timeout — malicious node pins operator CPU forever
Report
Repo: https://github.com/xeprotocol/xe @ 89a542e Suggested severity: Medium Payout XE address: da2ad2483b592cb5a35224cec5529bf0c48f4770ed6fe40a455c312b5c1dcbcf
xe chat send trusts server-advertised chat PoW difficulty with no bound and no timeout — malicious/compromised node pins the operator's CPU forever
- Lokasi:
client/chat.go:29-37—(*Client).ChatPoWDifficulty()(parse hex dari JSON/node, tanpa validasi rentang)cmd/xe/chat.go:110-124—chatSend()meneruskan difficulty itu kechat.NewEnvelopechat/envelope.go:78-80—NewEnvelope(..., difficulty)memanggilcore.ComputePoWConcurrent(idBytes, difficulty, runtime.NumCPU())core/pow.go:56-60,72-74—ComputePoWConcurrentmemakaicontext.Background()(tanpa timeout);ValidatePoW(core/pow.go:41-43) menerima bilapowHash >= difficultycmd/xe/main.go:219-224—nodeURL()defaulthttps://ldn.core.test.network(node publik, bukan localhost)
- HEAD:
89a542e - Tier yang disarankan: Medium (DoS CPU lokal terhadap operator; butuh node yang dikendalikan penyerang / terkompromi)
- Cek duplikat:
grep -i "difficulty|ComputePoW|pow.*spin|pow.*hang" tickets.md— satu-satunya yang terkait adalah XE-1850 ("solvePowaccepts out-of-range difficulty and short hashes, returning nonces that failvalidatePow— and hangs forever on a negative difficulty").- XE-1850 menyasar TS SDK (
solvePow, camelCase,sdk/) dan difficulty negatif. - 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/nodeyang tidak terautentikasi, tanpa timeout/cancel di sisi pemanggil. Tidak ada tiket untuk jalur Go ini.
- XE-1850 menyasar TS SDK (
Root cause
// client/chat.go:29-37
func (c *Client) ChatPoWDifficulty() (uint64, error) {
info, err := c.NodeInfo()
...
s, _ := info["chat_pow_difficulty"].(string)
if s == "" {
return 0, fmt.Errorf("node advertises no chat_pow_difficulty")
}
return strconv.ParseUint(s, 16, 64) // <-- nilai apa pun 0..2^64-1 diterima
}
// cmd/xe/chat.go:116-123
difficulty, err := c.ChatPoWDifficulty()
...
env, err := chat.NewEnvelope(kp.Address(), to, message, kp, difficulty)
// chat/envelope.go:78-80
if difficulty > 0 {
env.PoWNonce = core.ComputePoWConcurrent(idBytes, difficulty, runtime.NumCPU())
}
// core/pow.go:56-60
func ComputePoWConcurrent(blockHash []byte, difficulty uint64, numWorkers int) uint64 {
nonce, _ := ComputePoWWithContext(context.Background(), blockHash, difficulty, numWorkers)
return nonce
}
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.
Rantai 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.)
PoC (terverifikasi, go test, lalu file test dihapus)
- Difficulty dari server diterima apa adanya (test sementara
client/chatdiff_poc_test.go, serverhttptestmengembalikan{"chat_pow_difficulty":"ffffffffffffffff"}):
=== RUN TestPoCChatDifficultyFromServerUnvalidated
server-advertised difficulty accepted as-is: 0xffffffffffffffff (no bound, no timeout downstream)
--- PASS (0.01s)
- PoW pada difficulty ekstrem tidak pernah kembali, sementara difficulty default kembali (test sementara
core/pow_poc_test.go):
=== RUN TestPoCComputePoWExtremeDifficultyHangs
default difficulty 0xfffff80000000000: nonce 12740108599032212017 in 2.588026385s
extreme difficulty 0xffffffffffffffff00: no nonce in 10s (expected ~2^56 tries); a caller with no timeout hangs indefinitely
--- PASS (12.66s)
Reproduksi 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.
Perbaikan yang disarankan
- Di
client.ChatPoWDifficulty()(atauchat.NewEnvelope): tolak difficulty di luar rentang yang wajar, mis.difficulty <= chat.DefaultPoWDifficultyatau batas atas eksplisit; kembalikan error, jangan lanjut ke PoW. - Beri timeout pada
ComputePoWConcurrentdi jalur chat (mis.ComputePoWWithContextdengan timeout beberapa detik dan error bila gagal), dan/atau validasichatDifficultysaat node start (node/node.go:217-220).
Thread
Opened pull request #412 addressing this vulnerability:
-
Upper Bound & Timeout Constants (
chat/envelope.go):- Established
MaxPoWDifficulty uint64 = 0xffffff0000000000to bound acceptable proof-of-work difficulty. - Introduced
DefaultPoWTimeout = 30 * time.SecondandErrDifficultyTooHigh. - Added
NewEnvelopeWithContext(ctx, ...)with timeout cancellation, and boundedNewEnvelope(...). - Added difficulty upper bound validation to
VerifyFull(difficulty).
- Established
-
Client Validation (
client/chat.go):ChatPoWDifficulty()now verifies the node-advertised difficulty againstchat.MaxPoWDifficultyand fails fast with a descriptive error before any computation begins.
-
CLI Context Awareness (
cmd/xe/chat.go):- Bounded
chatSendto a 30-second context timeout callingchat.NewEnvelopeWithContext.
- Bounded
-
Node Preflight Validation (
node/node.go):- Validates
chatDifficulty <= chat.MaxPoWDifficultyduring node initialization.
- Validates
-
Unit Tests:
- Added comprehensive tests in
chat/envelope_test.goandclient/chat_test.goverifying boundary conditions, timeout cancellation, and server advertisement parsing.
- Added comprehensive tests in
Thanks. This is the same finding as https://bounty.xe.network/XE-0703, 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-13270 and says what differs; it is read like any other.