Skip to content

fix(artifacts): validate user_id and session_id in FileArtifactService path construction#5111

Open
vnykmshr wants to merge 1 commit intogoogle:mainfrom
vnykmshr:fix/validate-artifact-path-segments
Open

fix(artifacts): validate user_id and session_id in FileArtifactService path construction#5111
vnykmshr wants to merge 1 commit intogoogle:mainfrom
vnykmshr:fix/validate-artifact-path-segments

Conversation

@vnykmshr
Copy link
Copy Markdown

@vnykmshr vnykmshr commented Apr 2, 2026

Fixes #5110.

_base_root and _session_artifacts_dir pass user_id and session_id directly into Path() construction. The existing _resolve_scoped_artifact_path guards the filename, but the scope root itself is built from these unvalidated values - so traversal segments escape root_dir before the filename check runs.

Adds _validate_path_segment, using the same resolve(strict=False) + relative_to() pattern from _resolve_scoped_artifact_path, and applies it in both functions.

Testing plan

7 new test cases: user_id traversal (3 parametrized), session_id traversal (3 parametrized), delete-path traversal (confirms shutil.rmtree unreachable with crafted session_id). FILE service only - GCS and InMemory are not affected.

47 passed (artifacts)
5165 passed, 1 skipped (full suite)

…e path construction

_base_root and _session_artifacts_dir used user_id and session_id
directly in Path construction without checking for traversal segments.
A crafted value (e.g. "../../x") could escape the storage root.

Add _validate_path_segment using the same resolve()+relative_to()
guard already applied to filenames, and wire it into both functions.
@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileArtifactService: user_id and session_id not validated for path traversal

2 participants