Skip to content

Commit 2f6b9e6

Browse files
committed
Fix #81742: open_basedir bypass in SQLite3 by using file URI
A previous fix[1] was not sufficient to catch all potential file URIs, because the patch did not cater to URL encoding. Properly parsing and decoding the URI may yield a different result than the handling of SQLite3, so we play it safe, and reject any file URIs if open_basedir is configured. [1] <https://bugs.php.net/bug.php?id=77967> Closes GH-10018.
1 parent b6b4a62 commit 2f6b9e6

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
@@ -57,6 +57,9 @@ PHP NEWS
5757
. Fixed GH-10011 (Trampoline autoloader will get reregistered and cannot be
5858
unregistered). (Girgias)
5959

60+
- SQLite3:
61+
. Fixed bug #81742 (open_basedir bypass in SQLite3 by using file URI). (cmb)
62+
6063
24 Nov 2022, PHP 8.1.13
6164

6265
- CLI:

ext/sqlite3/sqlite3.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,14 +2040,8 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
20402040
if (memcmp(arg1, ":memory:", sizeof(":memory:")) && *arg1) {
20412041
if (strncmp(arg1, "file:", 5) == 0) {
20422042
/* starts with "file:" */
2043-
if (!arg1[5]) {
2044-
return SQLITE_DENY;
2045-
}
2046-
if (php_check_open_basedir(arg1 + 5)) {
2047-
return SQLITE_DENY;
2048-
}
2049-
}
2050-
if (php_check_open_basedir(arg1)) {
2043+
return SQLITE_DENY;
2044+
} else if (php_check_open_basedir(arg1)) {
20512045
return SQLITE_DENY;
20522046
}
20532047
}

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)