php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73922 Missing null byte checks for paths in curlfile_ctor()
Submitted: 2017-01-12 18:16 UTC Modified: 2017-01-16 07:03 UTC
From: max at cert dot cx Assigned: stas (profile)
Status: Closed Package: cURL related
PHP Version: 5.6.29 OS: BSD
Private report: No CVE-ID: None
 [2017-01-12 18:16 UTC] max at cert dot cx
Description:
------------
Missing null byte checks for paths in curlfile_ctor()
curl_file_create() doesn’t ensure that pathnames lack NULL byte, which might allow attacker to manipulate the upload file name and path.
Affected code:
==================================
static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
{
    char *fname = NULL, *mime = NULL, *postname = NULL;
    size_t fname_len, mime_len, postname_len;
    zval *cf = return_value;
 
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) { ⇐====
        return;
    }
==================================


Affected function:
==================================
CURLFile curl_file_create ( string $filename [, string $mimetype [, string $postname ]] )
==================================

type of parameters filename to change. From a security perspective, You may consider changing the type of parameter postname

Best,
Maksymilian Arciemowicz


Test script:
---------------
<?php

$request = curl_init('http://127.0.0.1/print.php');

curl_setopt($request, CURLOPT_POST, true);

$args['file'] = curl_file_create("./test.test\0.file.to.send.png", "image/png", "test.test\0.file.to.send.png");
curl_setopt($request, CURLOPT_POSTFIELDS, $args);

echo curl_exec($request);
curl_close($request);



Expected result:
----------------
warning

Actual result:
--------------
uploaded test.test and name

Array
(
    [file] => Array
        (
            [name] => test.test

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-16 01:35 UTC] stas@php.net
-Status: Open +Status: Closed -Type: Security +Type: Bug -PHP Version: 7.1.0 +PHP Version: 5.6.29 -Assigned To: +Assigned To: stas
 [2017-01-16 01:35 UTC] stas@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2017-01-16 07:03 UTC] max at cert dot cx
in your opinion it is a security flaw? If not, what is the difference between CVE-2015-4598, CVE-2015-3412, CVE-2015-3411 and this vulnerability?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 22:01:28 2024 UTC