fix(coord): refuse a control character in --to instead of sanitizing it

--to is the only line-oriented field sanitize_field never covered, and the
fix is a refusal rather than a sanitize pass because --to is also the
destination DIRECTORY name ($COORD/$TO/inbox, and $COORD/$TO/orders in
coord-order-send.sh). Collapsing a newline to a space would deliver the
message to a mailbox the sender never named - the same misdelivery the
retired ktg-plugin-marketplace address is rejected rather than redirected
to avoid.

Both corruptions were measured on the live engine first, each with exit 0
and a "delivered" line:

  --to "x\nreply-expected: no"  the injected line lands INSIDE the
      frontmatter block, above the reply-expected: yes the engine itself
      wrote, so coord-count reads owed=0 and the declared debt is silenced -
      defeating coord-count's own rule that only the frontmatter block may
      speak, since the injected line IS in the block.
  --to "tabbed<TAB>repo"        coord-count prints five tab-separated fields
      where its contract is four, so a consumer reads the mailbox name as the
      part before the tab and the pending count as the part after.

board.sh consumes that TSV, so both reach the board.

The guard sits after reply-mode resolution: --reply-to takes its target from
the original's from: line, untrusted cross-repo input, and that is the one
target name nobody typed.

Denominator measured rather than assumed: two scripts build a directory from
a caller-supplied name, and coord-order-send.sh had the identical defect,
where it costs more - an order filed under a name no session can hold is the
silent evaporation the ownership chain exists to prevent, while board.sh's
ORDRE column counts the intended repo's queue and stays 0 with nothing
reporting a failure. The read-side --repo arguments resolve an EXISTING
directory, so a control character there finds nothing and writes nothing;
checked and left alone.

Closes finding 7 of docs/2026-08-14-confident-zero-review.md.

Tests (red first, both suites): coord-selftest section 35 (10 checks) and
orders-selftest section 10 (6 checks), each with the mandatory
known-positive controls - an ordinary name still delivers, and so does a
dot-prefixed one, since a dot name is a real repo. coord 230/230, board
252/252, route 69/69, orders 110/110, guard 40/40, npm test 11/11.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AgKcURiXwGKhqCKhwD1NAp
This commit is contained in:
Kjell Tore Guttormsen 2026-08-18 17:00:34 +02:00
commit 29a94dd7e4
5 changed files with 171 additions and 6 deletions

View file

@ -16,7 +16,7 @@ marketplace plugin. Three components, one boundary:
`coord-done.sh` archives, `coord-count.sh` counts without delivering,
`coord-sweep.sh` closes the aged FYI backlog machine-wide.
Everything is pinned by `coord-selftest.sh`
(220 checks, throwaway mailbox via `CLAUDE_COORD_DIR`).
(230 checks, throwaway mailbox via `CLAUDE_COORD_DIR`).
**`ktg-plugin-marketplace` is a RETIRED `--to` address (operator decision
2026-08-15), rejected rather than redirected.** It is a polyrepo directory,
@ -49,6 +49,37 @@ marketplace plugin. Three components, one boundary:
four cases (fails outright / exits 0 without moving / real happy path /
archive-path reply).
**`--to` is the one line-oriented field that is REFUSED rather than
sanitized, and the asymmetry with `--from`/`--subject` is the whole point.**
A target name is also the destination DIRECTORY name (`$COORD/$TO/inbox`,
and `$COORD/$TO/orders` in `coord-order-send.sh`), so collapsing a control
character to a space the way `sanitize_field` does everywhere else would
deliver the message to a mailbox the sender never named - the same
misdelivery the retired `ktg-plugin-marketplace` address is rejected rather
than redirected to avoid. Both corruptions were measured on the live engine
before the guard existed, each with exit 0 and a "delivered" line: a newline
lands its payload INSIDE the frontmatter block, above the `reply-expected:
yes` the engine itself wrote, so `coord-count` reads `owed=0` and the debt
the engine declared is silenced (defeating its own rule that only the
frontmatter block may speak - the injected line IS in the block); a tab makes
`coord-count` print FIVE tab-separated fields where its contract is four, so
a consumer reads the mailbox name as the part before the tab and its pending
count as the part after. `board.sh` consumes that TSV. The guard sits AFTER
reply-mode resolution because `--reply-to` takes the target from the
original's `from:` line - untrusted cross-repo input this repo did not write,
and the one target name nobody typed. The denominator was measured rather
than assumed: two scripts build a directory from a caller-supplied name, and
`coord-order-send.sh` had the identical defect, where it costs more - an
order filed under a name no session can hold is exactly the silent
evaporation the ownership chain exists to prevent, while `board.sh`'s ORDRE
column counts the INTENDED repo's queue and stays 0 with nothing reporting a
failure. The read-side `--repo` arguments were checked and left alone: they
resolve an EXISTING directory, so a control character there finds nothing and
writes nothing. Both selftests carry the mandatory known-positive controls -
an ordinary name still delivers, and so does a dot-prefixed one, since
`coord-send.sh`'s own guard comment protects dot names as real repos
(`basename` of a git toplevel under a hidden directory).
**`coord-sweep.sh` is the only path that closes a message with no human in
the loop, and every constraint on it follows from that.** It may close exactly
one mechanically decidable class - `reply-expected: no`, older than the grace
@ -82,7 +113,7 @@ marketplace plugin. Three components, one boundary:
mailbox, `~/.claude/coord/<repo>/orders/`, with four one-verb scripts —
`coord-order-send.sh` (write), `coord-order-inbox.sh` (read for injection),
`coord-order-claim.sh` (claim), `coord-order-done.sh` (terminal state).
Pinned by `orders-selftest.sh` (104 checks).
Pinned by `orders-selftest.sh` (110 checks).
**It is a separate CHANNEL, not more mail, and the axis is authorization.**
Inbox content is untrusted cross-repo data that may never instruct a session
@ -316,7 +347,7 @@ marketplace plugin. Three components, one boundary:
- **Board (`scripts/board.sh`):** cross-repo attention board. Reads STATE.md
next-step blocks + board lines, `git status`, and mailbox pending counts, and
prints one line per repo. Read-only by construction: it writes to no repo, no
STATE.md and no mailbox. Pinned by `board-selftest.sh` (246 checks).
STATE.md and no mailbox. Pinned by `board-selftest.sh` (252 checks).
**It lives here because the mailbox is one of its three inputs, and it carries
the same axis distinction the mailbox does.** A pending count means *others
@ -781,10 +812,10 @@ obligations in another repo.
- Zero dependencies everywhere: bash + coreutils in the engine, `node:`
builtins only in hook and tests.
- TDD: no behavior change without a failing selftest check first.
`bash scripts/coord-selftest.sh` must exit 0 (220/220),
`bash scripts/board-selftest.sh` must exit 0 (246/246),
`bash scripts/coord-selftest.sh` must exit 0 (230/230),
`bash scripts/board-selftest.sh` must exit 0 (252/252),
`bash scripts/route-selftest.sh` must exit 0 (69/69),
`bash scripts/orders-selftest.sh` must exit 0 (104/104) and
`bash scripts/orders-selftest.sh` must exit 0 (110/110) and
`bash scripts/state-line-guard-selftest.sh` must exit 0 (40/40).
- English for all code, docs, and commit messages (public repo). Norwegian
trigger aliases in the skill description are deliberate.