{"id":"XE-0080","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"101","source_url":"https://github.com/xeprotocol/xe/issues/101","reporter_id":30,"title":"[SECURITY][Medium] DAO service - NUL byte in an inbox message causes an unhandled HTTP 500","area":"dao-harness","claimed_tier":"medium","assessed_tier":"minor","verdict":"valid","duplicate_of":null,"tracked":true,"internal_ref":"#1074","internal_url":"https://github.com/xeprotocol/core/issues/1074","status":"awarded","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":400000000,"award_approved":true,"paid_ref":"","created_at":"2026-10-29T13:57:22.962116+00:00","updated_at":"2026-11-11T15:12:16.507996+00:00","source_created_at":"2026-10-27T17:59:45+00:00","told_at":"2026-10-30T08:22:01+00:00","status_changed_at":"2026-11-04T01:27:27.255921+00:00","url":"https://bounty.xe.network/XE-0080","body":"# [SECURITY] NUL byte in a DAO inbox message causes an unhandled HTTP 500\n\n| Field | Value |\n|---|---|\n| **Severity** | Medium |\n| **Area** | DAO service — HTTP API |\n| **Component** | `dao/services/inbox.py` |\n| **Status** | Live-verified against `https://dao.test.network` |\n| **Date** | 2026-10-27 |\n\n---\n\n## 1. Summary\n\n`POST /v1/inbox` accepts a signed message whose `message` field is stored verbatim as the inbox body. The handler validates length only — it never rejects or strips control bytes. A single `U+0000` (NUL) anywhere in the body reaches PostgreSQL through `asyncpg`, which refuses NUL in a `text` column. The resulting driver exception is not caught by any handler in the DAO app, so the request fails with a bare **HTTP 500 Internal Server Error** instead of a typed 4xx.\n\n> **Verified live.** Every request carrying a NUL byte returns 500 (3/3 attempts); the same request with a plain body returns 201.\n\n## 2. Affected code\n\n| File | Line | Issue |\n|---|---|---|\n| `dao/services/inbox.py` | 64 | `body = (v.payload.get(\"message\") or \"\").strip()` — length check only, no control-byte rejection |\n| `dao/services/inbox.py` | 66–67 | Body written verbatim into `InboxMessage.body` (PostgreSQL `text`) |\n| `dao/main.py` | 59–64 | Only `StarletteHTTPException` is handled; the asyncpg error is unhandled → 500 |\n| `dao/settings.py` | 14 | `postgresql+asyncpg://…` — asyncpg rejects `U+0000` in text values |\n\n## 3. Reproduction\n\nSelf-contained — generates a fresh ed25519 key (no seat required; the endpoint accepts any validly signed request), signs the inbox payload, posts a body containing a NUL byte.\n\n```python\n# repro.py — run: pip install pynacl && python3 repro.py\nimport json, hashlib, time, urllib.request, urllib.error\nfrom nacl.signing import SigningKey\n\nBASE   = \"https://dao.test.network\"\nDOMAIN = b\"xe-dao/inbox/v1\\x00\"          # dao/canonical.py: DOMAIN_INBOX_HTTP\n\ndef canonical_json(v):\n    return json.dumps(v, sort_keys=True, separators=(\",\", \":\"), ensure_ascii=True).encode()\n\ndef post(message):\n    sk  = SigningKey.generate()\n    pub = sk.verify_key.encode().hex()\n    acct = hashlib.sha256(b\"xe/account/v1\" + bytes.fromhex(pub)).hexdigest()\n    payload = {\"message\": message, \"from_account\": acct}\n    ts = time.time_ns()\n    digest = hashlib.sha256(DOMAIN + canonical_json({\"payload\": payload, \"timestamp\": ts})).digest()\n    body = {\"payload\": payload, \"timestamp\": ts,\n            \"pub_key\": pub, \"signature\": sk.sign(digest).signature.hex()}\n    req = urllib.request.Request(BASE + \"/v1/inbox\", data=json.dumps(body).encode(),\n                                 headers={\"Content-Type\": \"application/json\"}, method=\"POST\")\n    try:\n        with urllib.request.urlopen(req, timeout=20) as r:\n            return r.status\n    except urllib.error.HTTPError as e:\n        return e.code\n\nprint(\"NUL byte  ->\", post(\"a\\u0000b\"))     # 500\nprint(\"plain     ->\", post(\"hello world\"))  # 201\nprint(\"C1 (U+009B) ->\", post(\"a\\u009bb\"))   # 201  (not the trigger)\nprint(\"DEL (U+007F) ->\", post(\"a\\u007fb\"))  # 201  (not the trigger)\n```\n\n**Observed:**\n\n```\nNUL byte  -> 500\nplain     -> 201\nC1 (U+009B) -> 201\nDEL (U+007F) -> 201\n```\n\nThe failure is specific to `U+0000`. Other control bytes (C1 `U+009B`, DEL `U+007F`) are accepted and return 201 — consistent with PostgreSQL permitting them but rejecting NUL in a `text` value.\n\n## 4. Impact\n\n- **Unhandled server error on a public, unauthenticated-to-reach endpoint.** `POST /v1/inbox` requires only a self-generated keypair — no seat, no allow-list, no proof-of-work (`pow_nonce=0`). Any client can trigger a 500 at will.\n- **Response-contract violation.** The API documents typed JSON errors (`{\"error\": …, \"status\": …}`). A 500 returns an HTML/plain error body instead, breaking clients that rely on the documented shape.\n- **No state corruption or DoS.** The transaction rolls back cleanly; the service stays healthy (health and inbox endpoints stay 200 after repeated triggers), and no NUL is persisted. Impact is bounded to a failed request and a 500 in the logs.\n\n> **Honest boundary:** this is a robustness / input-validation defect, not a funds or consensus issue. It is not a denial of service — the process recovers per request.\n\n## 5. Suggested fix\n\n1. Reject or strip control bytes in `http_submit` before the DB write, e.g. `if any(ord(c) < 0x20 and c not in \"\\t\\n\" for c in body): raise HTTPException(400, \"message contains a disallowed control character\")`.\n2. Add a catch-all handler (or a DB-layer wrapper) so a driver error surfaces as a typed `400/503` JSON error rather than an unhandled 500.\n3. Apply the same guard to any other free-text field written to a `text` column (proposal title/body, notes, pause post).\n\n## 6. Duplicate check\n\n- `xeprotocol/xe` issue tracker scanned (98 items, open + closed + PRs) on 2026-10-27.\n- Issue **#10** covers C1/bidi control bytes but in **Go `core/memo.go`** (block memo validation) — different component, different layer, and it does not cover the DAO Python inbox path or the NUL → PostgreSQL 500.\n- Issue **#49** covers unauthenticated inbox POST for lock contention — a different defect (hash-chain serialization), not input validation.\n- No existing issue describes a NUL byte causing an HTTP 500 in the DAO service.\n\n\n## 7. Submission checklist (per programme \"How to Report\")\n\n| Step | Requirement | Status |\n|---|---|---|\n| 1 | Reproduce against testnet; capture tx hashes / block heights | Live-verified against `https://dao.test.network`, 3/3 consistent. No tx hash exists for this finding: the request is rejected before any block is written, so there is no transaction to cite. The failure is observable directly from the HTTP response code and the reproduction script above is deterministic. |\n| 2 | GitHub issue with suggested severity tier and area | Tier: **Medium** · Area: **DAO service — HTTP API** |\n| 3 | Clear PoC + impact analysis (who is affected, worst case) | Included — sections 3 and 4 |\n| 4 | Critical/Severe goes to `security@xe.network` first | Not applicable — Medium is below Severe, so a public issue is the correct channel |\n| 5 | Triage by the core team | Awaiting |\n| 6 | XE address for payout at genesis | `d31bab17b9fd6635aa6cce191b4bea87e51d8ae8c93860537febe4294b01d05a` — XE native chain (block lattice, ed25519), BIP39 24-word + SLIP-0010 ed25519 m/44'/1'/account'; backup phrase in `xe-payout-wallet.secret` (0600) |\n\n---\n\n*Suggested tier: Medium (validation gap · inconsistent API response)*","patch_refs":[{"id":198,"repo":"xeprotocol/dao","kind":"pr","ref":"1","title":"","url":"https://github.com/xeprotocol/dao/pull/1","note":"","state":"","author":"","added_by":"desk","created_at":"2026-10-29T14:22:09.061497+00:00"},{"id":217,"repo":"xeprotocol/dao","kind":"commit","ref":"fd2b0d5f0ed1a3dbf0a11a9b33ce3cb7a1741c8d","title":"","url":"https://github.com/xeprotocol/dao/commit/fd2b0d5f0ed1a3dbf0a11a9b33ce3cb7a1741c8d","note":"","state":"","author":"","added_by":"token:5","created_at":"2026-10-30T01:39:16.472841+00:00"}],"thread":[{"id":28,"source":"github","source_ref":"6461749030","author":"arturbarszcz78","team":false,"body":"[comment from a blocked account removed]","created_at":"2026-10-28T05:48:34+00:00"},{"id":29,"source":"github","source_ref":"6462658663","author":"targammm","team":false,"body":"@arturbarszcz78 — this issue and its PoC were filed by me on 2026-10-27 17:59:45Z; the report body already carries the XE payout address for this finding. Per the programme rules, duplicate reports go to the first verifiable submission, and the report is the submission — not the patch.\n\nThe patch is welcome, but the beneficiary claim on this issue is not yours to make. Please remove the beneficiary wallet from this thread and from xeprotocol/dao#1, and file your own report if you have an original finding.\n\nTwo notes for the maintainers on the patch itself, since it is useful work despite the above:\n\n1. `dao/services/inbox.py` — `store_envelope` strips NUL instead of rejecting it, so the p2p chat path still accepts the byte; only `http_submit` rejects. The two paths should agree.\n2. `dao/main.py` — the new catch-all handler returns `str(exc)` to `/v1` clients, which discloses internal driver error text. The programme lists verbose errors as their own Medium-tier class; returning a generic message and logging the detail server-side would be the safer shape.\n3. `dao/services/portal.py` — NUL is rejected on title/body, but the control-character check present in `http_submit` is not applied here.\n\nHappy for the fix to land. The payout address for this report stays `d31bab17b9fd6635aa6cce191b4bea87e51d8ae8c93860537febe4294b01d05a`.","created_at":"2026-10-28T06:50:38+00:00"},{"id":59,"source":"github","source_ref":"6512509926","author":"Joseph Denne","team":false,"body":"Thanks, confirmed: a NUL byte in the message reaches the database driver and the error is not caught, so the endpoint answers a bare 500. Nothing is stored and the service is unaffected. The fix rejects control characters at every free-text input, chat included, and makes any unhandled error answer in the documented JSON shape without driver text. The third-party pull request on the dao repository is useful but will be revised on those points before anything merges; the report on this issue is the submission of record.","created_at":"2026-10-30T01:16:26+00:00"},{"id":64,"source":"github","source_ref":"6518126094","author":"josephdenne","team":true,"body":"Fix is on main: https://github.com/xeprotocol/dao/commit/fd2b0d5f0ed1a3dbf0a11a9b33ce3cb7a1741c8d. Deploying to dao.test.network next; this issue will be updated once it is live.","created_at":"2026-10-30T08:08:48+00:00"},{"id":68,"source":"github","source_ref":"6518392289","author":"josephdenne","team":true,"body":"This fix is now live on dao.test.network.","created_at":"2026-10-30T08:22:01+00:00"}]}