Skip to content

Commit 59ebbf5

Browse files
LawnGnomeweltling
authored andcommitted
Allow CURLOPT_FOLLOWLOCATION to be used with open_basedir.
Newer versions of libcurl prevent file:// location response headers by default, which means that the open_basedir check is unnecessary — the fact CURLOPT_REDIR_PROTOCOLS can't set CURLPROTO_FILE with open_basedir enabled means that there's no possibility of breaching the open_basedir restriction, and this allows HTTP redirects to be followed automatically. Implements FR #65646 (re-enable CURLOPT_FOLLOWLOCATION with open_basedir or safe_mode).
1 parent 04c823d commit 59ebbf5

6 files changed

+64
-22
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
of E_STRICT (phase 1 of RFC: https://wiki.php.net/rfc/incompat_ctx).
1111
(Gustavo)
1212

13+
- cURL:
14+
. Implemented FR #65646 (re-enable CURLOPT_FOLLOWLOCATION with open_basedir
15+
or safe_mode). (Adam)
16+
1317
- Session:
1418
. Fixed Bug #65315 (session.hash_function silently fallback to default md5)
1519
(Yasuo)

ext/curl/interface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,13 +2504,15 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
25042504

25052505
case CURLOPT_FOLLOWLOCATION:
25062506
convert_to_long_ex(zvalue);
2507+
#if LIBCURL_VERSION_NUM < 0x071304
25072508
if (PG(open_basedir) && *PG(open_basedir)) {
25082509
if (Z_LVAL_PP(zvalue) != 0) {
25092510
php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set");
25102511
RETVAL_FALSE;
25112512
return 1;
25122513
}
25132514
}
2515+
#endif
25142516
error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
25152517
break;
25162518

ext/curl/tests/bug65646.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #65646 (re-enable CURLOPT_FOLLOWLOCATION with open_basedir or safe_mode): open_basedir disabled
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('curl')) exit("skip curl extension not loaded");
6+
if (ini_get('open_basedir')) exit("skip open_basedir is set");
7+
?>
8+
--FILE--
9+
<?php
10+
$ch = curl_init();
11+
var_dump(curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true));
12+
curl_close($ch);
13+
?>
14+
--EXPECT--
15+
bool(true)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #65646 (re-enable CURLOPT_FOLLOWLOCATION with open_basedir or safe_mode): open_basedir enabled; curl >= 7.19.4
3+
--INI--
4+
open_basedir=.
5+
--SKIPIF--
6+
<?php
7+
if (!extension_loaded('curl')) exit("skip curl extension not loaded");
8+
if (version_compare(curl_version()['version'], '7.19.4', '<')) exit("skip curl version is too old");
9+
?>
10+
--FILE--
11+
<?php
12+
$ch = curl_init();
13+
var_dump(curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true));
14+
var_dump(curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_FILE));
15+
var_dump(curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_FILE));
16+
curl_close($ch);
17+
?>
18+
--EXPECTF--
19+
bool(true)
20+
21+
Warning: curl_setopt(): CURLPROTO_FILE cannot be activated when an open_basedir is set in %s on line %d
22+
bool(false)
23+
24+
Warning: curl_setopt(): CURLPROTO_FILE cannot be activated when an open_basedir is set in %s on line %d
25+
bool(false)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #65646 (re-enable CURLOPT_FOLLOWLOCATION with open_basedir or safe_mode): open_basedir enabled; curl < 7.19.4
3+
--INI--
4+
open_basedir=.
5+
--SKIPIF--
6+
<?php
7+
if (!extension_loaded('curl')) exit("skip curl extension not loaded");
8+
if (version_compare(curl_version()['version'], '7.19.4', '>=')) exit("skip curl version is too new");
9+
?>
10+
--FILE--
11+
<?php
12+
$ch = curl_init();
13+
var_dump(curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true));
14+
curl_close($ch);
15+
?>
16+
--EXPECTF--
17+
Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set in %s on line %d
18+
bool(false)

ext/curl/tests/curl_setopt_CURLOPT_FOLLOWLOCATION_open_basedir.phpt

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)