Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

download_file ignores the RFC 6266 filename* Content-Disposition parameter

Đang mở Phù hợp với người mới
#208 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

@rahul05ranjan đang làm issue này rồi.

Từ ngày 28/10/2026.

  • #209 của @rahul05ranjan — đang mở
  • #211 của @Lushiyao5 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với fsutil.download_file() và phần phân tích, làm sạch tên tệp hiện có được mô tả trong issue; sau đó tìm các bài kiểm thử và thêm một trường hợp sử dụng header Content-Disposition được cung cấp. Xác minh rằng filename* sau khi giải mã được ưu tiên và được làm sạch, còn các giá trị không hợp lệ hoặc bộ ký tự không xác định sẽ dùng phương án dự phòng như đã nêu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
268
Fork
22
Merge trung bình
4 ngày 11 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fabiocaccamo/python-fsutil

Tất cả issue của fabiocaccamo/python-fsutil

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.