{"id":"XE-0252","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":68,"title":"[SECURITY][Minor] SDK - memoBytes omits the node's control-byte rule, so a memo containing a NUL is signed and rejected at submit","area":"sdk-docs-web","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-02T16:38:58.145058+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":null,"told_at":"2026-11-08T20:18:49.852780+00:00","status_changed_at":"2026-11-08T20:18:33.681196+00:00","url":"https://bounty.xe.network/XE-0252","body":"# [SECURITY][Minor] SDK - memoBytes omits the node's control-byte rule, so a memo containing a NUL is signed and rejected at submit\r\n\r\n| Field | Value |\r\n|---|---|\r\n| **Severity** | Minor |\r\n| **Area** | SDK — block encoding |\r\n| **Component** | `src/encoding.ts` (`memoBytes`) |\r\n| **Version** | `xeprotocol/sdk` @ `0dbc92ecff709bee79768e4e37788c682a0f4525` (master, 2026-10-23) · `xeprotocol/xe` @ `978785929bc1` |\r\n| **Status** | Reproduced (unit, deterministic) |\r\n| **Date** | 2026-11-02 |\r\n| **Reporter** | Desk web account `xe:64e3ca3f…0cd4` (reporter id 68) — the same person who filed XE-0077 / XE-0078 / XE-0080 under the GitHub login `targammm` (reporter id 30). Please merge the two records so the award history is attributed once. |\r\n\r\n---\r\n\r\n## 1. Summary\r\n\r\nThe node accepts a memo only if it is valid UTF-8, at most 64 bytes, and free of control bytes: `core/memo.go`\r\nrejects every byte `< 0x20` except TAB and LF, and `0x7F`. The SDK's memo validator implements the first two\r\nrules and the unpaired-surrogate rule, but **not** the control-byte rule:\r\n\r\n```typescript\r\n// src/encoding.ts:81-92\r\nfunction memoBytes(memo: string | undefined): Uint8Array {\r\n  if (!memo) return new Uint8Array(0)\r\n  // A lone surrogate is not valid text. TextEncoder would quietly substitute\r\n  // U+FFFD, so the bytes signed would not be the memo the caller passed.\r\n  if (/[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]/.test(memo)) {\r\n    throw new XeUsageError('memo is not valid UTF-8: it contains an unpaired surrogate')\r\n  }\r\n  const bytes = new TextEncoder().encode(memo)\r\n  if (bytes.length > MAX_MEMO_BYTES) {\r\n    throw new XeUsageError(`memo too long: ${bytes.length} bytes (max ${MAX_MEMO_BYTES})`)\r\n  }\r\n  return bytes\r\n}\r\n```\r\n\r\nSo a caller who writes `memo: \"invoice\\u0000 42\"` gets a block that the SDK encodes, signs and proof-of-works\r\nsuccessfully, and the node then rejects it with\r\n`memo contains disallowed control byte 0x00 at offset 7`.\r\n\r\n> **Trigger:** any memo containing C0 control bytes other than TAB/LF, or DEL (0x7F). A NUL is the common\r\n> case — it is what a caller gets from `str.slice(0, idx)` over a NUL-separated buffer, from a JSON field that\r\n> was meant to be empty, or from a pasted hex/CSV field.\r\n\r\n## 2. Affected code\r\n\r\n| File | Line | Issue |\r\n|---|---|---|\r\n| `src/encoding.ts` | 81–92 | `memoBytes` validates length and surrogates, but not control bytes |\r\n| `src/encoding.ts` | 28 | `MAX_MEMO_BYTES = 64` — the length rule the SDK does implement |\r\n| `src/encoding.ts` | 195 | `const memo = memoBytes(block.memo)` — the only memo gate before signing |\r\n| `core/memo.go` | 10–30 | `ValidateMemo` — the node's rule: `c < 0x20 \\|\\| c == 0x7F` (TAB/LF excepted) |\r\n| `core/encoding.go` | 79 | `MarshalBlock` calls `ValidateMemo(b.Memo)` before hashing |\r\n| `core/ledger.go` | 1008, 1061 | `validateAndAddSend` / `validateAndAddBurn` call `ValidateMemo(b.Memo)` |\r\n\r\n## 3. Reproduction\r\n\r\nDeterministic — no network. The script encodes a `send` block with the SDK's own `marshalCanonical` and\r\ncompares it with a verbatim transcription of the node's `ValidateMemo`.\r\n\r\n```javascript\r\n// repro-memo-control-byte.mjs\r\nimport { marshalCanonical } from './dist/index.js'\r\n\r\n// verbatim from core/memo.go\r\nfunction nodeValidateMemo(memo) {\r\n  const bytes = new TextEncoder().encode(memo)\r\n  if (bytes.length > 64) return 'REJECTED - memo too long'\r\n  for (let i = 0; i < bytes.length; i++) {\r\n    const c = bytes[i]\r\n    if (c === 0x09 || c === 0x0a) continue\r\n    if (c < 0x20 || c === 0x7f) {\r\n      return `REJECTED - memo contains disallowed control byte 0x${c.toString(16).padStart(2, '0')} at offset ${i}`\r\n    }\r\n  }\r\n  return 'accepted'\r\n}\r\n\r\nfor (const [label, memo] of [\r\n  ['plain', 'payment for invoice 42'],\r\n  ['NUL',   'invoice' + String.fromCharCode(0x00) + '42'],\r\n  ['BEL',   'invoice' + String.fromCharCode(0x07) + '42'],\r\n  ['ESC',   'invoice' + String.fromCharCode(0x1b) + '42'],\r\n  ['DEL',   'invoice' + String.fromCharCode(0x7f) + '42'],\r\n  ['tab+LF','invoice' + String.fromCharCode(0x09) + String.fromCharCode(0x0a) + '42'],\r\n]) {\r\n  let sdk = 'threw'\r\n  try {\r\n    marshalCanonical({ type: 'send', account: ADDR, previous: HASH, balance: 1n,\r\n                       timestamp: 2n, asset: 'XE', source: HASH, amount: 1n, memo })\r\n    sdk = 'encoded'\r\n  } catch (e) { sdk = 'threw: ' + e.message }\r\n  console.log(label.padEnd(8), 'sdk:', sdk.padEnd(10), 'node:', nodeValidateMemo(memo))\r\n}\r\n```\r\n\r\n**Observed:**\r\n\r\n```\r\nplain    sdk: encoded    node: accepted\r\nNUL      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x00 at offset 7\r\nBEL      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x07 at offset 7\r\nESC      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x1b at offset 7\r\nDEL      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x7f at offset 7\r\ntab+LF   sdk: encoded    node: accepted\r\n```\r\n\r\nFull script: `repro-memo-control-byte.mjs` (also prints the memo tail as it lands in the canonical hash). It\r\nimports `marshalCanonical` from the **built** SDK (`sdk/dist/index.js`, built from\r\n`0dbc92ecff709bee79768e4e37788c682a0f4525`) and is attached, together with its output.\r\n\r\n## 4. Impact\r\n\r\n- **The transaction is rejected after the expensive part.** The SDK signs the block and solves the proof of\r\n  work before the node ever sees the memo, so the caller pays the PoW cost and then gets a 400.\r\n- **The error points at the wrong thing.** `XeApiError` from the node surfaces as a server-side rejection of\r\n  the whole block, with no hint that the memo was the problem — the caller has to read the node's message.\r\n- **A memo that \"looks empty\" to a caller can fail.** A NUL-terminated string read out of a binary buffer\r\n  carries the NUL into the memo, and the SDK accepts it silently.\r\n- **No funds are at risk.** The block never enters the ledger; the balance and the escrow are untouched. The\r\n  cost is a wasted PoW solve and a confusing error.\r\n\r\n> **Honest boundary:** this is a validation gap in the client's own input checks. It costs a rejected\r\n> transaction and a wasted proof-of-work solve; it does not lose funds, bypass a consensus rule, or let an\r\n> unprivileged actor degrade the network. That places it at Minor, not Medium — even though \"validation gap\"\r\n> appears in the Medium list, the *impact* here is a 400, not an accounting or consensus defect.\r\n\r\n## 5. Why the test suite misses it\r\n\r\n`test/unit/encoding.test.ts` has a `describe('memo rules')` block (line 64) and a\r\n`describe('memo text validity')` block (line 112). Between them they cover: a memo on a non-send block, the\r\n64-byte limit, UTF-8 byte counting, the unpaired-surrogate rule, and that an emoji is accepted. There is no\r\ncase with a control byte — because the SDK has no control-byte rule to test.\r\n\r\n## 6. Suggested fix\r\n\r\n1. Add the node's rule to `memoBytes`: reject any byte `< 0x20` except TAB (`0x09`) and LF (`0x0A`), and\r\n   `0x7F`, with a message in the SDK's existing style, e.g.\r\n   `memo contains a disallowed control byte 0x00 at offset 7`.\r\n2. Check the **encoded bytes**, not the JS string — the node indexes raw bytes.\r\n3. Add a regression test per control byte class (NUL, BEL, ESC, DEL) next to the existing surrogate tests, and\r\n   one asserting that TAB and LF still pass.\r\n\r\n> Note for the maintainer: issue #10 (Finding 4) proposes making the node's `ValidateMemo` *stricter* by\r\n> switching to rune-based `unicode.IsControl` + `unicode.Cf`, which would additionally reject C1 controls\r\n> (U+0080–U+009F), bidi overrides and zero-width characters. If that lands, the SDK gap widens rather than\r\n> closes, and a rune-based SDK check would be the better fix. A byte-level check as in (1) is still correct\r\n> against the node as it stands today.\r\n\r\n## 7. Duplicate check\r\n\r\n- `xeprotocol/sdk`: **0 issues, 14 PRs** (fetched 2026-11-02). No PR or issue mentions memo control bytes,\r\n  `memoBytes`, or the node's `ValidateMemo` rule. PR #10 (`stringifyWithBigInts` marker collision) is a\r\n  different defect in `src/json.ts`.\r\n- `xeprotocol/xe`: **236 issues + PRs**, all fetched and searched 2026-11-02. The only memo-related entries\r\n  are **#10** (node-side `ValidateMemo`, C1/bidi injection — see the note in §6), **#101** (DAO service NUL\r\n  byte → HTTP 500, a different component), **#16** / **#194** (the `stringifyWithBigInts` sentinel collision).\r\n  None is the SDK's memo validation.\r\n- XE bounty desk: all **113 published tickets** searched 2026-11-02 — 0 hits for \"control byte\"; the memo\r\n  hits are XE-0003 (= upstream #10), XE-0008 and XE-0115 (both the `stringifyWithBigInts` sentinel).\r\n\r\n## 8. Submission checklist (per programme \"How to Report\")\r\n\r\n| Step | Requirement | Status |\r\n|---|---|---|\r\n| 1 | Reproduce against testnet; capture tx hashes / block heights | Reproduced locally and deterministically: the SDK encodes all four control-byte memos and the node's own rule rejects each. Not submitted to the live testnet — the block would be rejected by design, so there is no accepted tx to cite. The comparison is byte-for-byte against `core/memo.go`. |\r\n| 2 | GitHub issue with suggested severity tier and area | Tier: **Minor** · Area: **SDK — block encoding** |\r\n| 3 | Clear PoC + impact analysis (who is affected, worst case) | Included — sections 3 and 4 |\r\n| 4 | Critical/Severe goes to `security@xe.network` first | Not applicable — Minor is below Severe, so a public issue is the correct channel |\r\n| 5 | Triage by the core team | Awaiting |\r\n| 6 | XE address for payout at genesis | `64e3ca3f6e9378cd549032de9f087b5496fd4100516c7bdb46c17b00d4220cd4` — XE native chain (block lattice, ed25519), derived from the reporter's recovery phrase via BIP39 → SLIP-0010 ed25519 `m/44'/1'/account'`; address = `sha256(\"xe/account/v1\" ‖ pubkey)` |\r\n\r\n---\r\n\r\n*Suggested tier: Minor (650 XE) — input-validation gap in the client; the transaction is rejected, no funds at risk*","patch_refs":[],"thread":[{"id":1154,"source":"desk","source_ref":"reply:706","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have confirmed the validation gap you describe in the SDK and it is being handled; we will update https://bounty.xe.network/XE-0252 when there is a fix to point at. Account changes on the desk are handled separately through the desk itself rather than from a report body.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}