claude-code - ✅(Solved) Fix Bug: Potential injection via unescaped prompt text in Ralph Wiggum setup heredoc [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52408Fetched 2026-04-24 06:07:58
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×1

In plugins/ralph-wiggum/scripts/setup-ralph-loop.sh (lines 140-150), the user-provided prompt text is inserted directly into a markdown file via a heredoc without any escaping:

cat > .claude/ralph-loop.local.md <<EOF
...
$PROMPT
EOF

If the prompt contains the literal string EOF on its own line, or shell-special characters, this could cause:

  • Premature heredoc termination, resulting in a truncated or malformed file
  • Unexpected shell expansion of variables or commands within the prompt text

Root Cause

In plugins/ralph-wiggum/scripts/setup-ralph-loop.sh (lines 140-150), the user-provided prompt text is inserted directly into a markdown file via a heredoc without any escaping:

cat > .claude/ralph-loop.local.md <<EOF
...
$PROMPT
EOF

If the prompt contains the literal string EOF on its own line, or shell-special characters, this could cause:

  • Premature heredoc termination, resulting in a truncated or malformed file
  • Unexpected shell expansion of variables or commands within the prompt text

Fix Action

Fixed

PR fix notes

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

Description (problem / solution / changelog)

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

Changed files

  • plugins/ralph-wiggum/scripts/setup-ralph-loop.sh (modified, +9/-4)

Code Example

cat > .claude/ralph-loop.local.md <<EOF
...
$PROMPT
EOF
RAW_BUFFERClick to expand / collapse

Description

In plugins/ralph-wiggum/scripts/setup-ralph-loop.sh (lines 140-150), the user-provided prompt text is inserted directly into a markdown file via a heredoc without any escaping:

cat > .claude/ralph-loop.local.md <<EOF
...
$PROMPT
EOF

If the prompt contains the literal string EOF on its own line, or shell-special characters, this could cause:

  • Premature heredoc termination, resulting in a truncated or malformed file
  • Unexpected shell expansion of variables or commands within the prompt text

Expected Behavior

User-provided prompt text should be safely written to the file without risk of heredoc injection or shell expansion.

Suggested Fix

Use a quoted heredoc delimiter to prevent shell expansion, or write the file using printf or a similar method that does not interpret the content.

extent analysis

TL;DR

Use a quoted heredoc delimiter or an alternative method like printf to safely write user-provided prompt text to the file.

Guidance

  • Identify potential security risks: heredoc injection and shell expansion can lead to premature termination or malformed files.
  • Consider using a quoted heredoc delimiter to prevent shell expansion, e.g., cat > .claude/ralph-loop.local.md <<'EOF'.
  • Alternatively, use printf to write the file content without interpreting the prompt text, e.g., printf '%s' "$PROMPT" > .claude/ralph-loop.local.md.
  • Verify the fix by testing with prompt texts containing special characters or the literal string EOF.

Example

cat > .claude/ralph-loop.local.md <<'EOF'
...
$PROMPT
EOF

or

printf '%s' "$PROMPT" > .claude/ralph-loop.local.md

Notes

This fix assumes that the prompt text does not need to be expanded by the shell. If expansion is required, alternative approaches may be necessary.

Recommendation

Apply workaround: use a quoted heredoc delimiter or printf to prevent heredoc injection and shell expansion, as it provides a safe and straightforward solution to the identified security risks.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING