diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index db4be878d8171..27135020fa3e3 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -110,6 +110,11 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir) *end = '\0'; end++; } + if (ptr[0] == '.' && ptr[1] == '.' && (ptr[2] == '\0' || IS_SLASH(ptr[2]))) { + /* Don't allow paths with a leading .. path component to be set at runtime */ + efree(pathbuf); + return FAILURE; + } if (php_check_open_basedir_ex(ptr, 0) != 0) { /* At least one portion of this open_basedir is less restrictive than the prior one, FAIL */ efree(pathbuf); diff --git a/tests/security/bug76359.phpt b/tests/security/bug76359.phpt new file mode 100644 index 0000000000000..df35d67d097da --- /dev/null +++ b/tests/security/bug76359.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #76359 (open_basedir bypass through adding "..") +--FILE-- + +--EXPECTF-- +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (%s) in %s on line %d +--CLEAN-- +