From 2d4b73653b8d0948de5b043aecf24ae4c915f8f4 Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Mon, 7 Oct 2024 23:37:33 +0200 Subject: [PATCH] Refactor generating of private key and random strings Generating of private key is atomic now. More secure random strings on PHP 7+. --- adminer/include/adminer.inc.php | 14 +++++--- adminer/include/auth.inc.php | 10 +++--- adminer/include/design.inc.php | 16 ++++++--- adminer/include/functions.inc.php | 57 ++++++++++++++++++++++--------- editor/include/adminer.inc.php | 5 ++- 5 files changed, 71 insertions(+), 31 deletions(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index b1707089..a03689d7 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -25,12 +25,16 @@ class Adminer { function connectSsl() { } - /** Get key used for permanent login - * @param bool - * @return string cryptic string which gets combined with password or false in case of an error - */ + /** + * Gets a private key used for permanent login. + * + * @param bool $create + * + * @return string|false Cryptic string which gets combined with password or false in case of an error. + * @throws \Random\RandomException + */ function permanentLogin($create = false) { - return password_file($create); + return get_private_key($create); } /** Return key used to group brute force attacks; behind a reverse proxy, you want to return the last part of X-Forwarded-For diff --git a/adminer/include/auth.inc.php b/adminer/include/auth.inc.php index 603bd470..ff17886c 100644 --- a/adminer/include/auth.inc.php +++ b/adminer/include/auth.inc.php @@ -1,4 +1,5 @@ \n"; echo "
"; diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index 09c3a854..60035044 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -142,14 +142,20 @@ function csp() { ); } -/** Get a CSP nonce -* @return string Base64 value -*/ -function get_nonce() { +/** + * Gets a CSP nonce. + * + * @return string Base64 value. + * @throws \Random\RandomException + */ +function get_nonce() +{ static $nonce; + if (!$nonce) { - $nonce = base64_encode(rand_string()); + $nonce = base64_encode(get_random_string(true)); } + return $nonce; } diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 67e5e583..44ab7e0b 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -1,4 +1,5 @@