Skip to content

A Heredoc Body Kept as the Safe Direction Vouches for a Wait-Loop Bound #2063

Closed as not planned

Description

@ptr727

Problem

_heredoc_openers in gh-write-guard.py keeps a heredoc's body as commands in three cases, each commented as the safe direction:

  • a tag _HEREDOC_TAG rejects, such as <<1;
  • the bare - tag of << -;
  • a shell name anywhere in the heredoc's pipeline, including one that is only an argument, as in echo bash <<EOF.

That is the safe direction for a rule that denies on what a body holds. For the wait-loop rule it is not, because a comparison in a kept body vouches for a loop whose condition carries no bound, the same harm #2059 fixed for a line holding ((.

Reproduce (constructed)

Each of these is allowed on develop and loops under timeout 3 bash until the timeout kills it:

while [ -e / ] <<1
[ x -lt 5 ]
1
do sleep 1; done
while [ -e / ] << -
[ x -lt 5 ]
-
do sleep 1; done
while echo bash >/dev/null <<EOF
[ x -lt 5 ]
EOF
do sleep 1; done

Done looks like

Each command above is denied, and a self-test row pins it. The comments calling each keep the safe direction, and the root README's "Two heredoc limits" paragraph, then say which rule each keep is safe for.

Found by the local strict review of the #2059 fix (handoff #2061). It is older than that fix.

Activity

  1. added
    bug
    agents
    pre-existing
    on Sep 29, 2026
  2. ptr727 commented on Sep 30, 2026

    @ptr727
    OwnerAuthor

    Another route to the same harm, found by the local strict review of the #2059 fix and reproduced on develop at 4c9087d: an apostrophe in a trailing comment makes _context_lex raise on the opener line, and the _operator_tokens fallback then keeps an unspaced <<EOF as one word, so no reading strips the body. Allowed, although bash opens the heredoc and the loop's condition is only [ -e /x ]:

    while [ -e /x ] <<EOF # don't
    [ x -lt 5 ]
    EOF
    do sleep 1; done

    The spaced << EOF form denies correctly.

  3. ptr727 commented on Oct 8, 2026

    @ptr727
    OwnerAuthor

    Declined per #2517, approved by the maintainer, under GOVERNANCE.md "Trust Boundaries and Hardening Effort": The guard backstops an agent's own mistakes, and this is a command shape built to defeat it rather than one an agent session writes, so a miss does not realistically occur. See #2517 for the per-issue reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentsbugpre-existing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions