Summary
FileArtifactService validates artifact filenames against traversal, but it still builds the user/session scope directories from raw user_id and session_id values. Path separators and .. segments in those identifiers can move storage outside the intended scope before the filename guard runs.
Affected code
src/google/adk/artifacts/file_artifact_service.py
Problem
_resolve_scoped_artifact_path() correctly keeps filename inside the provided scope root. However, FileArtifactService._base_root() and _session_artifacts_dir() use raw user_id and session_id path components.
As a result:
- crafted
user_id values can escape the configured artifact root
- crafted
session_id values can escape the intended per-user session scope
Expected behavior
user_id and session_id should remain single path components when used to construct artifact storage paths.
Proposed fix
Validate scope identifiers before path construction and reject values that are absolute paths, contain separators, or contain traversal segments.
Validation
I have a PR prepared that:
- validates
user_id and session_id as single path components
- adds regression tests for invalid scope identifiers
- reproduces the escape on current
origin/main
- passes
pytest tests/unittests/artifacts in clean Linux Docker
Summary
FileArtifactServicevalidates artifact filenames against traversal, but it still builds the user/session scope directories from rawuser_idandsession_idvalues. Path separators and..segments in those identifiers can move storage outside the intended scope before the filename guard runs.Affected code
src/google/adk/artifacts/file_artifact_service.pyProblem
_resolve_scoped_artifact_path()correctly keepsfilenameinside the provided scope root. However,FileArtifactService._base_root()and_session_artifacts_dir()use rawuser_idandsession_idpath components.As a result:
user_idvalues can escape the configured artifact rootsession_idvalues can escape the intended per-user session scopeExpected behavior
user_idandsession_idshould remain single path components when used to construct artifact storage paths.Proposed fix
Validate scope identifiers before path construction and reject values that are absolute paths, contain separators, or contain traversal segments.
Validation
I have a PR prepared that:
user_idandsession_idas single path componentsorigin/mainpytest tests/unittests/artifactsin clean Linux Docker