/careful: heredoc bodies are scanned as shell commands

Aperta
#4,843 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
bash, shell, typescript
Ambito
cli, security

Direzione di ricerca

Start by reading careful/bin/check-careful.sh and the change for #1060, which the issue identifies as handling two heredoc cases. Reproduce the quoted heredoc examples and inspect how the statement scan treats their bodies; also check _RX_TMP for the Windows temp-folder behavior. Done means quoted heredoc text no longer triggers destructive-command prompts, executable substitutions remain scanned, and recursive deletes under the resolved %TEMP% path are treated as scratch.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Since 1.103 made the destructive-command check a default hook, I get approval prompts in auto mode for commands that don't delete anything. Almost all of them have the same cause: the check reads the body of a heredoc as if it were shell.

#1060 fixed this for git commit -m "..." and for -m "$(cat <<'EOF' ... EOF)". Any other heredoc still goes through the statement scan, which splits the body at newlines and backticks and checks each line as a command.

Repro

1.103.1.0 on Windows 11 with Git Bash. I sent each of these as tool_input.command to careful/bin/check-careful.sh:

python - <<'EOF'
t = "the script runs rm -rf on the staging lib folder"
print(t)
EOF
git commit -F - <<'EOF'
staging: rm -rf the lib folder before copying
EOF

Both come back with:

{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"ask","permissionDecisionReason":"[careful] Destructive: recursive delete (rm -r). This permanently removes files."}}

The same message through git commit -m "$(cat <<'EOF' ... EOF)" returns {}, and so does the Python heredoc once the string no longer says rm.

Agents write heredocs like these all day, for small Python edits and for commit messages, and the text tends to describe the change. The one that made me look was a script rewriting a changelog line about a build step that clears a folder.

What I'd expect

With a quoted delimiter (<<'EOF', <<"EOF", <<\EOF) the body is literal, so it could be skipped the same way the commit message is. With an unquoted delimiter, $(...) and backticks in the body still run, so those parts would still need the scan.

Windows temp folders

A smaller thing. A recursive delete only counts as scratch under /tmp and /var/tmp (_RX_TMP). Git Bash maps /tmp to %TEMP%, but the same folder written as C:/Users/<user>/AppData/Local/Temp/<dir> still asks, and that's the spelling my agent's scratch folder has. Treating the resolved %TEMP% path like /tmp would cover it.

For now I've turned the guard off with gstack-config set destructive_guard off. That works, but I'd rather have it on.

Lingua principale
TypeScript
Stelle
143k
Fork
21k
Merge medio
7h 19m
PR unite (30g)
781

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di garrytan/gstack

Tutte le issue di garrytan/gstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.