Validate downloaded paths stay within the destination directory in SFTPHook.retrieve_directory#67985
Merged
potiuk merged 1 commit intoJun 4, 2026
Conversation
…TPHook.retrieve_directory SFTPHook.retrieve_directory and retrieve_directory_concurrently build each local destination path by joining the local directory with a path derived from directory-entry names returned by the remote SFTP server. Because those names can contain ".." components, the recursive download could write outside the configured local destination directory. Add a containment check (_validate_within_directory) that resolves each computed local path and refuses to write when it falls outside the destination directory, applied to both the serial and concurrent retrieval paths. Generated-by: Claude Opus 4.8 (1M context) following the guidelines at https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions
dabla
approved these changes
Jun 4, 2026
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.
SFTPHook.retrieve_directoryandretrieve_directory_concurrentlybuild eachlocal destination path by joining the local directory with a path derived from
directory-entry names returned by the remote SFTP server. Because those names
can contain
..components, the recursive download could write outside theconfigured local destination directory.
This adds a containment check (
_validate_within_directory) that resolves eachcomputed local path and refuses to write when it falls outside the destination
directory, applied to both the serial and concurrent retrieval paths.
Tests
retrieve_directoryraises whenget_tree_mapyields atraversing entry, and nothing is written outside the destination
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Opus 4.8 (1M context) following the guidelines at
https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions