Skip to content

fix(terminal): recheck mirror secret authority before Enter - #1065

Merged
devswha merged 3 commits into
mainfrom
fix/mirror-secret-recheck-before-enter
Oct 14, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/mirror-secret-recheck-before-enter

Conversation

@devswha

@devswha devswha commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Fixes #900

Root cause

server/index.ts (the attachment.mirror branch of the secret handler, ~L3161-3171 on main): the allowed authority guard was passed only to paneSendText. After the text RPC returned, paneSendKeys(pane, ["Enter"]) ran with no guard and no recheck. A sender who detached and rejoined, switched to observe (and back), or lost the attachment/pty while the text was being typed still had its secret submitted and was answered ok: true.

What changed

  • The Enter is now sent through the same guarded paneSendKeys(..., allowed) path that keystroke batches use (server: a queued chord or text can still write after its sender's authority lapses during the RPC connect #545), so authority is rechecked after typing and again once the Enter RPC has connected.
  • If the guard cancels the Enter, the typed characters are erased with one Backspace per character (an unguarded cleanup, so the secret is not left on the prompt line for someone else's Enter). The sender gets read_only when its role changed, otherwise not_attached.
  • Changelog fragment changelog.d/mirror-secret-authority.md.

Residual

A raw-mode reader receives the Backspace bytes but may not erase its own input buffer. Cleanup counts the submitted string's length and is not an atomic compare-and-erase against another device typing in the same pane at the same moment.

Tests

New contract cases in server/submit.contract.test.ts run a real masked read -s in a mirrored pane (terminalAttach: false), with a second client keeping the mirror alive:

  • none: normal delivery answers ok: true, and the reader gets all 12 characters. control
  • rejoin: detach + reattach while the text RPC is held. regression (fails on main)
  • observe: switch to observe while the text RPC is held. regression (fails on main)
  • observe-back: switch to observe and back. regression (fails on main)
  • enter-connect: detach + reattach while the Enter RPC connects. regression (fails on main)

Each regression case expects a refusal (not_attached / read_only), then types X + Enter itself and requires the reader to report length 1, which proves the secret was erased rather than left in the buffer.

Before / after

  • Before, with main's server/index.ts and the new test: control passes; the 4 stale-authority cases fail because the server answered { ok: true } and submitted the secret.
  • After: 5/5 pass, and 5 consecutive reruns were all 5/5.

Checks run

  • bun run typecheck: pass
  • HERDR_TEST_MODE=unit bun test ./server/conventions.test.ts ./scripts/conventions.test.ts ./scripts/changelog-fold.test.ts: 31 pass, 0 fail
  • bun test ./server/submit.contract.test.ts on an isolated herdr session: 66 pass, 0 fail
  • The author's lane also ran bun run test:unit (3515 pass, 0 fail) and bun run check fast (pass).

Guard the committing key after its RPC connects. If authority lapsed after typing, erase the typed characters and report not_attached or read_only instead of submitting.

Cover normal delivery, detach/rejoin, observe, observe-and-return, and loss while Enter connects with real masked shell reads. Raw-mode readers may consume Backspace bytes without erasing their own buffer.

Plan: .omo/plans/issue-sweep-2026-10-14.md
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c7b61045-b689-4f35-988e-644110e9e762
📥 Commits

Reviewing files that changed from the base of the PR and between 0de23fc and 7487bdf.

📒 Files selected for processing: 3
  • changelog.d/mirror-secret-authority.md
  • server/index.ts
  • server/submit.contract.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Fix the blocking PR #1065 review finding: UTF-16-counted Backspaces left Unicode secret bytes in canonical input. Use Ctrl+U and verify byte-exact multibyte cancellation in the existing submit contract tests.
Fix the blocking PR #1065 Unicode cleanup finding without relying on Ctrl+U, which does not clear Windows cooked input. Reject mirrored non-ASCII secrets before typing and retain Backspace cleanup for ASCII; leave PTY-attached secrets unchanged.
@devswha
devswha merged commit d87173d into main Oct 14, 2026
17 checks passed
@devswha
devswha deleted the fix/mirror-secret-recheck-before-enter branch October 14, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server: a mirrored secret's authority is not rechecked between typing the text and sending Enter

1 participant