Skip to content

fix: ask before SSH keys leave, keep vault readers consistent across compactions, and eight more review fixes - #368

Merged
kitlangton merged 5 commits into
devfrom
rust-security-fixes
Dec 2, 2026
Merged

kitlangton merged 5 commits into
devfrom
rust-security-fixes

Conversation

@kitlangton

@kitlangton kitlangton commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

hint: if you need to wait for this pull request to be reviewed, merged, or closed before continuing, use this instead of polling:
gh event listen --resource #368 --event com.github.pull_request.review.submitted.v1,com.github.pull_request.state.changed.v1

  • It prints the first event as a JSON line on stdout and exits; run it again to wait for the next one.
  • Add --timeout to stop waiting after a while, for example --timeout 30m; it then exits with status 8.
  • Events carry no details; read the pull request to see what changed.
  • It misses changes made before it starts, so read the pull request once it is running.
  • See gh event listen --help for other event types.
  • Event subscriptions are in preview and may not be enabled for your account.
    Ten correctness fixes from a code review: an SSH private key now asks for Touch ID on every way out, a vault reader can no longer silently lose frames across two compactions, and a second store never borrows the first store's daemon.
    Each fix comes with a focused regression test. The wire protocol is unchanged (still 38, crates/proto untouched) and there are no new dependencies.

❌ Before / ✅ After

# Case Before After
1 deadbolt read/run/inject of an SSH private key or its passphrase, Touch ID on ❌ returned with no prompt, while deadbolt get asked ✅ asks each time; answers only if the references still name the same key
2 Two identical deadbolt ask calls wait on one locked card, the item is swapped, the card is approved ❌ the waiter that didn't resolve the card checked nothing and got the swapped secret ✅ both waiters check against the approved card and are refused
3 Asking an app to quit during an update, pid reused meanwhile ❌ whichever app now has the pid was asked ✅ only the process with the start time read alongside the pid
4 macOS AutoFill ❌ no quick unlock for "With this Mac"; a twitter.com login never offered on x.com; cancel detected by English text ✅ either quick unlock is offered; shared sites registered; cancel and wrong passphrase carried as codes
5 A reader opens a vault while the writer compacts twice ❌ new pack paired with old logs: synced frames missing, no error ✅ reader notices the logs moved and starts over
5 Opening a vault directory ❌ read, checksummed and copied every log, then threw it away ✅ reads the pack it picks and the two logs it can append to
6 deadbolt unset of an SSH key's comment or passphrase ❌ public key and fingerprint left stale ✅ re-derived, same as set --unset
7 App can't reach the daemon at launch or reconnect ❌ error screen over items and a pending unlock still in memory ✅ cleared like a daemon that stopped
7 Quick panel shortcut inside the app, off macOS ❌ only Cmd+Shift+Space worked; the app names Ctrl+Shift+Space ✅ the platform's own default chord
8 Store placed with XDG_DATA_HOME ❌ shared the default store's daemon socket, so commands and a passphrase reached the wrong store's daemon ✅ its own socket; a daemon serving another store is refused
9 AutoFill extension's "send only to a verified daemon" rule ❌ a non-exhaustive list over the wire type: a new request would be sent unchecked ✅ exhaustive over the extension's own requests; a new one is a build error
10 deadbolt receive --force with two files of the same name in one bundle ❌ second silently replaced the first, both reported written ✅ refused before anything is written
10 deadbolt debug with a vault that failed to load ❌ counted as "removed" ✅ counted as "unavailable"
  resolve(refs):
+   if any ref is an SSH private key or passphrase and Touch ID is on:
+     prompt; look the refs up again; refuse if they name different items
  reader.open():
    open every WAL; choose newest pack
+   list WALs again; if the list changed, start over
  ensure_running():
-   reuse any daemon speaking this protocol
+   reuse it only if it serves this store

📊 Proof

26 new regression tests, all passing, plus existing tests adapted where an API changed. The two reader-race tests and the headless Touch ID ask test were also run against the old code and fail there; the others were not each re-run against the old code.

Check Result
cargo test --workspace (before the last commit) 1580 passed, 0 failed, 5 ignored
cargo clippy --workspace --all-targets -- -D warnings clean
cargo fmt --all -- --check clean
bun run check:wasm clean
bash scripts/file-size.sh 0 errors; 22 files over 800 and 29 warnings, same as dev

A review round then added five follow-ups in their own commit: with no app running, Touch ID's answer settles a deadbolt ask for every waiter (a second identical ask used to hang for a minute if the first one's check failed); the SSH Touch ID prompt counts keys, not titles; the store check also runs on a daemon that comes up after a start; pid 0 is never signalled; and one redundant cancel re-wrap is gone.

A second round added three more in the last commit: an ask is ended and its card taken down in one place (settle_ask), so the card is only cleared by whoever actually ended it; ensure_running holds the daemon that answers to one rule (accept) whether it was found running or just started; and a stray doc comment is gone. The last commit was checked with Clippy and the client, ask::, macos_autofill:: and CLI integration tests, not a full workspace run, and CI is green on it.

Things that behave differently on purpose:

  • XDG_DATA_HOME users: a store somewhere other than ~/.local/share/deadbolt now has its own daemon socket. A daemon already running for it at the old socket should be stopped once (deadbolt debug daemon stop). The default store, and stores placed with DEADBOLT_HOME, keep the names they have.
  • A daemon that comes up unusable: if the daemon that answers right after a start is newer, of another build, unverified or serving another store, the command now fails at once naming it and leaves it running. It used to wait five seconds and report that the daemon did not start, or, for another protocol, carry on as if it spoke this one. Two CLI tests that start such a daemon on purpose now expect that first call to fail.
  • deadbolt ask is not behind the new SSH Touch ID prompt: it has its own approval card.
  • Activity logs have a torn tail cut before the first append to them, no longer on every open.
  • AutoFill's touch_id_ready status field now means "a quick unlock is ready", either kind. Same field, same type.

👀 Read: crates/pack/src/vault_dir.rs, the reader's second WAL listing in try_open and the comment above VaultReader explaining why opening WALs first was not enough. Next, crates/cli/src/daemon/ask.rs, where targets now travel with the decision and an approval with no recorded targets fails closed. The rest is routine.

🔍 Found in a code audit · no user reports · open-time cost not measured

Checks run
  • cargo test --workspace, before the last commit: 1580 passed, 0 failed, 5 ignored (includes the Swift AutoFill end-to-end runner)
  • On the last commit: cargo test -p deadbolt-client 58 passed, 1 ignored; cargo test -p deadbolt-cli --bin deadbolt ask:: 9 passed; macos_autofill:: 12 passed; cargo test -p deadbolt-cli --test cli 69 passed, 2 failed locally (the two idle-lock tests, which can't pass on a Mac whose keyboard or mouse is in use; they pass in CI)
  • cargo clippy --workspace --all-targets -- -D warnings: no warnings
  • cargo fmt --all -- --check: no diff
  • bun run check:wasm: finished, no errors
  • bash scripts/file-size.sh: over 800: 22, over 1500: 0, prefix families: 0, wide folders: 0, errors: 0, warnings: 29
  • Not run: the extension's typecheck/tests/build, cargo deny, cargo machete (no extension or dependency changes)

… type cancels

- `resolve` asks Touch ID before an SSH private key or its passphrase
  leaves, each time, as `item get` does, and answers only if the
  references still name what the prompt was about.
- Coalesced `deadbolt ask` waiters all check their answer against the
  card that was approved: the targets travel with the decision, and an
  approval of a card that named no items approves none.
- `item unset` is the same edit as a `set` that unsets, so an SSH key's
  derived fields follow a removed comment or passphrase.
- macOS AutoFill offers quick unlock "With this Mac" too, registers a
  login for the sites that share its credentials, and runs both passkey
  ceremonies through one user-verification path.
- One classifier names a failure for the reply, the span and the log. A
  cancelled or unanswered Touch ID prompt is `cancelled` by its type,
  never by its message.
- The AutoFill FFI says per request whether it needs a verified daemon,
  exhaustively, and passes `wrong-passphrase` to Swift as its own code.
…out the history

- `VaultReader` lists the WALs again after choosing its pack and starts
  over if they moved. Two compactions between its WAL handles and its
  pack left it a pack whose carried tail was in a WAL it never opened:
  frames synced before the pack was written went missing, silently.
- `MemReader` is a handle on the file, as `FsReader` is: it sees appends
  made after it opened and keeps reading a deleted file. The simulation
  no longer has stronger guarantees than the file system.
- `VaultDir::open` cuts torn tails off the two logs it can append to and
  returns which pack is the base. It no longer reads, checksums and
  copies every WAL and activity log for callers that dropped them; an
  activity log is cut before the first append to it.
- A store placed by `XDG_DATA_HOME` gets its own daemon socket, as one
  placed by `DEADBOLT_HOME` does; the default store's names don't move.
  `ensure_running` refuses a daemon that serves another store.
- `request_quit_app` takes the start time read with the pid, as
  `terminate_pid` does, so a reused pid is never asked to quit.
- A failed connect drops what the daemon gave, like a daemon that
  stopped, in place of only changing the screen.
- The quick panel's in-app fallback is the default shortcut's chord on
  each platform: Ctrl+Shift+Space off macOS.
- `deadbolt receive` refuses a bundle whose files would land on each
  other, with `--force` too.
- `deadbolt debug` counts a vault that couldn't load as unavailable,
  not as one this device was removed from.
…review fixes

- An ask's outcome and the targets its card named are read from one
  place, the settled ask. With no app to show a card, Touch ID's answer
  settles the ask before any waiter reads the vault: the asker whose
  prompt it was used to check its own answer first and, when that
  failed, leave a second identical ask waiting out the minute.
- A passkey ceremony passes a cancelled Touch ID prompt on as it comes:
  it is already `cancelled` by its code.
- A Touch ID prompt for SSH keys counts keys, each a vault's item, so
  two keys that share a title in two vaults read "Deploy and 1 more".
  What the prompt was about is compared by vault too.
- `ensure_running` checks the store of the daemon that answers after a
  start, as it does one found running.
- Pid 0 is never a process to ask to quit or to signal.
…on to the same rule

- `settle_ask` ends an ask and takes its card down only if it was still
  the open one, at every place an ask is decided: the unlock-refresh
  error path cleared the card whether or not it had.
- `ensure_running` has one rule (`accept`) for the daemon that answers,
  found running or just started. One it can't use that answers after a
  start (unverified, newer, of another build, serving another store) is
  named at once: it used to be asked again for five seconds and reported
  as a daemon that did not start, or, of another protocol, taken for one
  this copy speaks to. The two protocol tests start such a daemon and
  now expect that first call to name it.
- A test's doc comment had three lines of another test's.
@kitlangton
kitlangton merged commit f07735d into dev Dec 2, 2026
13 checks passed
@kitlangton
kitlangton deleted the rust-security-fixes branch December 2, 2026 22:10
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.

1 participant