<!-- XE-0252 · [SECURITY][Minor] SDK - memoBytes omits the node's control-byte rule, so a memo containing a NUL is signed and rejected at submit · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0252>. The page is the record; this is the same page for reading.*

XE-0252 · Bounty

# \[SECURITY\]\[Minor\] SDK \- memoBytes omits the node's control-byte rule, so a memo containing a NUL is signed and rejected at submit

Triaging
claimed Minor
web
filed 2026-11-02 16:38 UTC
by xe:8e7bb03e

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Minor

Area
:   SDK / docs / web

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-08 20:17 UTC

Told
:   2026-11-08 20:18 UTC

### Patches

None linked.

### History

- [43757](https://bounty.xe.network/log/43757) 2026-11-08 20:18 UTC proposal.adopted
- [43756](https://bounty.xe.network/log/43756) 2026-11-08 20:18 UTC reply.sent
- [43071](https://bounty.xe.network/log/43071) 2026-11-08 20:18 UTC proposal.adopted
- [43070](https://bounty.xe.network/log/43070) 2026-11-08 20:18 UTC proposal.adopted
- [43069](https://bounty.xe.network/log/43069) 2026-11-08 20:18 UTC ticket.facts
- [43068](https://bounty.xe.network/log/43068) 2026-11-08 20:18 UTC proposal.adopted
- [43067](https://bounty.xe.network/log/43067) 2026-11-08 20:18 UTC ticket.facts
- [43066](https://bounty.xe.network/log/43066) 2026-11-08 20:18 UTC proposal.adopted
- [43065](https://bounty.xe.network/log/43065) 2026-11-08 20:18 UTC ticket.facts
- [43064](https://bounty.xe.network/log/43064) 2026-11-08 20:18 UTC proposal.adopted
- [43063](https://bounty.xe.network/log/43063) 2026-11-08 20:18 UTC ticket.facts
- [43062](https://bounty.xe.network/log/43062) 2026-11-08 20:18 UTC proposal.adopted

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

### Report

# \[SECURITY\]\[Minor\] SDK \- memoBytes omits the node's control-byte rule, so a memo containing a NUL is signed and rejected at submit

| Field | Value |
| --- | --- |
| **Severity** | Minor |
| **Area** | SDK — block encoding |
| **Component** | `src/encoding.ts` (`memoBytes`) |
| **Version** | `xeprotocol/sdk` @ `0dbc92ecff709bee79768e4e37788c682a0f4525` (master, 2026-10-23) · `xeprotocol/xe` @ `978785929bc1` |
| **Status** | Reproduced (unit, deterministic) |
| **Date** | 2026-11-02 |
| **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. |

---

## 1\. Summary

The node accepts a memo only if it is valid UTF-8, at most 64 bytes, and free of control bytes: `core/memo.go`
rejects every byte `< 0x20` except TAB and LF, and `0x7F`. The SDK's memo validator implements the first two
rules and the unpaired-surrogate rule, but **not** the control-byte rule:

```
// src/encoding.ts:81-92
function memoBytes(memo: string | undefined): Uint8Array {
  if (!memo) return new Uint8Array(0)
  // A lone surrogate is not valid text. TextEncoder would quietly substitute
  // U+FFFD, so the bytes signed would not be the memo the caller passed.
  if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(memo)) {
    throw new XeUsageError('memo is not valid UTF-8: it contains an unpaired surrogate')
  }
  const bytes = new TextEncoder().encode(memo)
  if (bytes.length > MAX_MEMO_BYTES) {
    throw new XeUsageError(`memo too long: ${bytes.length} bytes (max ${MAX_MEMO_BYTES})`)
  }
  return bytes
}
```

So a caller who writes `memo: "invoice\u0000 42"` gets a block that the SDK encodes, signs and proof-of-works
successfully, and the node then rejects it with
`memo contains disallowed control byte 0x00 at offset 7`.

> **Trigger:** any memo containing C0 control bytes other than TAB/LF, or DEL (0x7F). A NUL is the common
> case — it is what a caller gets from `str.slice(0, idx)` over a NUL-separated buffer, from a JSON field that
> was meant to be empty, or from a pasted hex/CSV field.

## 2\. Affected code

| File | Line | Issue |
| --- | --- | --- |
| `src/encoding.ts` | 81–92 | `memoBytes` validates length and surrogates, but not control bytes |
| `src/encoding.ts` | 28 | `MAX_MEMO_BYTES = 64` — the length rule the SDK does implement |
| `src/encoding.ts` | 195 | `const memo = memoBytes(block.memo)` — the only memo gate before signing |
| `core/memo.go` | 10–30 | `ValidateMemo` — the node's rule: `c < 0x20 || c == 0x7F` (TAB/LF excepted) |
| `core/encoding.go` | 79 | `MarshalBlock` calls `ValidateMemo(b.Memo)` before hashing |
| `core/ledger.go` | 1008, 1061 | `validateAndAddSend` / `validateAndAddBurn` call `ValidateMemo(b.Memo)` |

## 3\. Reproduction

Deterministic — no network. The script encodes a `send` block with the SDK's own `marshalCanonical` and
compares it with a verbatim transcription of the node's `ValidateMemo`.

```
// repro-memo-control-byte.mjs
import { marshalCanonical } from './dist/index.js'

// verbatim from core/memo.go
function nodeValidateMemo(memo) {
  const bytes = new TextEncoder().encode(memo)
  if (bytes.length > 64) return 'REJECTED - memo too long'
  for (let i = 0; i < bytes.length; i++) {
    const c = bytes[i]
    if (c === 0x09 || c === 0x0a) continue
    if (c < 0x20 || c === 0x7f) {
      return `REJECTED - memo contains disallowed control byte 0x${c.toString(16).padStart(2, '0')} at offset ${i}`
    }
  }
  return 'accepted'
}

for (const [label, memo] of [
  ['plain', 'payment for invoice 42'],
  ['NUL',   'invoice' + String.fromCharCode(0x00) + '42'],
  ['BEL',   'invoice' + String.fromCharCode(0x07) + '42'],
  ['ESC',   'invoice' + String.fromCharCode(0x1b) + '42'],
  ['DEL',   'invoice' + String.fromCharCode(0x7f) + '42'],
  ['tab+LF','invoice' + String.fromCharCode(0x09) + String.fromCharCode(0x0a) + '42'],
]) {
  let sdk = 'threw'
  try {
    marshalCanonical({ type: 'send', account: ADDR, previous: HASH, balance: 1n,
                       timestamp: 2n, asset: 'XE', source: HASH, amount: 1n, memo })
    sdk = 'encoded'
  } catch (e) { sdk = 'threw: ' + e.message }
  console.log(label.padEnd(8), 'sdk:', sdk.padEnd(10), 'node:', nodeValidateMemo(memo))
}
```

**Observed:**

```
plain    sdk: encoded    node: accepted
NUL      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x00 at offset 7
BEL      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x07 at offset 7
ESC      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x1b at offset 7
DEL      sdk: encoded    node: REJECTED - memo contains disallowed control byte 0x7f at offset 7
tab+LF   sdk: encoded    node: accepted
```

Full script: `repro-memo-control-byte.mjs` (also prints the memo tail as it lands in the canonical hash). It
imports `marshalCanonical` from the **built** SDK (`sdk/dist/index.js`, built from
`0dbc92ecff709bee79768e4e37788c682a0f4525`) and is attached, together with its output.

## 4\. Impact

- **The transaction is rejected after the expensive part.** The SDK signs the block and solves the proof of
  work before the node ever sees the memo, so the caller pays the PoW cost and then gets a 400\.
- **The error points at the wrong thing.** `XeApiError` from the node surfaces as a server-side rejection of
  the whole block, with no hint that the memo was the problem — the caller has to read the node's message.
- **A memo that "looks empty" to a caller can fail.** A NUL-terminated string read out of a binary buffer
  carries the NUL into the memo, and the SDK accepts it silently.
- **No funds are at risk.** The block never enters the ledger; the balance and the escrow are untouched. The
  cost is a wasted PoW solve and a confusing error.

> **Honest boundary:** this is a validation gap in the client's own input checks. It costs a rejected
> transaction and a wasted proof-of-work solve; it does not lose funds, bypass a consensus rule, or let an
> unprivileged actor degrade the network. That places it at Minor, not Medium — even though "validation gap"
> appears in the Medium list, the *impact* here is a 400, not an accounting or consensus defect.

## 5\. Why the test suite misses it

`test/unit/encoding.test.ts` has a `describe('memo rules')` block (line 64\) and a
`describe('memo text validity')` block (line 112). Between them they cover: a memo on a non-send block, the
64-byte limit, UTF-8 byte counting, the unpaired-surrogate rule, and that an emoji is accepted. There is no
case with a control byte — because the SDK has no control-byte rule to test.

## 6\. Suggested fix

1. Add the node's rule to `memoBytes`: reject any byte `< 0x20` except TAB (`0x09`) and LF (`0x0A`), and
   `0x7F`, with a message in the SDK's existing style, e.g.
   `memo contains a disallowed control byte 0x00 at offset 7`.
2. Check the **encoded bytes**, not the JS string — the node indexes raw bytes.
3. Add a regression test per control byte class (NUL, BEL, ESC, DEL) next to the existing surrogate tests, and
   one asserting that TAB and LF still pass.

> Note for the maintainer: issue #10 (Finding 4\) proposes making the node's `ValidateMemo` *stricter* by
> switching to rune-based `unicode.IsControl` \+ `unicode.Cf`, which would additionally reject C1 controls
> (U\+0080–U\+009F), bidi overrides and zero-width characters. If that lands, the SDK gap widens rather than
> closes, and a rune-based SDK check would be the better fix. A byte-level check as in (1) is still correct
> against the node as it stands today.

## 7\. Duplicate check

- `xeprotocol/sdk`: **0 issues, 14 PRs** (fetched 2026-11-02). No PR or issue mentions memo control bytes,
  `memoBytes`, or the node's `ValidateMemo` rule. PR #10 (`stringifyWithBigInts` marker collision) is a
  different defect in `src/json.ts`.
- `xeprotocol/xe`: **236 issues \+ PRs**, all fetched and searched 2026-11-02. The only memo-related entries
  are **#10** (node-side `ValidateMemo`, C1/bidi injection — see the note in §6), **#101** (DAO service NUL
  byte → HTTP 500, a different component), **#16** / **#194** (the `stringifyWithBigInts` sentinel collision).
  None is the SDK's memo validation.
- XE bounty desk: all **113 published tickets** searched 2026-11-02 — 0 hits for "control byte"; the memo
  hits are XE-0003 (\= upstream #10), XE-0008 and XE-0115 (both the `stringifyWithBigInts` sentinel).

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

| Step | Requirement | Status |
| --- | --- | --- |
| 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`. |
| 2 | GitHub issue with suggested severity tier and area | Tier: **Minor** · Area: **SDK — block encoding** |
| 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 — Minor 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 | `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)` |

---

*Suggested tier: Minor (650 XE) — input-validation gap in the client; the transaction is rejected, no funds at risk*

### Thread

**Joseph Denne**team2026-11-08 20:17 UTCdesk

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.
