/careful: heredoc bodies are scanned as shell commands

Abierto
#4,843 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
57/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
bash, shell, typescript
Área
cli, security

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
143k
Forks
21k
Merge medio
7 h 19 min
PR fusionados (30 d)
781

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de garrytan/gstack

Todos los issues de garrytan/gstack

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.