Validate FileArtifactService scope identifiers before building storage paths#5274
Open
petrmarinec wants to merge 1 commit intogoogle:mainfrom
Open
Validate FileArtifactService scope identifiers before building storage paths#5274petrmarinec wants to merge 1 commit intogoogle:mainfrom
petrmarinec wants to merge 1 commit intogoogle:mainfrom
Conversation
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
FileArtifactServicevalidates artifact filenames against traversal, but it still used rawuser_idandsession_idvalues when building the storage scope directories. Path separators or traversal segments in those identifiers could move storage outside the intended scope before the filename guard ran.Solution:
Validate
user_idandsession_idas single path components before path construction and reject absolute paths, embedded separators, and traversal segments. Added regression tests covering invalid scope identifiers for both user and session storage paths.Testing Plan
Unit Tests:
Passed locally:
PYTHONPATH=src pytest tests/unittests/artifacts/test_artifact_service.py -k "invalid_user_scope_identifiers or invalid_session_scope_identifiers or out_of_scope_paths"22 passedPassed in clean Linux Docker (
python:3.11-bookworm):pip install -e '.[test]'PYTHONPATH=src pytest tests/unittests/artifacts72 passedManual Validation:
origin/main,user_id='../../escape-target-current'causedFileArtifactService.save_artifact(...)to write outside the configured artifact root.InputValidationErrorand does not create the escaped directory.session_idalso raisesInputValidationErrorand does not create the escaped directory.Checklist
Additional context
This change keeps the existing filename traversal protections intact and closes the missing validation on the scope identifiers used to build the artifact storage paths.