Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit b806eb5

Browse files
committed
PHP-1431: Fix database name validation to include '$external', to allow execution of user admin commands
1 parent 722aa73 commit b806eb5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

db.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ int php_mongo_db_is_valid_dbname(char *dbname, int dbname_len TSRMLS_DC)
129129
return 0;
130130
}
131131

132+
/* We allow the special case "$external" as database name (PHP-1431) */
133+
if (strcmp("$external", dbname) == 0) {
134+
return 1;
135+
}
136+
132137
if (
133138
memchr(dbname, ' ', dbname_len) != 0 || memchr(dbname, '.', dbname_len) != 0 || memchr(dbname, '\\', dbname_len) != 0 ||
134139
memchr(dbname, '/', dbname_len) != 0 || memchr(dbname, '$', dbname_len) != 0

tests/generic/database-valid-name.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ Database: valid name checks
66
<?php
77
require_once "tests/utils/server.inc";
88
$a = mongo_standalone();
9-
$names = array("\\", "\$", "/", "foo.bar");
9+
$names = array("\\", "\$", "/", "foo.bar", '$external', 'run$fores');
1010
foreach ($names as $name) {
1111
try {
1212
$d = new MongoDB($a, $name);
13+
echo $name, ": OK\n";
1314
} catch (Exception $e) {
1415
echo $name, ": ", $e->getMessage(), "\n";
1516
}
@@ -20,3 +21,5 @@ foreach ($names as $name) {
2021
$: Database name contains invalid characters: $
2122
/: Database name contains invalid characters: /
2223
foo.bar: Database name contains invalid characters: foo.bar
24+
$external: OK
25+
run$fores: Database name contains invalid characters: run$fores

0 commit comments

Comments
 (0)