From 37dd7d2173cacfb08980d216b25db8b58735542a Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sun, 17 May 2026 18:20:05 +0800 Subject: [PATCH] fix(webui): rotate stale bootstrap password and highlight credentials log If the operator never completed the forced-change flow, the plaintext bootstrap password was unrecoverable on the next start (only the hash remained on disk, and the prior log line was likely gone). Now we detect a persisted state with mustChangePassword=true at load time and generate a fresh CSPRNG password so the operator can actually log in. The initial-credentials log block is also wrapped with separators and a bilingual notice so it stands out at boot. The 'initial credentials: user=admin password=%s' line is preserved verbatim because third-party launchers parse it. --- packages/core/src/webui/auth.ts | 11 +++++++++++ packages/core/src/webui/server.ts | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/core/src/webui/auth.ts b/packages/core/src/webui/auth.ts index 79226178..c8f6732e 100644 --- a/packages/core/src/webui/auth.ts +++ b/packages/core/src/webui/auth.ts @@ -151,6 +151,17 @@ export class WebuiAuth { const raw = fs.readFileSync(WEBUI_CONFIG_PATH, 'utf8'); const parsed = JSON.parse(raw) as unknown; if (isValidState(parsed)) { + if (parsed.mustChangePassword) { + // Previous start generated a bootstrap password but the operator + // never completed the forced-change flow. The plaintext is gone + // (only the hash is on disk, and the log line from last run may + // be lost), so rotate to a fresh CSPRNG password they can see. + const initialPassword = randomBytes(8).toString('hex'); + const state = generateInitialState(initialPassword); + atomicWrite(state); + log.warn('previous bootstrap password was never rotated; regenerated a new one'); + return new WebuiAuth(state, initialPassword, false); + } return new WebuiAuth(parsed, null, false); } log.error('webui.json schema invalid; backing up and regenerating credentials'); diff --git a/packages/core/src/webui/server.ts b/packages/core/src/webui/server.ts index c71a5d11..0c704a19 100644 --- a/packages/core/src/webui/server.ts +++ b/packages/core/src/webui/server.ts @@ -98,8 +98,14 @@ export async function initWebUI( log.warn('dev mode enabled: password=%s', WebuiAuth.devPassword); log.warn('dev mode skips config/webui.json and password rotation'); } else if (initialPassword) { + log.info('════════════════════════════════════════════════════════════════'); + log.info(' ★ WebUI 初始登录凭据 / Initial WebUI Credentials ★'); + log.info(' 请立即登录并修改密码 —— 关闭程序后此密码无法找回。'); + log.info(' 若跳过初始改密,下次启动将自动生成新的随机密码。'); + log.info(' Log in and change the password now; it will not be shown again.'); + log.info('────────────────────────────────────────────────────────────────'); log.info('initial credentials: user=admin password=%s', initialPassword); - log.info('password change required after first login'); + log.info('════════════════════════════════════════════════════════════════'); } else if (auth.mustChangePassword()) { log.warn('password change is still required'); }