Skip to content

Security: GcsArtifactService missing input validation on path components allows cross-user artifact access (CWE-22) #6115

Closed

Description

@Ashutosh0x

Summary

GcsArtifactService._get_blob_prefix() constructs GCS blob paths by directly interpolating user_id, app_name, and session_id into f-strings without any validation. A user_id containing path traversal sequences (e.g., ../other-user) allows an attacker to read, write, or delete another user's artifacts in the same GCS bucket.

Vulnerability

File: src/google/adk/artifacts/gcs_artifact_service.py, lines 156-171

python def _get_blob_prefix(self, app_name, user_id, filename, session_id=None): # No validation on app_name, user_id, or session_id if self._file_has_user_namespace(filename): return f'{app_name}/{user_id}/user/{filename}' return f'{app_name}/{user_id}/{session_id}/{filename}'

Attack

A user_id of ../victim-user constructs:
app_name/../victim-user/user/filename -> victim-user/user/filename

This allows User A to:

  • Read User B's artifacts (_load_artifact)
  • Overwrite User B's artifacts (_save_artifact)
  • Delete User B's artifacts (_delete_artifact)

Comparison with FileArtifactService

FileArtifactService in the same package already validates these inputs via _validate_path_segment() (line 141-163), which rejects path separators, .., and null bytes. GcsArtifactService lacks this validation entirely.

Impact

  • Cross-user data access in multi-tenant deployments using GCS-backed artifact storage
  • Data destruction via cross-user artifact deletion
  • CWE-22: Improper Limitation of a Pathname to a Restricted Directory

Fix

Add _validate_gcs_path_segment() with the same checks as FileArtifactService._validate_path_segment(), and call it in _get_blob_prefix() before constructing blob paths.

References

Activity

  1. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Jun 14, 2026
  2. added theissue type on Jun 14, 2026
  3. surajksharma07 commented on Jun 15, 2026

    @surajksharma07
    Collaborator

    @Ashutosh0x confirmed the path traversal in _get_blob_prefix(), and the approach in PR #6116 (adding _validate_gcs_path_segment() to mirror what FileArtifactService already does) is exactly the right direction.

    Could you make sure the 10 unit tests cover all four operations (save, load, delete, list) before we kick off the review on #6116?

    Once you've verified the fix holds up end-to-end on your setup, we'll move forward with the review.

  4. Ashutosh0x commented on Jun 15, 2026

    @Ashutosh0x
    ContributorAuthor

    Thanks @surajksharma07! I've updated the tests in PR #6116 to cover all four operations. The test file now has:

    Unit tests (10) - _validate_gcs_path_segment() directly:

    • Valid user IDs pass
    • ../ traversal blocked
    • .. and . blocked
    • Forward slash, backslash, null byte blocked
    • Empty values blocked
    • app_name and session_id traversal blocked

    Operation-level tests (8) - through the async public API with mocked GCS client:

    • save_artifact - rejects traversal user_id, traversal app_name, null byte user_id
    • load_artifact - rejects traversal user_id, traversal session_id
    • delete_artifact - rejects traversal user_id, backslash user_id
    • list_artifact_keys - rejects traversal user_id, .. user_id

    Total: 18 tests covering all four operations and all validation rules.

    Each operation-level test uses unittest.mock to mock the GCS client, confirming that InputValidationError is raised before any GCS call is made. Ready for review!

  5. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    and removed
    request clarification[Status] The maintainer need clarification or more information from the author
    on Jun 16, 2026
  6. surajksharma07 commented on Jun 16, 2026

    @surajksharma07
    Collaborator

    @Ashutosh0x Confirmed, thanks — the 18 tests cover all four operations (save/load/delete/list) plus the segment-validation unit cases, and #6116 is green across CI (header-check, change-validation, CLA).

    Team is looking more into it.
    Thanks!

  7. added a commit that references this issue on Jul 7, 2026
    8718aef
  8. added a commit that references this issue on Aug 11, 2026
    59bd21d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

needs review[Status] The PR/issue is awaiting review from the maintainerservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions