fix(trust): a project's risky commands, :w with a file and :serve wait for :trust
Merged
KI
20d ago+482+482+012345678901234567890123456789-77-77-01234567890123456789
Problem
#191 made a project's key mappings that can run commands wait for :trust, and listed three remaining gaps:
[commands]steps without!applied untrusted. A project command likeX = "nnoremap j :!y<CR>"(orcommand …,normal …,execute …,source …,trust,permissions allow …) defined or replayed something that runs commands as soon as you ran:X.:wwith a file and:serveweren't risky. From an untrusted mapping or command,:w! <path>could overwrite a file with the transcript, and:servecould open the session to the network.- The
:trustmessage missed some keys. It was computed without your own config, so a key held back only because it calls one of your commands (such as:Test<CR>with yourTest = "!npm test") was applied by:trustbut not named.
Change
commandLineRisk(src/keys.ts and keys.rs) also flags:w/:writegiven a file or!, and:servewith any argument exceptstop.- Project commands: in an untrusted project file, a
[commands]entry with any step thatcommandLineRiskflags is held back like one with a shell step. It's named in the trust message ascommands.<Name>and applied by:trust; running it first says it waits for:trust. Safe ex-only commands still apply. - The trust message is computed with your own commands in view, so every held-back key and command is named.
- Registry:
runsOflists a command's risky ex steps, and the validator rejects steps that hide what runs. - Docs: docs/config.md (the trust paragraph,
[commands], "A project's mappings") and docs/registry.md. - The TypeScript app and the Rust binary behave the same.
Verification
- Unit tests in both languages:
- each new risky line, and the safe neighbors that stay allowed;
- a project command gated by a risky ex step, applied after
:trust; - the trust message naming a key that calls one of your commands;
- the registry rules.
- pty test on both builds: a repository defines
X = "nnoremap j :!touch pwned<CR>".:Xthenjbefore:trustcreates nothing; after:trust, it does. - The full runs (
npm test,cargo test, and the pty suite through the binary) are in progress, and the results go here before merging.
Follow-ups
None planned.
Generated by Claude Code
Summary by cubic
A project's .vigent.toml now holds back [commands] with risky ex steps until :trust, and treats :w with a file or ! and :serve as risky, so an untrusted file can't run commands, overwrite files, or open the session to the network through them. The trust message is computed with your own config in view, so it names every key and command it applies.
Bug Fixes
- A
[commands]entry whose step can run a shell command (nnoremap j :!touch pwned<CR>,command,normal,execute,source,trust,permissions allow,w! file,serve) now waits for:trust; before, only!steps did. :w/:writegiven a file or!(and:wq,:x) and:servewith any argument butstopare new risky lines; a bare:wand:serve stopstay allowed.:trustandvigent trustread the project file over your config, so a key or command gated only because it calls one of yours (like:Test<CR>with yourTest = "!npm test") is named in the message.- The registry validator lists a command's risky ex steps and rejects steps that define keys or mappings, replay keys, or trust/allow, so an entry can't hide what runs.