This repository was archived by the owner on Mar 3, 2026. It is now read-only.
fix: Implement path containment to prevent traversal attacks#2654
Merged
ddelgrosso1 merged 10 commits intomainfrom Oct 6, 2025
Merged
fix: Implement path containment to prevent traversal attacks#2654ddelgrosso1 merged 10 commits intomainfrom
ddelgrosso1 merged 10 commits intomainfrom
Conversation
This patch introduces strict path validation in TransferManager.downloadManyFiles to mitigate Arbitrary File Write and Path Traversal vulnerabilities. The fix includes two layers of defense: 1. Rejects Absolute Paths: Immediately throws an error if the object name is an absolute path (e.g., /etc/passwd). 2. Containment Check: Uses path.resolve to normalize the destination path and verify it remains strictly within the intended baseDir, preventing traversal using ../ sequences. SECURITY NOTE: This changes behavior by actively rejecting files with malicious path segments that were previously susceptible to writing outside the target directory.
…y creation This commit resolves several critical issues in the `downloadManyFiles` logic related to path handling, destination assignment, and concurrent directory creation, enabling proper execution of bulk downloads and passing relevant tests.
Avoids redundant file system calls (fsp.mkdir) when downloading multiple files within the same directory. The call, while idempotent, was being performed for every file download, leading to unnecessary I/O overhead. This commit introduces a to track directories that have already been created within a single call, ensuring that is executed only once per unique destination directory path.
ddelgrosso1
reviewed
Sep 29, 2025
Moves the logic for resolving and validating the base download directory (`baseDir`, including initial path traversal checks) out of `downloadManyFiles` and into the private helper `_resolveAndValidateBaseDir`. This change cleans up the primary download execution path, making the file-by-file iteration loop more focused and readable.
ddelgrosso1
reviewed
Oct 1, 2025
| promises.push( | ||
| limit(async () => { | ||
| const destination = passThroughOptionsCopy.destination; | ||
| if (!createdDirectories.has(destinationDir)) { |
Contributor
There was a problem hiding this comment.
Why do we need a separate variable to track which directories have been created?
Contributor
Author
There was a problem hiding this comment.
The mkdir call is now performed on every iteration for every file, which could introduce a slight performance overhead due to redundant fs calls, especially if many files are in the same directory. While fsp.mkdir with recursive: true handles existing directories gracefully, you could optimize this by tracking created directories in a Set to avoid repeated calls for the same directory.
ddelgrosso1
reviewed
Oct 1, 2025
ddelgrosso1
reviewed
Oct 1, 2025
Removes the 'SECURITY_ABSOLUTE_PATH_REJECTED' & 'SECURITY_PATH_TRAVERSAL_REJECTED' code assignment from the thrown RequestError. The corresponding test assertion is updated to check the error message and type instead of the removed .code property.
ddelgrosso1
approved these changes
Oct 6, 2025
This was referenced Oct 29, 2025
6 tasks
6 tasks
6 tasks
ddelgrosso1
added a commit
that referenced
this pull request
Oct 30, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
Impact
Testing
Additional Information
Checklist
Fixes #