Skip to content

The destructive-command check no longer asks about text inside quoted heredocs (#4843) - #4852

Closed
garrytan wants to merge 6 commits into
mainfrom
careful-quoted-heredoc-bodies
Closed

garrytan wants to merge 6 commits into
mainfrom
careful-quoted-heredoc-bodies

Conversation

@garrytan

@garrytan garrytan commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Commit messages sent with git commit -F - <<'EOF', gh bodies sent with --body-file - and a bare cat <<'EOF' no longer trigger an approval prompt because their text mentions rm -rf or git push -f.
Bash never expands a body with a quoted delimiter, so it is text; a body read by a shell, ssh, eval, python or a SQL client, an editor or exec option, an unquoted delimiter, a pipe, and every command outside the body are still checked. Fixes #4843, reported by @nghorbani.
Nothing to do after merging.

What changed
  • New careful/bin/mask-heredoc.awk, run by check-careful.sh only when a Bash command contains <<. It follows bash's quoting, comments and heredoc rules, and blanks only the body lines of a heredoc whose delimiter is quoted (<<'EOF', <<"EOF", <<\EOF, and the <<- forms). The header line and closing delimiter are kept, so anything chained on them is still read. The hook change is 23 added lines; every existing check reads the masked command, as it already does for git commit -m messages (/careful hook triggers false positives on patterns inside commit messages #1060).
  • Readers whose body counts as text: git [-C dir] commit -F - / --file - with only -a, -q, -s, --allow-empty, --amend, --no-edit or --cleanup= beside it; gh issue|pr create|comment|edit -F - / --body-file - with title, base, head, repo, label, assignee, reviewer, milestone and draft options only; and a bare cat.
  • Nothing is masked when the command has an unclosed heredoc, an unquoted delimiter, $( ), ${ }, backticks, a pipe, an output redirect to a file, process substitution, a command named by a path or variable, or a shell or interpreter name inside any word (sh, bash, ssh, eval, xargs, python, node and others, so -c core.editor=bash and --exec 'bash m' count). PowerShell commands are never masked.
  • python - <<'EOF' still asks when its body mentions a destructive command: python runs its program, and no text check can show a program never starts a process. The first repro in /careful: heredoc bodies are scanned as shell commands #4843 therefore still asks; the commit-message repro no longer does.
  • One existing expectation in test/hook-scripts.test.ts recorded the bug (git commit -F - <<'EOF'\ndocs: rm -rf src\nEOF asks). It now expects no prompt, and its place in the "stays unmasked" table is taken by the unquoted twin, which still asks.
  • The Windows %TEMP% spelling mentioned at the end of /careful: heredoc bodies are scanned as shell commands #4843 is not part of this change: Windows has minimal support, and /tmp already covers Git Bash's scratch folder.
Tests
  • test/careful-replay.test.ts: 68 new rows. 12 fix rows (each asked or denied on main) and 56 controls that keep main's decision: bash/sh/sh -s/zsh/dash/sudo bash/env bash/ssh host sh/ssh host reading the body, source/. of stdin, eval, a read loop, here-strings, git -c core.editor=bash, git commit -e, GIT_EDITOR=bash, a later amend or rebase --exec, gh --editor, unquoted and unclosed delimiters, an indented delimiter without <<-, a CRLF delimiter, deletes chained with &&, ;, || and | on the header line or after the closing line, a heredoc marker in a comment or in quotes, several heredocs on one line, every python heredoc, cat writing a script that a later command runs, and psql. Plus a 200 KB message timing test.
  • Main-vs-head replay over every payload the careful test files send: counts are in the agent notes.
Agent notes
Agent notes

Replay counts and review results are added by /gstack-ship.

Open in Capy

{"head":"86aa7dd20b891d050537ea19643f331669229b24","run":"ship","status":"started","review_loop":{"passes":1,"blocking_found":2,"deferred":0,"noted":0,"fixed":3,"scope":"frozen","rounds":1,"dispatches":{"specialist":1}}}
{"head":"86aa7dd20b891d050537ea19643f331669229b24","run":"ship","mark":"stop","tree":"0fa01b8fa706ff62ca3205219b57a3ce6a5477ee","at":"2026-11-26T17:08:43.700Z"}

garrytan and others added 2 commits November 26, 2026 16:35
)

A heredoc with a quoted delimiter is never expanded, so a body read by git
commit -F -, gh --body-file - or a bare cat is now masked for every check, as
a commit message already is, and a python program read from stdin that starts
no process is masked for the shell-statement scan. Shell, ssh, eval and SQL
readers, unquoted delimiters, pipes and every command outside the body are
still checked.

Reported-by: Nima Ghorbani (@nghorbani)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 26, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

garrytan and others added 2 commits November 26, 2026 16:40
… list change as non-behavioral

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=red-team
Review-Finding: p1/specialist-batched#2 reader=red-team
Review-Finding: p1/specialist-batched#3 reader=testing
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot marked this pull request as draft November 26, 2026 17:09
garrytan and others added 2 commits November 26, 2026 17:20
Review-Finding: p2/specialist-batched#1 reader=security
Review-Finding: p2/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: ship2-p1/specialist-batched#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Parking this draft. Each review round found one more bash feature the text check does not model. The latest: unquoted brace expansion such as git -C {.,-c,core.hooksPath=/tmp/h} commit -F - <<'EOF' turns into a -c option, so the guard would allow a commit that main denies. Until the design changes, quoted heredocs keep the old prompts. The repro and the options for a narrower design are in the lane's report.

@capy-ai

capy-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Closing this draft unmerged. Across four review passes, modelling bash command lines in awk kept exposing new syntax bypasses (editor flags, function/hash -p shadowing, later-statement alias replay of .git/COMMIT_EDITMSG, and bash brace expansion like git -C {.,-c,core.hooksPath=...}). Leaving the branch intact for reference; if we revisit #4843, it should be either a strict flag-free literal header match or a real bash AST parser rather than an awk scanner.

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.

/careful: heredoc bodies are scanned as shell commands

1 participant