fix(trust): a project's key mappings that can run commands wait for :trust
Merged
KI
21d ago+966+966+012345678901234567890123456789-27-27-01234567890123456789
Problem
A project's .vigent.toml holds back everything that runs programs until you :trust it: hooks, [commands] shell steps, engine commands and arguments, and Claude Code allow rules. Its [keys] mappings were applied untrusted, though. A mapping's right-hand side is replayed as keys, so a cloned repository could map j to :!cmd<CR>, and pressing j ran a shell command without :trust. The same was reachable through:
- raw keys (
q:!cmd<CR>); - lists (
[":", "!cmd", "<CR>"]); <Cmd>…<CR>mappings;[keys.command]lines;- insert-mode
<Esc>:!cmd<CR>; - mappings that define a command or mapping (
:command,:nnoremap) or replay keys (:normal).
The registry had the matching gap: it builds runs from the trust gate, so a keymap entry mapping a key to :!cmd<CR> was shown as "data only" in vigent add and on the website.
Change
mappingCommandLinesandcommandLineRisk(src/keys.ts and keys.rs, mirrored):- The first simulates a right-hand side the way vigent replays it and returns each command line it would run. Lines it can't follow (cursor moves, history, completion, paste) count as risky.
- A line is risky if it's a shell command (after any range), a definer or replayer (
:command,:delcommand, the map/noremap/unmap family,:normal,:execute,:source),:trustor:permissions allow, or a user command whose expanded steps do one of these.
loadConfig: in an untrusted project file, a risky mapping isn't applied and is named in the trust message askeys.<mode>.<lhs>.:trustnow applies the mappings that waited to the live keymap, in both builds. Safe mappings and your own config.toml are unchanged.- Registry:
runsOflists a keymap's risky command lines, sovigent addand the website show them.- The validator rejects keymaps that define, replay, trust, or hide what they run.
- In the regenerated index,
command/landnow also lists<leader>L → Land.
- Docs: docs/config.md (the trust paragraph, and "A project's mappings"), docs/registry.md (safety model), and the registry page.
- The TypeScript app and the Rust binary behave the same.
Verification
Run on this branch, which contains current main (5dcf358):
| Suite | Pass | Fail | Skipped |
|---|---|---|---|
npm test | 470 | 0 | 13 |
cargo test (crates/vigent) | 195 | 0 | – |
| full pty suite through the packaged Rust binary | 476 | 0 | 7 |
- Unit tests in both languages:
- every path above, ranges, user commands, and safe mappings that stay allowed;
- the gating, and
:trustapplying the mapping; - the user's own config being unaffected;
- the registry: a keymap with
:!x<CR>is listed, and definers are rejected.
- pty test on both builds: a repository maps
jto:!touch pwned<CR>. Before:trust,jcreates nothing and the message nameskeys.normal.j; after:trust, it creates the file. The test fails on the binary from before this change. - Differential run: a one-off comparison of 20,000 random right-hand sides across all modes found the TypeScript and Rust results identical.
cargo build --releasehas no warnings; the binary is 2.9 MB (1.3 MB download).
Follow-ups
[commands]steps without!still apply untrusted, so a project command likeX = "nnoremap j :!y<CR>"defines a shell mapping when you run:X. Gating definer steps in[commands]the same way would close that.- From a mapping,
:w! <path>can overwrite a file with the transcript, and:serveopens the session to the network. Consider gating these too. - The
:trustmessage is computed without your own config. A key held back only because it calls one of your commands is applied by:trust, but isn't named in the message.