Skip to content

Commit a5601b2

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #76359: open_basedir bypass through adding ".."
2 parents 0fb3714 + ee9e075 commit a5601b2

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Fixed bug #81076 (incorrect debug info on Closures with implicit binds).
77
(krakjoe)
88
. Fixed bug #81068 (Double free in realpath_cache_clean()). (Dimitry Andric)
9+
. Fixed bug #76359 (open_basedir bypass through adding ".."). (cmb)
910

1011
- Opcache:
1112
. Fixed bug #80968 (JIT segfault with return from required file). (Dmitry)

main/fopen_wrappers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
101101
*end = '\0';
102102
end++;
103103
}
104+
if (ptr[0] == '.' && ptr[1] == '.' && (ptr[2] == '\0' || IS_SLASH(ptr[2]))) {
105+
/* Don't allow paths with a leading .. path component to be set at runtime */
106+
efree(pathbuf);
107+
return FAILURE;
108+
}
104109
if (php_check_open_basedir_ex(ptr, 0) != 0) {
105110
/* At least one portion of this open_basedir is less restrictive than the prior one, FAIL */
106111
efree(pathbuf);

tests/security/bug76359.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #76359 (open_basedir bypass through adding "..")
3+
--FILE--
4+
<?php
5+
ini_set('open_basedir', __DIR__);
6+
mkdir(__DIR__ . "/bug76359");
7+
chdir(__DIR__ . "/bug76359");
8+
var_dump(ini_set('open_basedir', ini_get('open_basedir') . PATH_SEPARATOR . ".."));
9+
chdir("..");
10+
chdir("..");
11+
?>
12+
--EXPECTF--
13+
bool(false)
14+
15+
Warning: chdir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (%s) in %s on line %d
16+
--CLEAN--
17+
<?php
18+
@rmdir(__DIR__ . "/bug76359");
19+
?>

0 commit comments

Comments
 (0)