Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

download_file ignores the RFC 6266 filename* Content-Disposition parameter

未关闭 适合新手
#208 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@rahul05ranjan 已经在做这个了。

开始于 2026年10月28日。

  • #209 来自 @rahul05ranjan —— 未关闭
  • #211 来自 @Lushiyao5 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从 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

  1. Parse filename*=charset'language'percent-encoded-value (parameter name case-insensitive).
  2. Percent-decode the value using the declared charset.
  3. Give it precedence over the basic filename parameter.
  4. 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.
  5. On an unknown charset or a malformed extended value, fall back to the basic filename parameter / URL / random name as before.

Happy to send a PR.

主要语言
Python
星标
268
派生
22
平均合并
4 天 11 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fabiocaccamo/python-fsutil 的其他 Issue

查看 fabiocaccamo/python-fsutil 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。