fix: validate path segments in GcsArtifactService to prevent cross-user artifact access#6116
fix: validate path segments in GcsArtifactService to prevent cross-user artifact access#6116Ashutosh0x wants to merge 4 commits into
Conversation
…er artifact access
|
Hi @surajksharma07 — this fixes a path traversal (CWE-22) in GcsArtifactService reported in #6115. The Note: This is the same vulnerability class as #5603 / PR #5927 (which I also fixed). Let me know if you'd like any adjustments! |
|
Hi @Ashutosh0x , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit and mypy-diff tests and also fix the formatting errors before we can proceed with a review. |
Summary
Fix for #6115 - Validate
user_id,app_name, andsession_idinGcsArtifactService._get_blob_prefix()to prevent path traversal attacks that allow cross-user artifact access.Problem
GcsArtifactService._get_blob_prefix()constructs GCS blob paths by directly interpolating user-supplied identifiers into f-strings:python return f'{app_name}/{user_id}/user/{filename}' return f'{app_name}/{user_id}/{session_id}/{filename}'No validation is performed on
user_id,app_name, orsession_id. A malicioususer_idlike../other-userescapes the intended namespace, enabling cross-user artifact read/write/delete.Note:
FileArtifactServicein the same package already validates these inputs via_validate_path_segment(). This PR bringsGcsArtifactServiceto parity.Fix
Added
_validate_gcs_path_segment()static method that rejects:/and\).and..)Called in
_get_blob_prefix()before constructing any blob path.Testing
Added
tests/unittests/artifacts/test_gcs_artifact_path_traversal.pywith 10 tests covering:../other-usertraversal blocked..and.blockedbash pytest tests/unittests/artifacts/test_gcs_artifact_path_traversal.py -vFixes #6115