Bounty
XE-13270 · Bounty

[Medium] xe chat send trusts server-advertised PoW difficulty with no bound and no timeout — malicious node pins operator CPU forever

Closed · duplicate —claimed Medium xe#397 filed 2026-11-11 15:41 UTC by DICKY KUSUMA WARDHANI

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 ke chat.NewEnvelope
    • chat/envelope.go:78-80 — NewEnvelope(..., difficulty) memanggil core.ComputePoWConcurrent(idBytes, difficulty, runtime.NumCPU())
    • core/pow.go:56-60,72-74 — ComputePoWConcurrent memakai context.Background() (tanpa timeout); ValidatePoW (core/pow.go:41-43) menerima bila powHash >= difficulty
    • cmd/xe/main.go:219-224 — nodeURL() default https://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 ("solvePow accepts out-of-range difficulty and short hashes, returning nonces that fail validatePow — 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 /node yang tidak terautentikasi, tanpa timeout/cancel di sisi pemanggil. Tidak ada tiket untuk jalur Go ini.

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)

  1. Difficulty dari server diterima apa adanya (test sementara client/chatdiff_poc_test.go, server httptest mengembalikan {"chat_pow_difficulty":"ffffffffffffffff"}):
=== RUN   TestPoCChatDifficultyFromServerUnvalidated
    server-advertised difficulty accepted as-is: 0xffffffffffffffff (no bound, no timeout downstream)
--- PASS (0.01s)
  1. 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() (atau chat.NewEnvelope): tolak difficulty di luar rentang yang wajar, mis. difficulty <= chat.DefaultPoWDifficulty atau batas atas eksplisit; kembalikan error, jangan lanjut ke PoW.
  • 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).

Thread

kleitonbernardino-lab2026-11-11 21:29 UTCgithub

Opened pull request #412 addressing this vulnerability:

  1. Upper Bound & Timeout Constants (chat/envelope.go):

    • Established MaxPoWDifficulty uint64 = 0xffffff0000000000 to bound acceptable proof-of-work difficulty.
    • Introduced DefaultPoWTimeout = 30 * time.Second and ErrDifficultyTooHigh.
    • Added NewEnvelopeWithContext(ctx, ...) with timeout cancellation, and bounded NewEnvelope(...).
    • Added difficulty upper bound validation to VerifyFull(difficulty).
  2. Client Validation (client/chat.go):

    • ChatPoWDifficulty() now verifies the node-advertised difficulty against chat.MaxPoWDifficulty and fails fast with a descriptive error before any computation begins.
  3. CLI Context Awareness (cmd/xe/chat.go):

    • Bounded chatSend to a 30-second context timeout calling chat.NewEnvelopeWithContext.
  4. Node Preflight Validation (node/node.go):

    • Validates chatDifficulty <= chat.MaxPoWDifficulty during node initialization.
  5. Unit Tests:

    • Added comprehensive tests in chat/envelope_test.go and client/chat_test.go verifying boundary conditions, timeout cancellation, and server advertisement parsing.
Joseph Denneteam2026-11-20 00:05 UTCgithub

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.