Merge pull request #17374 from mauriciofauth/issue-17368

Clear config storage params from session after failed access
This commit is contained in:
Maurício Meneghini Fauth 2022-02-15 17:26:39 -03:00 committed by GitHub
commit b277e46fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\Config\Forms\User\UserFormList;
use function array_flip;
use function array_merge;
use function basename;
use function htmlspecialchars;
use function http_build_query;
use function is_array;
use function json_decode;
@ -166,12 +167,17 @@ class UserPreferences
}
if (! $dbi->tryQuery($query, DatabaseInterface::CONNECT_CONTROL)) {
$message = Message::error(__('Could not save configuration'));
$message->addMessage(
Message::rawError(
$dbi->getError(DatabaseInterface::CONNECT_CONTROL)
),
'<br><br>'
);
$message->addMessage(Message::error($dbi->getError(DatabaseInterface::CONNECT_CONTROL)), '<br><br>');
if (! $this->hasAccessToDatabase($cfgRelation['db'])) {
/**
* When phpMyAdmin cached the configuration storage parameters, it checked if the database can be
* accessed, so if it could not be accessed anymore, then the cache must be cleared as it's out of date.
*/
$_SESSION['relation'][$GLOBALS['server']] = [];
$message->addMessage(Message::error(htmlspecialchars(
__('The phpMyAdmin configuration storage database could not be accessed.')
)), '<br><br>');
}
return $message;
}
@ -179,6 +185,17 @@ class UserPreferences
return true;
}
private function hasAccessToDatabase(string $database): bool
{
$escapedDb = $GLOBALS['dbi']->escapeString($database);
$query = 'SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = \'' . $escapedDb . '\';';
if ($GLOBALS['cfg']['Server']['DisableIS']) {
$query = 'SHOW DATABASES LIKE \'' . Util::escapeMysqlWildcards($escapedDb) . '\';';
}
return (bool) $GLOBALS['dbi']->fetchSingleRow($query, 'ASSOC', DatabaseInterface::CONNECT_CONTROL);
}
/**
* Returns a user preferences array filtered by $cfg['UserprefsDisallow']
* (exclude list) and keys from user preferences form (allow list)

View File

@ -140,6 +140,7 @@ class UserPreferencesTest extends AbstractNetworkTestCase
*/
public function testSave(): void
{
$GLOBALS['cfg']['Server']['DisableIS'] = true;
$GLOBALS['server'] = 2;
$_SESSION['relation'][2]['PMA_VERSION'] = PMA_VERSION;
$_SESSION['relation'][2]['userconfigwork'] = null;
@ -251,7 +252,8 @@ class UserPreferencesTest extends AbstractNetworkTestCase
$this->assertInstanceOf(Message::class, $result);
$this->assertEquals(
'Could not save configuration<br><br>err1',
'Could not save configuration<br><br>err1'
. '<br><br>The phpMyAdmin configuration storage database could not be accessed.',
$result->getMessage()
);
}