Skip to content

Contain remote log upload paths within base_log_folder - #72162

Open
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:fix-remote-log-path-containment
Open

Contain remote log upload paths within base_log_folder#72162
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:fix-remote-log-path-containment

Conversation

@potiuk

@potiuk potiuk commented Aug 27, 2026

Copy link
Copy Markdown
Member

Why

S3RemoteLogIO.upload, GCSRemoteLogIO.upload and WasbRemoteLogIO.upload build the local log path as base_log_folder.joinpath(path), then read that file and — when delete_local_copy is set — shutil.rmtree(os.path.dirname(local_loc)).

joinpath and PurePath.relative_to are purely lexical: neither normalises ... A relative log path containing .. therefore resolves outside base_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:

base = self.base_log_folder.resolve()
local_path = (raw if raw.is_absolute() else base / raw).resolve()
try:
    local_path.relative_to(base)
except ValueError:
    self.log.warning("Skipping deletion: path %s is outside base_log_folder %s", local_path, base)
    return

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

  • Add a resolve() + relative_to(base_log_folder) containment check to upload() in the S3, GCS and WASB remote log handlers, skipping with a warning when the path escapes — mirroring the CloudWatch handler.
  • The check runs before the file is read, so it covers both the read/upload and the delete_local_copy deletion.
  • Add a test to each of the three provider test suites covering the traversing path and asserting the file and its parent survive.

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

moto and 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_compile and ruff check clean on all six changed files.
  • The containment arithmetic itself, exercised against real temporary directories across six cases: normal relative path (allowed), .. 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

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.
@boring-cyborg boring-cyborg Bot added area:logging area:providers provider:amazon AWS/Amazon - related issues provider:google Google (including GCP) related issues provider:microsoft-azure Azure-related issues labels Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:logging area:providers provider:amazon AWS/Amazon - related issues provider:google Google (including GCP) related issues provider:microsoft-azure Azure-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant