Skip to content

Commit c04372a

Browse files
adilburaksenclaude
andcommitted
fix(agents): prevent path traversal in AgentTool config_path resolution
Absolute config_path values were accepted unconditionally, and relative paths were joined without boundary validation, allowing traversal outside the agent directory via "../../../etc/passwd" style inputs. Fix: reject absolute paths; for relative paths, verify the normalized result stays within the parent agent's directory before loading. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7e61b51 commit c04372a

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/google/adk/agents/config_agent_utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,21 @@ def resolve_agent_reference(
157157
"""
158158
if ref_config.config_path:
159159
if os.path.isabs(ref_config.config_path):
160-
return from_config(ref_config.config_path)
161-
else:
162-
return from_config(
163-
os.path.join(
164-
os.path.dirname(referencing_agent_config_abs_path),
165-
ref_config.config_path,
166-
)
160+
raise ValueError(
161+
f"Absolute paths are not allowed in AgentTool config_path:"
162+
f" {ref_config.config_path!r}"
167163
)
164+
agent_dir = os.path.dirname(referencing_agent_config_abs_path)
165+
resolved_path = os.path.normpath(
166+
os.path.join(agent_dir, ref_config.config_path)
167+
)
168+
canonical_agent_dir = os.path.normpath(agent_dir)
169+
if not resolved_path.startswith(canonical_agent_dir + os.sep):
170+
raise ValueError(
171+
f"Path traversal detected: config_path {ref_config.config_path!r}"
172+
" resolves outside the agent directory"
173+
)
174+
return from_config(resolved_path)
168175
elif ref_config.code:
169176
return _resolve_agent_code_reference(ref_config.code)
170177
else:

0 commit comments

Comments
 (0)