Harden Content-Disposition filename sanitization in download_file to prevent path traversal#181
Harden Content-Disposition filename sanitization in download_file to prevent path traversal#181Copilot wants to merge 3 commits into
download_file to prevent path traversal#181Conversation
Agent-Logs-Url: https://github.com/fabiocaccamo/python-fsutil/sessions/32602292-a86d-4d8e-8262-dae539be404a Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #181 +/- ##
==========================================
+ Coverage 98.33% 98.46% +0.13%
==========================================
Files 13 13
Lines 780 781 +1
==========================================
+ Hits 767 769 +2
+ Misses 13 12 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| filename_match = re.search(filename_pattern, content_disposition) | ||
| if filename_match: | ||
| filename = filename_match.group(1) | ||
| filename = os.path.basename(filename_match.group(1)) |
| filename_match = re.search(filename_pattern, content_disposition) | ||
| if filename_match: | ||
| filename = filename_match.group(1) | ||
| filename = os.path.basename(filename_match.group(1)) |
Agent-Logs-Url: https://github.com/fabiocaccamo/python-fsutil/sessions/79e7623b-5e54-484b-838b-9b58f5877733 Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/fabiocaccamo/python-fsutil/sessions/6af6fe4f-2ec3-4e2e-91e3-8ec6fa5cbe5f Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Applied in |
download_file to prevent path traversaldownload_file to prevent path traversal
Describe your changes
download_fileaccepted an untrusted filename fromContent-Dispositionwithout full cross-platform normalization, allowing traversal-like path components to be preserved in some cases.This update hardens filename extraction so header-derived values cannot escape the target directory.
Scope
src/fsutil/operations.pyinsidedownload_file:/os.path.basename(...)tests/test_operations.pyforContent-Disposition: filename="..\\..\\evil.txt".Behavior change
/) and Windows (\) separators before path join.dirpath.Patch
Related issue
GHSA-4c6f-3rvc-56cx
Checklist before requesting a review