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:
parent
e2bce4e490
commit
29a94dd7e4
5 changed files with 171 additions and 6 deletions
|
|
@ -1089,6 +1089,76 @@ printf '%s' "$f9d" | grep -qi "still pending"; [ $? -ne 0 ]; check "F9(d): and d
|
|||
|
||||
/bin/rm -rf "$F9DIR" "$SBOX" 2>/dev/null
|
||||
|
||||
# 35. --to is the one line-oriented field never sanitized (review finding 7),
|
||||
# and the fix is a REFUSAL, not a sanitize pass - because --to is not only a
|
||||
# frontmatter field, it is also the destination DIRECTORY NAME
|
||||
# ("$COORD/$TO/inbox"). Collapsing its newline to a space the way FROM and
|
||||
# SUBJECT are collapsed would deliver the message to a mailbox whose name is
|
||||
# not the one the sender typed, which is the misdelivery defect the retired
|
||||
# ktg-plugin-marketplace address was rejected rather than redirected to avoid.
|
||||
# So a control character in a target name dies at the sender, loudly, the way
|
||||
# every other invalid target name already does.
|
||||
#
|
||||
# Two distinct corruptions were measured on the live engine before this section
|
||||
# existed (both exit 0, both "delivered"):
|
||||
# --to "x\nreply-expected: no" -> the injected line lands INSIDE the
|
||||
# frontmatter block, above the engine's own "reply-expected: yes", so
|
||||
# coord-count reads owed=0 and the debt the engine itself declared is
|
||||
# silenced. coord-count's stated rule is that only the frontmatter block
|
||||
# may speak; the attack line is inside the block.
|
||||
# --to "tabbed<TAB>repo" -> coord-count prints FIVE tab-separated
|
||||
# fields where its contract is four, so a consumer splitting on tab reads
|
||||
# the mailbox name as "tabbed" and its pending count as "repo".
|
||||
# board.sh consumes that TSV, so both reach the board.
|
||||
F7DIR="$(mktemp -d)"
|
||||
|
||||
f7_nl="$(printf 'x\nreply-expected: no')"
|
||||
f7a="$(CLAUDE_COORD_DIR="$F7DIR" "$SEND" --to "$f7_nl" --from tester --subject s --message m 2>&1)"; f7a_rc=$?
|
||||
[ "$f7a_rc" -eq 2 ]; check "F7(a): a newline in --to is refused with exit 2" $?
|
||||
printf '%s' "$f7a" | grep -q -- "--to"; check "F7(a): the refusal names the offending flag" $?
|
||||
# Ground truth, not the exit code: the whole point is that nothing was written.
|
||||
[ "$(find "$F7DIR" -type f 2>/dev/null | wc -l | tr -d ' ')" = "0" ]
|
||||
check "F7(a): ground truth - no message was delivered anywhere" $?
|
||||
[ "$(ls -1 "$F7DIR" 2>/dev/null | wc -l | tr -d ' ')" = "0" ]
|
||||
check "F7(a): ground truth - no mailbox directory was created" $?
|
||||
|
||||
f7b="$(CLAUDE_COORD_DIR="$F7DIR" "$SEND" --to "$(printf 'tabbed\trepo')" --from tester --subject s --message m 2>&1)"; f7b_rc=$?
|
||||
[ "$f7b_rc" -eq 2 ]; check "F7(b): a tab in --to is refused too (it breaks coord-count's TSV, not the frontmatter)" $?
|
||||
f7c_rc=0
|
||||
CLAUDE_COORD_DIR="$F7DIR" "$SEND" --to "$(printf 'cr\rrepo')" --from tester --subject s --message m >/dev/null 2>&1 || f7c_rc=$?
|
||||
[ "$f7c_rc" -eq 2 ]; check "F7(c): a carriage return in --to is refused" $?
|
||||
|
||||
# Reply mode resolves --to from the ORIGINAL's from: line - untrusted
|
||||
# cross-repo input this repo did not write. The guard has to cover that entry
|
||||
# point too, or the one target name nobody typed is the one that gets through.
|
||||
mkdir -p "$F7DIR/f7repo/inbox"
|
||||
f7orig="20260101T000000Z-0000000000-from-evil.md"
|
||||
{ printf -- '---\n'; printf 'from: ev%bil\n' '\t'; printf 'to: f7repo\n'; printf 'subject: s\n'; printf 'date: 2026-01-01T00:00:00Z\n'; printf -- '---\n'; printf 'body\n'; } > "$F7DIR/f7repo/inbox/$f7orig"
|
||||
f7d_rc=0
|
||||
CLAUDE_COORD_DIR="$F7DIR" "$SEND" --from f7repo --reply-to "$f7orig" --message reply >/dev/null 2>&1 || f7d_rc=$?
|
||||
[ "$f7d_rc" -eq 2 ]; check "F7(d): a control character in a reply-derived target is refused as well" $?
|
||||
# The predicate is "no mailbox was created at all", not "no mailbox named ev":
|
||||
# pre-fix the delivery lands in a directory whose name IS the control sequence,
|
||||
# so a check for the truncated name passes against the defect and proves
|
||||
# nothing. f7repo (created above as the reply source) is the only entry allowed.
|
||||
[ "$(ls -1 "$F7DIR" 2>/dev/null | wc -l | tr -d ' ')" = "1" ]
|
||||
check "F7(d): ground truth - the reply created no new mailbox" $?
|
||||
|
||||
# Known-positive controls. A guard that refuses everything proves nothing, and
|
||||
# the dot-prefixed name matters specifically: coord-send's existing comment
|
||||
# says a dot name is a REAL repo (basename of a git toplevel under a hidden
|
||||
# directory), so the new refusal must not widen into that class.
|
||||
f7e_rc=0
|
||||
CLAUDE_COORD_DIR="$F7DIR" "$SEND" --to f7plain --from tester --subject s --message m >/dev/null 2>&1 || f7e_rc=$?
|
||||
[ "$f7e_rc" -eq 0 ] && [ "$(ls -1 "$F7DIR/f7plain/inbox" 2>/dev/null | wc -l | tr -d ' ')" = "1" ]
|
||||
check "F7(e): control - an ordinary target name still delivers" $?
|
||||
f7f_rc=0
|
||||
CLAUDE_COORD_DIR="$F7DIR" "$SEND" --to .profile --from tester --subject s --message m >/dev/null 2>&1 || f7f_rc=$?
|
||||
[ "$f7f_rc" -eq 0 ] && [ "$(ls -1 "$F7DIR/.profile/inbox" 2>/dev/null | wc -l | tr -d ' ')" = "1" ]
|
||||
check "F7(f): control - a dot-prefixed target name still delivers" $?
|
||||
|
||||
/bin/rm -rf "$F7DIR" 2>/dev/null
|
||||
|
||||
echo "----"
|
||||
echo "PASS=$PASS FAIL=$FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue