Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-23 20:32:30 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-26 23:34:18 +0300
commit5d9142674d09379a9e4394779c1e624dd2d6ece5 (patch)
tree682076d5816f9c1c2948c03662f19893f029467c /libraries
parent69bc86677345a875c442c0a40d2836369bc7afbb (diff)
Allow longer cookie encryption keys to be used
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r--libraries/classes/Controllers/HomeController.php14
-rw-r--r--libraries/classes/Plugins/Auth/AuthenticationCookie.php13
2 files changed, 21 insertions, 6 deletions
diff --git a/libraries/classes/Controllers/HomeController.php b/libraries/classes/Controllers/HomeController.php
index 998cc3b4ce..39235fdc06 100644
--- a/libraries/classes/Controllers/HomeController.php
+++ b/libraries/classes/Controllers/HomeController.php
@@ -311,19 +311,23 @@ class HomeController extends AbstractController
* Check if user does not have defined blowfish secret and it is being used.
*/
if (! empty($_SESSION['encryption_key'])) {
- if (empty($cfg['blowfish_secret'])) {
+ $encryptionKeyLength = mb_strlen($cfg['blowfish_secret'], '8bit');
+ if ($encryptionKeyLength < SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
$this->errors[] = [
'message' => __(
- 'The configuration file now needs a secret passphrase (blowfish_secret).'
+ 'The configuration file needs a valid key for cookie encryption.'
+ . ' A temporary key was automatically generated for you.'
+ . ' Please refer to the [doc@cfg_blowfish_secret]documentation[/doc].'
),
'severity' => 'warning',
];
- } elseif (mb_strlen($cfg['blowfish_secret'], '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
+ } elseif ($encryptionKeyLength > SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
$this->errors[] = [
'message' => sprintf(
__(
- 'The secret passphrase in configuration (blowfish_secret) is not the correct length.'
- . ' It should be %d bytes long.'
+ 'The cookie encryption key in the configuration file is longer than necessary.'
+ . ' It should only be %d bytes long.'
+ . ' Please refer to the [doc@cfg_blowfish_secret]documentation[/doc].'
),
SODIUM_CRYPTO_SECRETBOX_KEYBYTES
),
diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php
index 33faf56b34..e083ddf19a 100644
--- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php
+++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php
@@ -597,11 +597,21 @@ class AuthenticationCookie extends AuthenticationPlugin
*/
private function getEncryptionSecret(): string
{
+ /** @var mixed $key */
$key = $GLOBALS['cfg']['blowfish_secret'] ?? null;
- if (is_string($key) && mb_strlen($key, '8bit') === SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
+ if (! is_string($key)) {
+ return $this->getSessionEncryptionSecret();
+ }
+
+ $length = mb_strlen($key, '8bit');
+ if ($length === SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
return $key;
}
+ if ($length > SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
+ return mb_substr($key, 0, SODIUM_CRYPTO_SECRETBOX_KEYBYTES, '8bit');
+ }
+
return $this->getSessionEncryptionSecret();
}
@@ -610,6 +620,7 @@ class AuthenticationCookie extends AuthenticationPlugin
*/
private function getSessionEncryptionSecret(): string
{
+ /** @var mixed $key */
$key = $_SESSION['encryption_key'] ?? null;
if (is_string($key) && mb_strlen($key, '8bit') === SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
return $key;