fix: prevent path traversal in download_file via Content-Disposition header#180
Open
kartikganesh wants to merge 1 commit into
Open
fix: prevent path traversal in download_file via Content-Disposition header#180kartikganesh wants to merge 1 commit into
kartikganesh wants to merge 1 commit into
Conversation
…header A malicious server could return a Content-Disposition header with a filename containing path traversal sequences (e.g. "../../.bashrc"), causing files to be written outside the intended download directory. This fix applies os.path.basename() to sanitize the filename after extraction from headers or URL, ensuring it cannot escape the target directory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
download_file()where a malicious server could return aContent-Dispositionheader with directory traversal sequences (e.g.filename="../../.bashrc")join_path(), allowing file writes outside the intended download directoryos.path.basename()to strip directory components from the extracted filenameSecurity Impact
Severity: High
Type: CWE-22 (Path Traversal)
A malicious HTTP server can cause arbitrary file writes on the filesystem by responding with a crafted
Content-Dispositionheader:Any application using
fsutil.download_file()to download from untrusted URLs is affected.Test plan
download_filewith normal URLs still works../sequences are sanitized to just the basenamefilename="../../../") fall back to UUID name🤖 Generated with Claude Code