fix(safety): allow image-only messages without text content#1208
fix(safety): allow image-only messages without text content#1208smkrv wants to merge 1 commit intonearai:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a bug where messages containing only attachments, such as image-only messages without captions, were incorrectly rejected by the safety validation system. The change introduces a conditional bypass for the empty-input validation when attachments are present, ensuring that these messages are properly handled and processed downstream, thus improving the robustness of message processing across various channels. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a bug where messages containing only attachments without any text were being rejected by the safety validation. The fix modifies process_user_input to bypass the empty-input validation check when attachments are present, as the message content is augmented with attachment information downstream in the pipeline. The change is localized to the safety validation logic and resolves the described issue.
Messages with attachments (e.g., photos sent via Telegram) but no text caption were rejected by safety validation with "Input cannot be empty". The empty-input check now skips when the message has attachments, since the attachment pipeline (augment_with_attachments) will provide content downstream. Non-empty text messages still go through full validation. Fixes image/file-only messages being rejected across all channels.
e2afa3a to
903739b
Compare
zmanian
left a comment
There was a problem hiding this comment.
Review: REQUEST CHANGES
Correct diagnosis -- image-only messages (empty content + attachments) were rejected by the Validator before the attachment pipeline could extract useful content. The bypass is safe: empty strings contain no injection payload.
Issues (should fix):
-
Missing regression test at the
thread_opslevel. The new tests only prove the validator rejects empty input (already true). The actual bypass logic inthread_ops.rshas no test. Perreview-discipline.md: "Every bug fix must include a test that would have caught the bug." Need a test exercisingprocess_user_inputwith empty content + non-empty attachments. -
Incomplete bypass. After skipping
validate_input,check_policy(content)andscan_inbound_for_secrets(content)still run on the empty string (lines ~258 and ~269 in thread_ops.rs). Both are harmless on empty input, but semantically wrong and confusing for future maintainers. The bypass should cover all three checks consistently when content is empty and attachments are present.
Note (not blocking, worth tracking separately):
augment_with_attachments produces content from image transcripts and extracted text that never passes through safety validation (validate_input, check_policy, scan_inbound_for_secrets). An adversary could embed prompt injection in an image transcript or PDF text. This predates this PR and is not made worse by it, but is worth a follow-up issue.
What's good:
- Narrowly scoped fix (12 lines of production code)
- Bypass lives in the caller, not the validator -- preserves validator invariants
- Security analysis: bypass only fires on literally empty strings, non-empty messages still get full safety checks
- CI all green
Problem
Messages with attachments (photos, files) but no text caption are rejected by safety validation:
This affects all channels (Telegram, web, etc.) when users send image-only messages.
Root cause:
SafetyLayer::validate_input(content)inthread_ops.rsrejects empty strings. For image-only messages,contentis empty because the text portion has no caption — but the message has valid attachments that get processed downstream byaugment_with_attachments().Fix
Skip the empty-input validation check when the message has attachments. The attachment pipeline will provide content (image descriptions, extracted text) downstream. Non-empty text messages still go through full safety validation.
Testing
cargo test)cargo clippy --all-features)