php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79286 Update basename comment for $_FILES["file"]["name"]
Submitted: 2020-02-19 15:45 UTC Modified: 2020-02-19 16:48 UTC
From: craig at craigfrancis dot co dot uk Assigned:
Status: Closed Package: *General Issues
PHP Version: master-Git-2020-02-19 (Git) OS: N/A
Private report: No CVE-ID: None
 [2020-02-19 15:45 UTC] craig at craigfrancis dot co dot uk
Description:
------------
In the PHP source code, the user supplied filename passes though _basename().

    https://github.com/php/php-src/blob/0b4778c377a5753a0deb9cfc697d4f62acf93a29/main/rfc1867.c#L1139

The comment mentions this is due to Internet Explorer providing the "full path of the file on the user's filesystem".

While that might be valid, it's much more important that the comment focuses on the security issue this avoids.

For example, you will find examples of PHP code that does something like this:

    $dest = __DIR__ . '/../../uploads/' . $_FILES["image"]['name']);

    move_uploaded_file($_FILES['image']['tmp_name'], $dest);

Which would cause a problem if an "Evil Hacker" was to set the filename to a relative path, e.g.

    curl -F 'file=@example.php;filename=../../../example.php' https://example.com/upload/


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-19 16:48 UTC] craig at craigfrancis dot co dot uk
-Status: Open +Status: Closed
 [2020-02-19 16:48 UTC] craig at craigfrancis dot co dot uk
Has just been fixed:

https://github.com/php/php-src/commit/fb57ae9084a98ac5f06cd7b2d10205489b537e20
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 11:01:32 2024 UTC