php / php/php-src

filenames in multipart/form-data are not percent decoded

Đang mở
#8,206 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Category: Engine Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

For the following form:

<pre>
<?php
var_dump(PHP_VERSION);
var_dump($_FILES);
?>
</pre>

<form method="post" action="test.php" enctype="multipart/form-data">
<input type="file" name="some_file">

<button type="submit">Submit</button>
</form>

Uploading a file called ".txt in Firefox and Chrome

Resulted in this output:

string(5) "8.1.3"
array(1) {
  ["some_file"]=>
  array(6) {
    ["name"]=>
    string(7) "%22.txt"
    ["full_path"]=>
    string(7) "%22.txt"
    ["type"]=>
    string(10) "text/plain"
    ["tmp_name"]=>
    string(14) "/tmp/phpWl5h5S"
    ["error"]=>
    int(0)
    ["size"]=>
    int(0)
  }
}

But I expected this output instead:

string(5) "8.1.3"
array(1) {
  ["some_file"]=>
  array(6) {
    ["name"]=>
    string(5) "".txt"
    ["full_path"]=>
    string(5) "".txt"
    ["type"]=>
    string(10) "text/plain"
    ["tmp_name"]=>
    string(14) "/tmp/phpWl5h5S"
    ["error"]=>
    int(0)
    ["size"]=>
    int(0)
  }
}

Because I wasn't sure about the correct behavior myself I've checked with #curl on irc.libera.chat. In the replies I got the following references:

RFC 7578#2 specifies percent-encoding for use in HTTP

So nowadays special characters, specifically the double quote (") are percent-encoded instead of backslash-encoded and PHP should properly decode those, like it already does for backslash encoding.

PHP Version

8.1.3

Operating System

Docker on Ubuntu 20.04

Hướng dẫn đóng góp

Mở 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.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện quá trình tải lên multipart/form-data được mô tả với PHP 8.1.3, sử dụng tên tệp có chứa dấu ngoặc kép, rồi kiểm tra các giá trị name và full_path kết quả trong $_FILES. So sánh cách xử lý mã hóa phần trăm với hành vi hiện có được mã hóa bằng dấu gạch chéo ngược; được xem là hoàn tất khi cả hai trường đều chứa tên tệp đã giải mã.

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

Đánh giá

Công nghệ
c, php
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

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.