Bug: Inline file extraction processes non-user messages in _extrac_and_replace_inline_files, leading to file injection and content corruption
Describe the bug
There is a subtle but critical bug in the function _extrac_and_replace_inline_files (file: src/google/adk/flows/llm_flows/_code_execution.py), which is responsible for extracting and handling inline files during code execution flows. The intended logic, as stated in the code comments, is to process only user messages when replacing inline data with file placeholders and injecting files into the code executor context. However, the current guard uses if content.role != 'user' and not content.parts: continue instead of the correct or. As a result, non-user messages (assistant or tool roles) that contain parts are also processed, which can:
- Corrupt conversation history by rewriting assistant/tool message parts to file placeholders.
- Inject unintended files into the code execution environment, potentially altering downstream executions and code behavior.
- Break the "user-only" intent and allow for non-user content to be treated as file inputs, which is both a data fidelity and security concern.
To Reproduce
- Construct an LlmRequest with a non-user message containing an inline_data part (e.g. an assistant message with a CSV attachment).
- Run a flow that triggers code execution preprocessing (calls
_extrac_and_replace_inline_files). - Observe that the non-user message is mutated to a file placeholder and the file is injected into the code executor context, even though it did not come from the user.
Expected behavior
- Only messages with
role='user'should have inline data extracted and replaced; all other roles must be ignored in this processing step. - No assistant/tool message parts should ever be rewritten or used to inject files into code execution.
Screenshots N/A
Desktop (please complete the following information):
- OS: Windows
- Python version (python -V): 3.13.2
- ADK version (pip show google-adk): >=1.10.0
Model Information: Not model-specific; the bug occurs in preprocessing before model invocation.
Additional context
- File:
src/google/adk/flows/llm_flows/_code_execution.py - Relevant code:
for i in range(len(llm_request.contents)):
content = llm_request.contents[i]
# Only process the user message.
if content.role != 'user' and not content.parts:
continue
- The intended guard should be:
if content.role != 'user' or not content.parts:
continue
- This bug allows arbitrary file injection and content rewriting from any assistant/tool message with inline parts, violating code execution safety and user data integrity.
- A function name typo (
_extrac_and_replace_inline_filesmissing a "t") further reduces maintainability. - This issue is not a duplicate of any known open issue (see open issues). Note: API access is limited to 30 results out of 509 total; please double-check full list.
Impact
- High severity: breaks core data flow assumptions and introduces risk of data corruption, file injection, and unpredictable code execution behaviors. Should be prioritized for patching.
References
Hello @0x-Professor
We recommend trying the latest ADK version to check if your issue is resolved with new release or not. If you still face the issue even with new version, could you please share code where you constructed LlmRequest to help us analyze this issue better?
This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.
This has been automatically closed because it has been marked as stale for over 7 days.