Skip to content

Normalize fd redirects in command safety check#208

Closed
backnotprop wants to merge 2 commits intomainfrom
claude/fix-web-content-fetching-UpYbs
Closed

Normalize fd redirects in command safety check#208
backnotprop wants to merge 2 commits intomainfrom
claude/fix-web-content-fetching-UpYbs

Conversation

@backnotprop
Copy link
Owner

Summary

Updated the isSafeCommand function to normalize file descriptor redirects before checking against destructive patterns. This prevents legitimate commands with safe output redirections from being incorrectly flagged as unsafe.

Key Changes

  • Added normalization step that strips common safe file descriptor redirects before destructive pattern matching:
    • N>/dev/null - redirects any file descriptor to /dev/null
    • N>&M - file descriptor merges (e.g., 2>&1)
    • &>/dev/null - bash shorthand for redirecting all output to /dev/null
  • The normalization only applies to destructive pattern checking, preserving the original command for safe pattern validation

Implementation Details

The fix addresses a false positive issue where commands like curl ... 2>/dev/null or curl ... 2>&1 | head would be incorrectly blocked by the > destructive pattern rule. By removing these safe redirections before pattern matching, we allow legitimate commands while maintaining security checks for actual destructive operations.

https://claude.ai/code/session_01Jk1P5aZPERSzrmA9urfb4B

claude added 2 commits March 3, 2026 20:04
The `>` redirect detection in isSafeCommand() was falsely blocking common
curl patterns like `curl ... 2>/dev/null` and `curl ... 2>&1 | head`.
This prevented agents from fetching web content (e.g. via jina.ai or
markdown.new) during planning mode.

Fix: strip safe fd redirects (2>/dev/null, 2>&1, &>/dev/null) from the
command before checking against destructive patterns, while still
blocking actual file redirects like `> output.txt`.

https://claude.ai/code/session_01Jk1P5aZPERSzrmA9urfb4B
The planning phase system prompt says "bash (read-only commands only)"
which causes models to self-censor and not attempt curl/wget for web
content fetching (e.g. jina.ai, markdown.new). Update the prompt to
explicitly mention curl/wget is allowed, and mention web fetching in
the explore step instructions.

https://claude.ai/code/session_01Jk1P5aZPERSzrmA9urfb4B
@backnotprop backnotprop closed this Mar 5, 2026
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.

2 participants