Security: Fix path traversal and arbitrary code execution#5059
Open
l3tchupkt wants to merge 1 commit intogoogle:mainfrom
Open
Security: Fix path traversal and arbitrary code execution#5059l3tchupkt wants to merge 1 commit intogoogle:mainfrom
l3tchupkt wants to merge 1 commit intogoogle:mainfrom
Conversation
Fixes two critical vulnerabilities in ADK API server: 1. Path Traversal in agent_loader.py (CWE-22): - Added _validate_agent_path() to ensure agent_name resolves within agents_dir - Prevents directory traversal using .. sequences on all platforms - Called before loading YAML config from filesystem 2. Arbitrary Code Execution via importlib (CWE-470): - Added _SAFE_MODULE_PREFIXES allowlist to config_agent_utils.py - Restricts resolve_fully_qualified_name() to google.adk.* namespace - Also secured _resolve_agent_code_reference() and resolve_code_reference() 3. API Boundary Sanitization: - Added app_name validation to RunAgentRequest model - Rejects path traversal characters at HTTP API layer Author: Lakshmikanthan K <badassletchu@gmail.com>
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 free
to 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.
Description of Change
Problem:
Two security vulnerabilities exist in the ADK API server (
adk api_server/adk web):Path Traversal (CWE-22): The AgentLoader._load_from_yaml_config() method in src/google/adk/cli/utils/agent_loader.py directly joins
agents_dirwith the user-suppliedapp_nameparameter without validating the resolved path stays withinagents_dir. This allows an attacker to use..sequences (including URL-encoded Windows backslashes like%5C) to traverse outside the intended directory and load YAML config files from arbitrary filesystem locations.Arbitrary Code Execution (CWE-470): The resolve_fully_qualified_name() function in src/google/adk/agents/config_agent_utils.py calls
importlib.import_module()on strings read directly from YAML configuration files without any allowlisting or sandboxing. Combined with the path traversal, an attacker can place a malicious Python module and trigger its execution via YAML config references likebefore_model_callbacks.Solution:
Path Traversal Fix: Added _validate_agent_path() method that uses
Path.resolve()andPath.relative_to()to ensure the resolved agent path stays strictly withinagents_dir. This works on both Unix and Windows platforms.Import Restriction Fix: Added
_SAFE_MODULE_PREFIXESallowlist (frozenset({"google.adk."})) and applied security checks to:API Boundary Sanitization: Added
app_namevalidator to RunAgentRequest Pydantic model that rejects path traversal characters (..,/,\) at the HTTP API layer before processing.Testing Plan
Unit Tests:
Test Results:
Manual E2E Tests:
The fixes prevent the attack chain described in the vulnerability report:
..\evilor../evilinapp_nameis now blockedattacker_pkg.run.callback) are restricted togoogle.adk.*namespaceChecklist
Additional Context
CWE Classifications:
Affected Files:
Author: Lakshmikanthan K badassletchu@gmail.com