<!-- XE-0080 · [SECURITY][Medium] DAO service - NUL byte in an inbox message causes an unhandled HTTP 500 · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0080>. The page is the record; this is the same page for reading.*

XE-0080 · Bounty

# \[SECURITY\]\[Medium\] DAO service \- NUL byte in an inbox message causes an unhandled HTTP 500

Awarded
Minorclaimed Medium
[xe#101](https://github.com/xeprotocol/xe/issues/101)
filed 2026-10-27 17:59 UTC
by targammm

Verdict
:   Valid

Tier
:   Minor

Claimed
:   Medium

Area
:   DAO harness

Duplicate of
:   —

Tracked
:   internally

Award
:   400 XE approved
    · ceiling 650

Updated
:   2026-11-11 15:12 UTC

Told
:   2026-10-30 08:22 UTC

### Patches

- [dao#1](https://github.com/xeprotocol/dao/pull/1)
- [dao@fd2b0d5f0e](https://github.com/xeprotocol/dao/commit/fd2b0d5f0ed1a3dbf0a11a9b33ce3cb7a1741c8d)

### History

- [2627](https://bounty.xe.network/log/2627) 2026-11-04 01:28 UTC github.labels
- [2625](https://bounty.xe.network/log/2625) 2026-11-04 01:27 UTC proposal.adopted
- [2624](https://bounty.xe.network/log/2624) 2026-11-04 01:27 UTC ticket.status patched → awarded
- [2623](https://bounty.xe.network/log/2623) 2026-11-04 01:27 UTC ticket.status accepted → patched
- [2622](https://bounty.xe.network/log/2622) 2026-11-04 01:27 UTC proposal.adopted
- [2621](https://bounty.xe.network/log/2621) 2026-11-04 01:27 UTC ticket.facts
- [2582](https://bounty.xe.network/log/2582) 2026-11-03 19:42 UTC proposal.created
- [2576](https://bounty.xe.network/log/2576) 2026-11-03 19:29 UTC proposal.created
- [2168](https://bounty.xe.network/log/2168) 2026-11-03 01:23 UTC github.labels
- [2154](https://bounty.xe.network/log/2154) 2026-11-03 01:22 UTC ticket.status awarded → accepted
- [2153](https://bounty.xe.network/log/2153) 2026-11-03 01:22 UTC ticket.facts
- [1150](https://bounty.xe.network/log/1150) 2026-10-31 11:14 UTC github.labels

[Full history](https://bounty.xe.network/log?ref=XE-0080) · [JSON](https://bounty.xe.network/v1/tickets/XE-0080) · [markdown](https://bounty.xe.network/XE-0080.md)

### Report

# \[SECURITY\] NUL byte in a DAO inbox message causes an unhandled HTTP 500

| Field | Value |
| --- | --- |
| **Severity** | Medium |
| **Area** | DAO service — HTTP API |
| **Component** | `dao/services/inbox.py` |
| **Status** | Live-verified against `https://dao.test.network` |
| **Date** | 2026-10-27 |

---

## 1\. Summary

`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.

> **Verified live.** Every request carrying a NUL byte returns 500 (3/3 attempts); the same request with a plain body returns 201\.

## 2\. Affected code

| File | Line | Issue |
| --- | --- | --- |
| `dao/services/inbox.py` | 64 | `body = (v.payload.get("message") or "").strip()` — length check only, no control-byte rejection |
| `dao/services/inbox.py` | 66–67 | Body written verbatim into `InboxMessage.body` (PostgreSQL `text`) |
| `dao/main.py` | 59–64 | Only `StarletteHTTPException` is handled; the asyncpg error is unhandled → 500 |
| `dao/settings.py` | 14 | `postgresql+asyncpg://…` — asyncpg rejects `U+0000` in text values |

## 3\. Reproduction

Self-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.

```
# repro.py — run: pip install pynacl && python3 repro.py
import json, hashlib, time, urllib.request, urllib.error
from nacl.signing import SigningKey

BASE   = "https://dao.test.network"
DOMAIN = b"xe-dao/inbox/v1\x00"          # dao/canonical.py: DOMAIN_INBOX_HTTP

def canonical_json(v):
    return json.dumps(v, sort_keys=True, separators=(",", ":"), ensure_ascii=True).encode()

def post(message):
    sk  = SigningKey.generate()
    pub = sk.verify_key.encode().hex()
    acct = hashlib.sha256(b"xe/account/v1" + bytes.fromhex(pub)).hexdigest()
    payload = {"message": message, "from_account": acct}
    ts = time.time_ns()
    digest = hashlib.sha256(DOMAIN + canonical_json({"payload": payload, "timestamp": ts})).digest()
    body = {"payload": payload, "timestamp": ts,
            "pub_key": pub, "signature": sk.sign(digest).signature.hex()}
    req = urllib.request.Request(BASE + "/v1/inbox", data=json.dumps(body).encode(),
                                 headers={"Content-Type": "application/json"}, method="POST")
    try:
        with urllib.request.urlopen(req, timeout=20) as r:
            return r.status
    except urllib.error.HTTPError as e:
        return e.code

print("NUL byte  ->", post("a\u0000b"))     # 500
print("plain     ->", post("hello world"))  # 201
print("C1 (U+009B) ->", post("a\u009bb"))   # 201  (not the trigger)
print("DEL (U+007F) ->", post("a\u007fb"))  # 201  (not the trigger)
```

**Observed:**

```
NUL byte  -> 500
plain     -> 201
C1 (U+009B) -> 201
DEL (U+007F) -> 201
```

The 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.

## 4\. Impact

- **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.
- **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.
- **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.

> **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.

## 5\. Suggested fix

1. 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")`.
2. 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\.
3. Apply the same guard to any other free-text field written to a `text` column (proposal title/body, notes, pause post).

## 6\. Duplicate check

- `xeprotocol/xe` issue tracker scanned (98 items, open \+ closed \+ PRs) on 2026-10-27.
- 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\.
- Issue **#49** covers unauthenticated inbox POST for lock contention — a different defect (hash-chain serialization), not input validation.
- No existing issue describes a NUL byte causing an HTTP 500 in the DAO service.

## 7\. Submission checklist (per programme "How to Report")

| Step | Requirement | Status |
| --- | --- | --- |
| 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. |
| 2 | GitHub issue with suggested severity tier and area | Tier: **Medium** · Area: **DAO service — HTTP API** |
| 3 | Clear PoC \+ impact analysis (who is affected, worst case) | Included — sections 3 and 4 |
| 4 | Critical/Severe goes to `security@xe.network` first | Not applicable — Medium is below Severe, so a public issue is the correct channel |
| 5 | Triage by the core team | Awaiting |
| 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) |

---

*Suggested tier: Medium (validation gap · inconsistent API response)*

### Thread

**arturbarszcz78**2026-10-28 05:48 UTCgithub

\[comment from a blocked account removed\]

**targammm**2026-10-28 06:50 UTCgithub

@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.

The 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.

Two notes for the maintainers on the patch itself, since it is useful work despite the above:

1. `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.
2. `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.
3. `dao/services/portal.py` — NUL is rejected on title/body, but the control-character check present in `http_submit` is not applied here.

Happy for the fix to land. The payout address for this report stays `d31bab17b9fd6635aa6cce191b4bea87e51d8ae8c93860537febe4294b01d05a`.

**Joseph Denne**2026-10-30 01:16 UTCgithub

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.

**josephdenne**team2026-10-30 08:08 UTCgithub

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.

**josephdenne**team2026-10-30 08:22 UTCgithub

This fix is now live on dao.test.network.
