download_file ignores the RFC 6266 filename* Content-Disposition parameter
维护者通常 4 天内回复
评估
调研方向
从 fsutil.download_file() 以及 issue 中描述的现有文件名解析和清理逻辑开始;然后找到它的测试,并添加一个使用所提供的 Content-Disposition header 的用例。验证解码后的 filename* 优先并经过清理,而格式错误的值或未知字符集会按说明回退。
由索引模型根据 Issue 内容生成。
描述
Summary
fsutil.download_file() only extracts the filename from the basic quoted parameter of Content-Disposition:
filename_pattern = r'filename="(.*)"'
However, many servers (S3, GitHub, browsers-side conventions) send the filename through the extended parameter when it contains non-ASCII characters, per RFC 6266 / RFC 5987:
Content-Disposition: attachment; filename="fallback.txt"; filename*=UTF-8''%E2%82%AC%20rates.txt
RFC 6266 says filename* takes precedence over filename. Today download_file() ignores filename* entirely, so such downloads are saved under a URL-derived name (or a random download-<uuid> name), silently dropping the server-provided filename.
Repro
class MockResponse:
headers = {"content-disposition": "attachment; filename=\"fallback.txt\"; filename*=UTF-8''%E2%82%AC%20rates.txt"}
...
path = fsutil.download_file("https://example.com/file.txt", dirpath=tmp)
# expected: "€ rates.txt" (from filename*)
# actual: "file.txt" (derived from the URL)
Expected behavior
- Parse
filename*=charset'language'percent-encoded-value(parameter name case-insensitive). - Percent-decode the value using the declared charset.
- Give it precedence over the basic
filenameparameter. - Keep the existing path-traversal sanitization (
\//normalization +os.path.basename) on the decoded value, since it comes from an untrusted header — the same hardening that #181 added for the basic parameter. - On an unknown charset or a malformed extended value, fall back to the basic
filenameparameter / URL / random name as before.
Happy to send a PR.
- 主要语言
- Python
- 星标
- 268
- 派生
- 22
- 平均合并
- 4 天 11 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fabiocaccamo/python-fsutil 的其他 Issue
-
Atomic append fails to create a missing file可能已有人在做 @harbinresearcher 于 16 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
fabiocaccamo/python-fsutil#201 ·
维护者通常 4 天内回复
-
get_unique_name appends to the previous candidate name when a collision triggers a retry可能已有人在做 @rahul05ranjan 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
fabiocaccamo/python-fsutil#206 ·
维护者通常 4 天内回复
-
Add `toml` files operation support.可能重新可做 @fabiocaccamo 于 1337 天前认领,目前没有进行中的 PR。 未关闭enhancement
fabiocaccamo/python-fsutil#42 · 已指派 1 人 ·
维护者通常 4 天内回复
查看 fabiocaccamo/python-fsutil 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 86/100
-
Validate finite output clamping limits in StepPredictor.prepare_clamping_params to prevent silent NaN/Inf propagation可能已有人在做 @muskan-creates352 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
mllam/neural-lam#848 ·
维护者通常 2 天内回复
-
infra
难度 1/5 1 小时以内 新手友好度 88/100
fab-geocommuns/RNB-coeur#1166 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
deepspeedai/DeepSpeed#8951 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
aws/context-ontology-accelerator#343 ·
维护者通常 1 天内回复