Skip to content

fix(guard): restore refusals for commands that run a shell - #229

Merged
TornquistK merged 2 commits into
mainfrom
workset/settle-release-review-follow-ups
Dec 2, 2026
Merged

TornquistK merged 2 commits into
mainfrom
workset/settle-release-review-follow-ups

Conversation

@TornquistK

@TornquistK TornquistK commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups from the 1.0.0..main review before stable 1.0.1. OpenSpec change: settle-release-review-follow-ups.

The artifact guard (Claude hook and OpenCode middleware share evaluate()):

 commandTargets(command)
   commandText = stripHeredocBodies(command)   # quote state now carried across lines
   isCommand   = commandTextMask(commandText)
+  shellWords  = shell or eval in command position (after | ; & ( $( ` or a line break,
+                behind assignments and env/sudo/exec/command/xargs)
-  scan redirect + tee at command-text offsets
+  scan redirect + tee at command-text offsets, or everywhere if shellWords   # 1.0.0's quote-blind scan
-  nested -c / eval strings: any command's -c
+  nested -c / eval strings: -c only after a shell word or su
+  heredoc bodies whose marker line runs a shell: scan as commands
+  drop duplicate targets

Shell words: sh bash dash ksh zsh ash mksh yash posh csh tcsh fish, also as a path.

Patterns: >| is a redirect. A quoted target with spaces (> "a b.md") is one word. Every tee file is judged, whatever its options; a word behind < or <<< is input, not a tee file.

Other items:

  • project.ts: the archived-dependency remedy quotes the name with shellQuote, which apply-chain.ts now exports. It prints mate artifact publish 'acme'.
  • companion-sync.ts: the doc comment of companionForkRefusal now says only the fork state is cached, and the ignore check runs per target.
  • cli-e2e-launch-sync.test.ts: the held lock is released 500 ms after the CLI prints "waiting for another companion sync to finish", not on a 1.5 s timer. The test asserts the sync had not run before the release. runMate gained an optional onStderr callback.
  • commands.mdx: in a linked worktree served by the main worktree, mate claude and mate wrap remove a .claude/skills folder that holds only Mate's links.

Evidence

  • Before / after in the real hook (verify-mate, the run's installed validate-artifact-path hook fed a Bash payload; base 8bffd332 vs this branch):
    command                                   base  branch
    eval cat \> notes/x.md                      0     2
    echo 'cat > notes/x.md' | sh                0     2
    sh <<< 'cat > notes/x.md'                   0     2
    bash -c "$(printf 'cat > notes/x.md')"      0     2
    bash <<'EOF' / cat > notes/x.md / EOF       0     2
    echo hi >| notes/x.md                       0     2
    echo x | tee -i notes/x.md                  0     2
    grep -c '> notes/x.md' README.md            2     0
    git commit -m "fix: write > notes/x.md"     0     0
    tee out.txt < notes/x.md                    0     0
    printf x > notes/x.md  (control)            2     2
    
    The refusal names target: notes/x.md and a suggested companion path.
  • -c refusals main makes stay: a new test pins ash/mksh/yash/posh/csh/tcsh/fish -c, busybox ash -c, nice/timeout/sudo -u/docker exec/xargs … sh -c and su - acme -c. With only the five POSIX shells, 8 of them fail; with the full list, all pass.
  • validate-artifact-path, shell-heredoc and companion-policy: 147 pass, 0 fail. test:hooks: 157 pass.
  • typecheck, lint, format:check, knip, docs:check: clean. The full bun run test exited 0 before the shell-list commit; the affected guard tests and static checks passed again after it.
  • Lock-wait e2e file: 7 of 7 pass.
  • Not exercised: a session in a wrapped repository without mate claude (the hook was driven with a launched session's environment); the publish remedy text outside its integration test; -c after script, flock or npx is no longer read as a script (accepted in design.md).
  • Second opinion: 1 blocker found, 1 fixed without review, 0 open
  • Finish: ad4a0fa

Merge Danger

Door: two-way

Revert the commits. Nothing persists.

Blast Radius: guard

A command that runs a shell and also quotes a > x.md text is refused again, as in 1.0.0. Example: bash scripts/x.sh "--note > a.md". The refusal names the target. Commands that run no shell keep main's behaviour.

Scan a command that runs a shell or eval quote-blind, read -c only after a shell or su, scan heredoc bodies fed to a shell, carry quote state across heredoc lines, and judge >|, quoted targets with spaces and every tee file. Also quote the publish remedy with shellQuote, correct the fork check's doc comment, release the lock-wait e2e lock on the waiting line, and document the served-worktree skills folder removal.
- Read -c as a script after ash, mksh, yash, posh, csh, tcsh and fish too, and pin
  main's nested-shell refusals in a test.
- Skip tee words behind an input redirect or here-string.
- Dedupe command targets; match heredoc bodies to shell lines by line number.
- Lock-wait e2e test asserts the sync waited for the release.
@TornquistK
TornquistK merged commit cb39ed3 into main Dec 2, 2026
1 check passed
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