From 6d3962574c6217f7be3c6f9cfcc7552db282bb32 Mon Sep 17 00:00:00 2001 From: lucanlee Date: Sun, 9 Aug 2026 00:34:54 +0800 Subject: [PATCH] =?UTF-8?q?perf/security:=20V0.9.5-0.9.6=20db=5Fpending=5F?= =?UTF-8?q?upgrades=20=E7=BC=93=E5=AD=98=20+=20config=20=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E5=A4=96=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - V0.9.5 (P3): db_pending_upgrades() 加 static 请求内缓存,同请求只算一次 - V0.9.6 (安全): config.php 移除明文密码,改从 gitignored 的 config.secret.php 或 环境变量读取;新增 config.secret.php.example 模板;.gitignore 忽略 config/config.secret.php (修复 Webhook reset 反复覆盖明文凭据的隐患;服务器部署前需自建 config.secret.php) --- .gitignore | 1 + app/Core/Helper.php | 11 ++++++++--- config/config.php | 24 ++++++++++++++++++++---- config/config.secret.php.example | 9 +++++++++ 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 config/config.secret.php.example diff --git a/.gitignore b/.gitignore index e04554c..c9a07c7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ storage/cache/ storage/data/ storage/logs/ storage/uploads/ +config/config.secret.php *.zip _dbg_login.html start_local.sh diff --git a/app/Core/Helper.php b/app/Core/Helper.php index e6ec1ff..4d55496 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -544,12 +544,15 @@ if (!function_exists('site_url')) { */ function db_pending_upgrades(): int { + // V0.9.5:请求内缓存(一次请求内多次调用只算一次),避免每后台页重复 glob+md5_file+SELECT + static $cache = null; + if ($cache !== null) return $cache; try { - if (\Core\Db::driver() !== 'mysql') return 0; + if (\Core\Db::driver() !== 'mysql') { $cache = 0; return 0; } $dir = db_upgrade_dir(); - if (!is_dir($dir)) return 0; + if (!is_dir($dir)) { $cache = 0; return 0; } $files = glob($dir . '/*.sql') ?: []; - if (!$files) return 0; + if (!$files) { $cache = 0; return 0; } \Core\Installer::ensureUpgradeLog(); $applied = \Core\Db::query("SELECT file, hash FROM db_upgrades")->fetchAll(\PDO::FETCH_KEY_PAIR); $n = 0; @@ -560,8 +563,10 @@ if (!function_exists('site_url')) { $n++; } } + $cache = $n; return $n; } catch (\Throwable $e) { + $cache = 0; return 0; } } diff --git a/config/config.php b/config/config.php index 150a346..7dcce26 100644 --- a/config/config.php +++ b/config/config.php @@ -1,8 +1,24 @@ '', + 'admin_pass' => '', +], $secret); + return [ 'app' => [ 'name' => '酷冰甲 · 降温服', @@ -17,7 +33,7 @@ return [ 'port' => 3306, 'dbname' => 'coolcoth_comf', 'user' => 'coolcoth_comf', - 'pass' => 'QDBKzY817hDhTiKk', + 'pass' => $secret['db_pass'] ?: (getenv('COOLCOTH_DB_PASS') ?: ''), 'charset' => 'utf8mb4', ], 'file' => [ @@ -27,7 +43,7 @@ return [ // 后台登录账号(文件模式 / 首次安装) 'admin' => [ 'username' => 'admin', - 'password' => 'admin888', + 'password' => $secret['admin_pass'] ?: (getenv('COOLCOTH_ADMIN_PASS') ?: ''), // 本地规则红线:生产环境(mysql 模式)必须关闭配置文件兜底账号,禁用默认密码后门。 // 仅本地演示(file 模式)可临时置 true。远端已实测默认密码可登录,已置 false 封堵。 'allow_config_fallback' => false, diff --git a/config/config.secret.php.example b/config/config.secret.php.example new file mode 100644 index 0000000..71165d7 --- /dev/null +++ b/config/config.secret.php.example @@ -0,0 +1,9 @@ + '在此填入数据库密码', + 'admin_pass' => '在此填入后台密码(务必改为强口令,不要用 admin888)', +];