Uh oh!
There was an error while loading. Please reload this page.
Validate images before they enter conversation context - #33
Merged
Conversation
The CLI's Read tool detects images by file extension and base64-encodes them into content blocks. If a file has an image extension but contains non-image data (e.g. an HTML redirect from an auth-gated URL), the API rejects it with 400 "Could not process image". The bad block persists in conversation history, causing every subsequent turn to fail. Layer 1 — PreToolUse hook on Read: - Check magic bytes (PNG/JPEG/GIF/WebP signatures) and file size (<5MB) - Deny Read with clear error message if invalid — conversation intact - Detects HTML pages saved with image extensions Layer 1b — Nerve-sourced image validation (Telegram pipeline): - Validate base64 data before constructing content blocks - Replace invalid images with descriptive text block Layer 2 — Error handler railguard: - Detect "Could not process image/document" in generic exception handler - Clear sdk_session_id so next turn starts fresh CLI (no --resume) - Last resort for images entering via MCP tools or CLI internals Also fix pre-existing test_proxy failure: test_non_interactive_proxy_mode leaked host ANTHROPIC_API_KEY through patch.dict(clear=False).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test_non_interactive_proxy_mode— hostANTHROPIC_API_KEYleaked throughpatch.dict(clear=False)Context
On April 3, session
665441degot stuck in an infinite error loop after attempting to read images from a private GitHub issue. The CLI's Read tool base64-encoded what was likely an HTML auth redirect page (saved with a.pngextension), and the API rejected it. Since the CLI re-sends full conversation history on every turn, the bad image block poisoned the entire session.Test plan