aft icon indicating copy to clipboard operation
aft copied to clipboard

bash: a heredoc body line that starts with the delimiter skips permission checks for the rest of the command

Open null-axiom opened this issue 3 days ago • 1 comments

Version: AFT v0.68.1 on OpenCode 2.4.3, macOS, zsh.

What happens. When a heredoc body contains a line that starts with the delimiter (but isn't exactly the delimiter), every command after the heredoc runs without a permission check. A host deny rule on a later command is not applied.

Repro. With a host policy denying shell:git stash*:

cat <<'END'
ENDING
END
git stash show; echo after

The command runs and prints after. No permission ask or denial for git stash show.

Controls, same policy:

  • Body line xENDING (delimiter text mid-line): denied correctly.
  • Body line probe or forkScoped: denied correctly.
  • echo ENDING; git stash show (no heredoc): denied correctly.

So the trigger is a body line with the delimiter as a prefix. It's easy to hit by accident with short delimiters like E or EOF: any body line starting with E (for example Effect.forkScoped(...) in a TypeScript snippet) closes the heredoc early for the permission parser. We hit it this way in a real session: a git stash push … ; git stash pop placed after a python3 - <<'E' heredoc ran despite the deny.

Expected. A heredoc ends only at a line exactly equal to the delimiter (after stripping leading tabs for <<-), as in POSIX shells. For reference, OpenCode's own scanner (packages/core/src/shell/scan.ts) splits the repro correctly into cat <<'END'…END, git stash show, echo after.

If the parser can't settle where a heredoc ends, failing closed (asking for the whole command) would be safer than skipping the later parts.

null-axiom avatar Nov 30 '26 19:11 null-axiom

Thanks for the precise report. It was a real bypass, and the fix is in PR #1596.

Cause: AFT reads shell commands with tree-sitter-bash before checking them against permission rules. That parser ends a heredoc at the first body line that starts with the delimiter (ENDING ends <<END). Bash ends it only at a line that is exactly the delimiter. So everything after such a line was read as heredoc text, and a deny rule like git stash* never saw the commands that followed.

Fix:

  • AFT now checks every heredoc end against bash's own rule. When the parser disagrees, AFT repairs only plainly literal heredoc text. Anything it can't settle is treated as a command it can't read.
  • Your command now produces a separate check for git stash show, and your deny rule applies to it.
  • On OpenCode 2, a command AFT can't fully read now always asks, even under an allow-all rule.

We checked the fix with four independent security reviews, and against bash 5.2, macOS's /bin/bash 3.2, zsh and /bin/sh.

It ships in the next AFT release. We'll close this issue when that release is out.

aft-alfonso[bot] avatar Dec 02 '26 08:12 aft-alfonso[bot]