diff --git a/src/google/adk/agents/config_agent_utils.py b/src/google/adk/agents/config_agent_utils.py index 9f77336d8b8..67fc3f6c915 100644 --- a/src/google/adk/agents/config_agent_utils.py +++ b/src/google/adk/agents/config_agent_utils.py @@ -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}" diff --git a/tests/unittests/agents/test_agent_config.py b/tests/unittests/agents/test_agent_config.py index e112365ce6a..2541fe7e55d 100644 --- a/tests/unittests/agents/test_agent_config.py +++ b/tests/unittests/agents/test_agent_config.py @@ -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")