Skip to content

Commit 8301803

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix #81742: open_basedir bypass in SQLite3 by using file URI
2 parents 0ac9e8e + 2f6b9e6 commit 8301803

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ PHP NEWS
5252
. Fixed GH-10011 (Trampoline autoloader will get reregistered and cannot be
5353
unregistered). (Girgias)
5454

55+
- SQLite3:
56+
. Fixed bug #81742 (open_basedir bypass in SQLite3 by using file URI). (cmb)
57+
5558
08 Dec 2022, PHP 8.2.0
5659

5760
- CLI:

ext/sqlite3/sqlite3.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,14 +2073,8 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
20732073
if (memcmp(arg1, ":memory:", sizeof(":memory:")) && *arg1) {
20742074
if (strncmp(arg1, "file:", 5) == 0) {
20752075
/* starts with "file:" */
2076-
if (!arg1[5]) {
2077-
return SQLITE_DENY;
2078-
}
2079-
if (php_check_open_basedir(arg1 + 5)) {
2080-
return SQLITE_DENY;
2081-
}
2082-
}
2083-
if (php_check_open_basedir(arg1)) {
2076+
return SQLITE_DENY;
2077+
} else if (php_check_open_basedir(arg1)) {
20842078
return SQLITE_DENY;
20852079
}
20862080
}

ext/sqlite3/tests/bug81742.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #81742 (open_basedir bypass in SQLite3 by using url encoded file)
3+
--EXTENSIONS--
4+
sqlite3
5+
--INI--
6+
open_basedir=.
7+
--FILE--
8+
<?php
9+
$db = new SQLite3(':memory:');
10+
$db->query("ATTACH 'file:..%2ffoo.php' as db2;");
11+
?>
12+
--EXPECTF--
13+
Warning: SQLite3::query(): not authorized in %s on line %d

0 commit comments

Comments
 (0)