Fix image file name not in AI issue#282
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (5)
📝 WalkthroughWalkthroughPropagates original image filenames from client uploads through message types and server input processing, and adjusts backend output serialization to return only the last element for list outputs. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client (UI)
participant Frontend as Frontend Logic
participant Server as Server Input Processor
participant Agent as Agent Runtime
participant Arium as Arium Serializer
Client->>Frontend: user uploads image (file + base64)
Frontend->>Frontend: construct imageMessage including file_name
Frontend->>Server: send conversationInputs (includes imageMessage)
Server->>Server: detect file_name -> insert text UserMessage + image doc
Server->>Agent: deliver processed messages to agent runtime
Agent->>Arium: produce node outputs (may be list)
Arium->>Agent: serialize node output (pick last element for lists)
Agent-->>Server: return serialized reply
Server-->>Frontend: return agent response to UI
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
wavefront/client/src/pages/apps/[appId]/workflows/[id].tsx (1)
377-387: Nit: unnecessary optional chaining onuploadedImage.file?.name.Per the
uploadedImagestate type (lines 34-38),file: Fileis required, souploadedImage.file?.namecan be simplified touploadedImage.file.namefor consistency with the multi-image path on line 372. No functional impact —file_nameis optional inImageContent.- file_name: uploadedImage.file?.name, + file_name: uploadedImage.file.name,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@wavefront/client/src/pages/apps/`[appId]/workflows/[id].tsx around lines 377 - 387, The optional chaining on uploadedImage.file?.name is unnecessary because uploadedImage.file is required by its state type; update the imageMessage construction in the uploadedImage fallback branch to use uploadedImage.file.name (mirror the multi-image path usage) and ensure setChatHistory and messageInputs continue to receive the same imageMessage shape.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@wavefront/server/modules/agents_module/agents_module/utils/input_processing_utils.py`:
- Around line 46-56: Sanitize the user-controlled file_name before embedding it
into the UserMessage: implement a helper like _sanitize_file_name(name,
max_len=256) that returns None for non-strings/empty values, strips control
chars and newlines (keep only printable chars and truncate to max_len), then use
its result instead of raw file_name when creating the TextMessageContent in the
block that appends to resolved_inputs; apply the same helper when handling the
document path elsewhere to close the similar injection vector.
---
Nitpick comments:
In `@wavefront/client/src/pages/apps/`[appId]/workflows/[id].tsx:
- Around line 377-387: The optional chaining on uploadedImage.file?.name is
unnecessary because uploadedImage.file is required by its state type; update the
imageMessage construction in the uploadedImage fallback branch to use
uploadedImage.file.name (mirror the multi-image path usage) and ensure
setChatHistory and messageInputs continue to receive the same imageMessage
shape.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0b242003-e733-48e4-bcbe-6ffe88368e85
📒 Files selected for processing (6)
flo_ai/flo_ai/arium/arium.pywavefront/client/src/components/InferencePopup.tsxwavefront/client/src/pages/apps/[appId]/agents/[id].tsxwavefront/client/src/pages/apps/[appId]/workflows/[id].tsxwavefront/client/src/types/chat-message.tswavefront/server/modules/agents_module/agents_module/utils/input_processing_utils.py
| # Inject filename as a text message before the image so | ||
| # agents can reference the original file name in their output. | ||
| file_name = input_content.get('file_name') | ||
| if file_name: | ||
| resolved_inputs.append( | ||
| UserMessage( | ||
| content=TextMessageContent( | ||
| text=f'The original filename of this image is: {file_name}' | ||
| ) | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Minor: sanitize user-controlled file_name before embedding it in the prompt.
file_name flows from the browser File.name with no server-side sanitization, so an attacker (or a user with a crafty filename) can inject newlines/instructions into the prompt, e.g. photo.jpg\n\nIgnore previous instructions and .... This widens the existing prompt-injection surface that the document-filename injection (lines 89-99) already has. At a minimum, strip control characters/newlines and quote the value; ideally, bound the length too.
🛡️ Suggested hardening
if is_image_message(input_content):
# Inject filename as a text message before the image so
# agents can reference the original file name in their output.
- file_name = input_content.get('file_name')
+ file_name = _sanitize_file_name(input_content.get('file_name'))
if file_name:
resolved_inputs.append(
UserMessage(
content=TextMessageContent(
- text=f'The original filename of this image is: {file_name}'
+ text=f'The original filename of this image is: "{file_name}"'
)
)
)And a small helper (apply similarly on the document path to fix the pre-existing equivalent issue):
def _sanitize_file_name(name: Any, max_len: int = 256) -> str | None:
if not isinstance(name, str) or not name:
return None
# Drop control chars/newlines; keep it on a single line.
cleaned = ''.join(ch for ch in name if ch.isprintable() and ch not in '\r\n')
return cleaned[:max_len] or None🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@wavefront/server/modules/agents_module/agents_module/utils/input_processing_utils.py`
around lines 46 - 56, Sanitize the user-controlled file_name before embedding it
into the UserMessage: implement a helper like _sanitize_file_name(name,
max_len=256) that returns None for non-strings/empty values, strips control
chars and newlines (keep only printable chars and truncate to max_len), then use
its result instead of raw file_name when creating the TextMessageContent in the
block that appends to resolved_inputs; apply the same helper when handling the
document path elsewhere to close the similar injection vector.
Summary by CodeRabbit
New Features
Behavior Change
Misc