fix(trust): a project's risky commands, :w with a file and :serve wait for :trust

Merged
KI
20d ago
+482-77

Problem

#191 made a project's key mappings that can run commands wait for :trust, and listed three remaining gaps:

  1. [commands] steps without ! applied untrusted. A project command like X = "nnoremap j :!y<CR>" (or command …, normal …, execute …, source …, trust, permissions allow …) defined or replayed something that runs commands as soon as you ran :X.
  2. :w with a file and :serve weren't risky. From an untrusted mapping or command, :w! <path> could overwrite a file with the transcript, and :serve could open the session to the network.
  3. The :trust message 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 your Test = "!npm test") was applied by :trust but not named.

Change

  • commandLineRisk (src/keys.ts and keys.rs) also flags :w/:write given a file or !, and :serve with any argument except stop.
  • Project commands: in an untrusted project file, a [commands] entry with any step that commandLineRisk flags is held back like one with a shell step. It's named in the trust message as commands.<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: runsOf lists 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>". :X then j before :trust creates 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/:write given a file or ! (and :wq, :x) and :serve with any argument but stop are new risky lines; a bare :w and :serve stop stay allowed.
  • :trust and vigent trust read the project file over your config, so a key or command gated only because it calls one of yours (like :Test<CR> with your Test = "!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.