Contain remote log upload paths within base_log_folder - #72162
Open
potiuk wants to merge 1 commit into
Open
Conversation
The S3, GCS and WASB remote log handlers build the local log path with base_log_folder.joinpath(path) and then read it and, when delete_local_copy is set, shutil.rmtree its parent. Both joinpath and PurePath.relative_to are purely lexical and do not normalise '..', so a relative log path containing '..' resolves outside base_log_folder: its contents are uploaded to the remote log store and its parent directory is removed. The CloudWatch handler in the same package already guards this exact operation with resolve() + relative_to(base) and skips with a warning. This ports that check to the other three handlers so the behaviour is consistent across remote log destinations, and adds a test to each covering both the traversing and the legitimate case. Paths that resolve inside base_log_folder are unaffected, including relative paths containing '..' segments that stay within the folder.
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.
Why
S3RemoteLogIO.upload,GCSRemoteLogIO.uploadandWasbRemoteLogIO.uploadbuild the local log path asbase_log_folder.joinpath(path), then read that file and — whendelete_local_copyis set —shutil.rmtree(os.path.dirname(local_loc)).joinpathandPurePath.relative_toare purely lexical: neither normalises... A relative log path containing..therefore resolves outsidebase_log_folder, so its contents get uploaded to the remote log store and its parent directory gets removed.CloudWatchRemoteLogIO.upload, in the same package, already guards exactly this operation:So the correct behaviour is already established here — three of the four remote log handlers just don't have it. This makes them consistent.
What
resolve()+relative_to(base_log_folder)containment check toupload()in the S3, GCS and WASB remote log handlers, skipping with a warning when the path escapes — mirroring the CloudWatch handler.delete_local_copydeletion.Compatibility
No behaviour change for paths that resolve inside
base_log_folder. That explicitly includes relative paths with internal..segments that stay within the folder (e.g.dag_id=a/../1.log), and absolute paths inside the folder — both verified.Testing
motoand the other provider test dependencies aren't available in my local environment, so I could not execute the three provider suites — CI needs to run them. What I did verify locally:py_compileandruff checkclean on all six changed files...traversal (blocked), deep traversal (blocked), absolute inside base (allowed), absolute outside base (blocked), and internal..staying inside (allowed — confirming no false positives on legitimate paths).🤖 Generated with Claude Code