Skip to content

Bound the Guard's Shift-Line Heredoc Work So a Crafted Command Cannot Outrun the Hook #2198

Closed

Description

@ptr727

Problem

The #2112 fix on branch feature/auto-2112 (handoff #2123) makes _heredoc_shift_ends in host-setup/agent-safety/claude/gh-write-guard.py do work quadratic in the openers on a line holding (( or $[, times the lines after it, where develop does work linear in the openers. A PreToolUse hook that runs past its timeout fails open, so a command slow enough to read lets the command run unjudged.

Reproduce (constructed)

A command of about 55 KB, one : $((0)) line followed by 1000 << X openers, then 3000 filler lines, takes about 78 s on the branch against about 3 s on develop. No agent writes this shape by accident.

Done looks like

A shift line reads at most a bounded number of openers before the command is treated as past the reading limit and denied, and a self-test row pins a command past that bound as a deny.

Found by the third local strict review pass of the #2112 fix, and filed as a follow-up per decision #2126.

Activity

  1. added
    bug
    agents
    on Oct 1, 2026
  2. added a commit that references this issue on Oct 1, 2026
    658034f
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

    agentsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions