Merge pull request #17559 from MauricioFauth/db-table-lowercase-privs

Fix checking db and table privileges when case is sensitive
This commit is contained in:
Maurício Meneghini Fauth 2022-05-26 22:31:26 -03:00 committed by GitHub
commit 4f9009c114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 41 deletions

View File

@ -13,6 +13,8 @@ use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use function mb_strtolower;
/**
* Controller for database privileges
*/
@ -37,7 +39,8 @@ class PrivilegesController extends AbstractController
}
/**
* @param array $params Request parameters
* @param string[] $params Request parameters
* @psalm-param array{checkprivsdb: string} $params
*/
public function __invoke(array $params): string
{
@ -45,14 +48,19 @@ class PrivilegesController extends AbstractController
$scriptName = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$db = $params['checkprivsdb'];
if ($this->dbi->getLowerCaseNames() === '1') {
$db = mb_strtolower($params['checkprivsdb']);
}
$privileges = [];
if ($this->dbi->isSuperUser()) {
$privileges = $this->privileges->getAllPrivileges($params['checkprivsdb']);
$privileges = $this->privileges->getAllPrivileges($db);
}
return $this->template->render('database/privileges/index', [
'is_superuser' => $this->dbi->isSuperUser(),
'db' => $params['checkprivsdb'],
'db' => $db,
'database_url' => $scriptName,
'text_dir' => $text_dir,
'is_createuser' => $this->dbi->isCreateUser(),

View File

@ -29,7 +29,6 @@ use function is_string;
use function ob_get_clean;
use function ob_start;
use function str_replace;
use function strtolower;
use function urlencode;
/**
@ -395,10 +394,10 @@ class PrivilegesController extends AbstractController
$this->response->addHTML(
$serverPrivileges->getHtmlForAddUser(Util::escapeMysqlWildcards(is_string($dbname) ? $dbname : ''))
);
} elseif (isset($_GET['checkprivsdb'])) {
if (isset($_GET['checkprivstable'])) {
} elseif (isset($_GET['checkprivsdb']) && is_string($_GET['checkprivsdb'])) {
if (isset($_GET['checkprivstable']) && is_string($_GET['checkprivstable'])) {
$this->response->addHTML($tableController([
'checkprivsdb' => strtolower($_GET['checkprivsdb']),
'checkprivsdb' => $_GET['checkprivsdb'],
'checkprivstable' => $_GET['checkprivstable'],
]));
$this->render('export_modal');
@ -408,7 +407,7 @@ class PrivilegesController extends AbstractController
return;
} else {
$this->response->addHTML($databaseController(['checkprivsdb' => strtolower($_GET['checkprivsdb'])]));
$this->response->addHTML($databaseController(['checkprivsdb' => $_GET['checkprivsdb']]));
$this->render('export_modal');
}
} else {

View File

@ -13,6 +13,8 @@ use PhpMyAdmin\Server\Privileges;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use function mb_strtolower;
/**
* Controller for table privileges
*/
@ -38,7 +40,8 @@ class PrivilegesController extends AbstractController
}
/**
* @param array $params Request parameters
* @param string[] $params Request parameters
* @psalm-param array{checkprivsdb: string, checkprivstable: string} $params
*/
public function __invoke(array $params): string
{
@ -46,14 +49,21 @@ class PrivilegesController extends AbstractController
$scriptName = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$db = $params['checkprivsdb'];
$table = $params['checkprivstable'];
if ($this->dbi->getLowerCaseNames() === '1') {
$db = mb_strtolower($params['checkprivsdb']);
$table = mb_strtolower($params['checkprivstable']);
}
$privileges = [];
if ($this->dbi->isSuperUser()) {
$privileges = $this->privileges->getAllPrivileges($params['checkprivsdb'], $params['checkprivstable']);
$privileges = $this->privileges->getAllPrivileges($db, $table);
}
return $this->template->render('table/privileges/index', [
'db' => $params['checkprivsdb'],
'table' => $params['checkprivstable'],
'db' => $db,
'table' => $table,
'is_superuser' => $this->dbi->isSuperUser(),
'table_url' => $scriptName,
'text_dir' => $text_dir,

View File

@ -1055,11 +1055,6 @@ parameters:
count: 6
path: libraries/classes/Controllers/Database/OperationsController.php
-
message: "#^Method PhpMyAdmin\\\\Controllers\\\\Database\\\\PrivilegesController\\:\\:__invoke\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Controllers/Database/PrivilegesController.php
-
message: "#^Cannot access offset non\\-empty\\-string on mixed\\.$#"
count: 1
@ -1520,11 +1515,6 @@ parameters:
count: 1
path: libraries/classes/Controllers/Table/OperationsController.php
-
message: "#^Method PhpMyAdmin\\\\Controllers\\\\Table\\\\PrivilegesController\\:\\:__invoke\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Controllers/Table/PrivilegesController.php
-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
@ -1840,11 +1830,6 @@ parameters:
count: 1
path: libraries/classes/Core.php
-
message: "#^Offset 'pass'\\|'port'\\|'user' does not exist on array\\{scheme\\?\\: string, host\\: non\\-empty\\-string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
count: 1
path: libraries/classes/Core.php
-
message: "#^Method PhpMyAdmin\\\\CreateAddField\\:\\:buildColumnCreationStatement\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1

View File

@ -1313,11 +1313,6 @@
<code>$_error</code>
</RedundantCondition>
</file>
<file src="libraries/classes/Controllers/Database/PrivilegesController.php">
<MixedArgument occurrences="1">
<code>$params['checkprivsdb']</code>
</MixedArgument>
</file>
<file src="libraries/classes/Controllers/Database/QueryByExampleController.php">
<MixedArgument occurrences="10">
<code>$_POST['db']</code>
@ -2490,9 +2485,7 @@
</MixedMethodCall>
</file>
<file src="libraries/classes/Controllers/Server/PrivilegesController.php">
<MixedArgument occurrences="18">
<code>$_GET['checkprivsdb']</code>
<code>$_GET['checkprivsdb']</code>
<MixedArgument occurrences="16">
<code>$_POST['userGroup']</code>
<code>$db</code>
<code>$db</code>
@ -3287,12 +3280,6 @@
<code>$query</code>
</MixedArgument>
</file>
<file src="libraries/classes/Controllers/Table/PrivilegesController.php">
<MixedArgument occurrences="2">
<code>$params['checkprivsdb']</code>
<code>$params['checkprivstable']</code>
</MixedArgument>
</file>
<file src="libraries/classes/Controllers/Table/RecentFavoriteController.php">
<MixedArgument occurrences="4">
<code>$_REQUEST['db']</code>