Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/google/adk/agents/config_agent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,14 @@ def resolve_agent_reference(
The created agent instance.
"""
if ref_config.config_path:
if os.path.isabs(ref_config.config_path):
# `os.path.isabs` is platform-dependent: on Windows a root-relative path
# such as `/etc/passwd` has no drive, so it is not "absolute" and would
# slip past this guard into the traversal check below, which reports a
# different error (or, across drives, an unhandled commonpath error). A
# config_path rooted under either platform's spelling is absolute here.
if os.path.isabs(
ref_config.config_path
) or ref_config.config_path.startswith(("/", "\\")):
raise ValueError(
"Absolute paths are not allowed in AgentRefConfig config_path:"
f" {ref_config.config_path!r}"
Expand Down
17 changes: 17 additions & 0 deletions tests/unittests/agents/test_agent_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,23 @@ def test_resolve_agent_reference_blocks_absolute_path():
)


def test_resolve_agent_reference_blocks_root_relative_path():
"""A root-relative config_path counts as absolute on every platform.

On Windows `os.path.isabs` is False for a path that has a root but no
drive, so both spellings are rejected explicitly.
"""
for config_path in ("/etc/passwd", "\\etc\\passwd"):
ref_config = AgentRefConfig(config_path=config_path)
with pytest.raises(
ValueError,
match="Absolute paths are not allowed in AgentRefConfig config_path",
):
config_agent_utils.resolve_agent_reference(
ref_config, "/workspace/main.yaml"
)


def test_resolve_agent_reference_blocks_path_traversal():
"""Verify resolve_agent_reference raises ValueError for path traversal."""
ref_config = AgentRefConfig(config_path="../outside.yaml")
Expand Down
Loading