Skip to content

Commit ee9e075

Browse files
committed
Fix #76359: open_basedir bypass through adding ".."
We explicitly forbid adding paths with a leading `..` to `open_basedir` at runtime. Closes GH-7024.
1 parent 99a2085 commit ee9e075

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
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug #81068 (Double free in realpath_cache_clean()). (Dimitry Andric)
7+
. Fixed bug #76359 (open_basedir bypass through adding ".."). (cmb)
78

89
- Standard:
910
. Fixed bug #81048 (phpinfo(INFO_VARIABLES) "Array to string conversion").

main/fopen_wrappers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
110110
*end = '\0';
111111
end++;
112112
}
113+
if (ptr[0] == '.' && ptr[1] == '.' && (ptr[2] == '\0' || IS_SLASH(ptr[2]))) {
114+
/* Don't allow paths with a leading .. path component to be set at runtime */
115+
efree(pathbuf);
116+
return FAILURE;
117+
}
113118
if (php_check_open_basedir_ex(ptr, 0) != 0) {
114119
/* At least one portion of this open_basedir is less restrictive than the prior one, FAIL */
115120
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)