Skip to content

fix: prevent heredoc injection in ralph loop setup script#52418

Open
sakal-s wants to merge 1 commit intoanthropics:mainfrom
sakal-s:fix/heredoc-injection-ralph-setup
Open

fix: prevent heredoc injection in ralph loop setup script#52418
sakal-s wants to merge 1 commit intoanthropics:mainfrom
sakal-s:fix/heredoc-injection-ralph-setup

Conversation

@sakal-s
Copy link
Copy Markdown

@sakal-s sakal-s commented Apr 23, 2026

Summary

  • Split the state file write into two steps: a heredoc for frontmatter (where variable expansion is intentional) and printf for the prompt (where text should be written verbatim)
  • Previously, the prompt was in an unquoted heredoc which could cause:
    • Early termination if the prompt contained EOF on its own line
    • Unintended shell expansion of $VAR or $(cmd) in the prompt text

Test plan

  • Test with a normal prompt — state file is created correctly
  • Test with a prompt containing $HOME — should be written literally, not expanded
  • Test with a prompt containing EOF on its own line — file should not be truncated

Fixes #52408

🤖 Generated with Claude Code

The prompt text was inserted into an unquoted heredoc (<<EOF), which
caused two issues:
1. If the prompt contained 'EOF' on its own line, the heredoc would
   terminate early, producing a truncated state file.
2. Shell variables ($VAR) and command substitutions ($(cmd)) in the
   prompt would be expanded rather than written literally.

Write the file in two steps: a heredoc for the frontmatter (where
variable expansion is intentional) and printf for the prompt (where
the text should be written verbatim).

Fixes anthropics#52408

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Potential injection via unescaped prompt text in Ralph Wiggum setup heredoc

2 participants