fix: enforce path boundary in built-in agent file tools (path traversal)#5615
Open
adilburaksen wants to merge 1 commit intogoogle:mainfrom
Open
fix: enforce path boundary in built-in agent file tools (path traversal)#5615adilburaksen wants to merge 1 commit intogoogle:mainfrom
adilburaksen wants to merge 1 commit intogoogle:mainfrom
Conversation
resolve_root_directory.py: prevent path traversal in Agent Builder Assistant - Add _validate_root_directory() to reject absolute paths and '..' from session-state root_directory (closes Flaw 2 from the security report) - Remove the unconditional 'if is_absolute: return' bypass that let any absolute file_path skip root enforcement (closes Flaw 1) - Resolve both candidate and root to real paths, then enforce the boundary with candidate.relative_to(resolved_root); ValueError on escape Affected tools: read_files, write_files, delete_files, explore_project Attack vector: POST /apps/__agent session state + read_files with '/' root_directory or absolute file_path → arbitrary file read/write/delete
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.
Summary
Fixes a path traversal vulnerability in the Agent Builder Assistant's file tools
(
read_files,write_files,delete_files,explore_project).Supersedes #5413 — the YAML callback RCE portion of #5413 was already addressed
internally (2026-04-21). This PR contains only the
resolve_root_directory.pyfix.Root cause
Two flaws in
resolve_root_directory.py:Flaw 1 — Absolute path bypass (line 51–52 before fix):
Any absolute path passed to
read_files/write_files/delete_fileswas returneddirectly, allowing
/etc/passwd,/root/.ssh/id_rsa, etc.Flaw 2 — Attacker-controlled
root_directory(line 56–57 before fix):Session state is set via
POST /apps/{app_name}/users/{user}/sessions. An attackercan inject
root_directory: "/"to redirect all relative file paths under/.Fix
_validate_root_directory(): rejects absolute paths and..components fromsession-state
root_directoryfile_pathvalues are resolved toa real path and verified to be within
resolved_rootviacandidate.relative_to()is_absolute → returnbypassAttack scenario (for context)
No authentication bypass required —
/runand session creation have no auth by defaultin dev mode; the intended security boundary is container isolation (documented in ADK).
This PR does not change that model — it closes the path escape within the boundary.
Testing
Added
_validate_root_directory()unit tests cover: absolute path rejection,..component rejection, null-byte rejection, valid relative paths pass through.