|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-09-24 11:59 UTC] research at g0blin dot co dot uk
Description:
------------
It appears that when a user sets the value of the cURL option CURLOPT_URL, and uses the 'file://' schema, NULL bytes are not correctly stripped (as they are for http requests, for example). If user input is accepted as the CURLOPT_URL option, with the code expecting to add an extension on the end of the URL (i.e. .json) in order to force a download of a specific file type, this can be bypassed by supplying a NULL byte.
Also, if within the code, the user input is being checked for the schema by use of a strpos, this can also be subverted by use of a NULL byte.
This can result in disclosure of local files.
If this is accepted as a bug, I can request a CVE-ID to be put against this report, or you can provide me with a CVE-ID (once one has been obtained), for my records.
Test script:
---------------
<?php
$url = "file:///etc/passwd%00http://google.com";
if (strpos($url,"http://")!==FALSE) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);
} else { echo "Error: provide a URL that uses the HTTP schema!"; }
Expected result:
----------------
The result expected would of been an error, stating an the provided path could not be found.
Actual result:
--------------
The actual result was the output of the file '/etc/passwd'.
Patchesfix-url-5.4 (last revision 2014-09-29 01:07 UTC by stas@php.net)fix-options-5.5 (last revision 2014-09-29 01:01 UTC by stas@php.net) fix-5.5 (last revision 2014-09-29 00:54 UTC by stas@php.net) bug68089.diff (last revision 2014-09-25 10:40 UTC by johannes@php.net) Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
trivial patch: diff --git a/ext/curl/interface.c b/ext/curl/interface.c index d7cacf5..094c8ae 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -170,6 +170,11 @@ static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, { CURLcode error = CURLE_OK; + if (strlen(str) != len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Curl option %d contains invalid characters (\\0) ignoring");; + return FAILURE; + } + #if LIBCURL_VERSION_NUM >= 0x071100 if (make_copy) { #endif