fix: 管理员初始化令牌输入框改为按需显示

注册模态框里固定显示「管理员初始化令牌(仅首次部署,可选)」输入框,
每个来注册的普通用户都会看到它,既令人困惑,也等于对外宣告存在一个
提权入口。该字段由 924f9ff 引入,与后端的引导令牌机制配套。

后端鉴权本身没有问题(令牌随机、check hasAdmin、advisory lock 防并发),
所以本次只调整展示层面,不改动注册与提权逻辑:

- GET /api/settings 新增 bootstrap_required 布尔值,仅在「部署者配置了
  ADMIN_BOOTSTRAP_TOKEN」且「系统尚无管理员」时为 true。只返回布尔值,
  不泄露令牌本身或其长度。
- index.html 中该输入框默认 display:none。
- js/auth.js 打开注册框时查询设置,按 bootstrap_required 决定显隐;
  字段隐藏时按「未提供」处理,避免普通注册传入空串触发 403。

这样三种情形各得其所:
- 普通部署(未配置令牌):任何人都看不到该字段
- 首次部署(已配置令牌、尚无管理员):显示,部署者据此创建管理员
- 初始化完成:自动隐藏

新增 test/bootstrap-ui.test.js 锁住上述约定,覆盖「标记中默认隐藏」
「接口只暴露布尔值」「隐藏时不提交空令牌」「表单对字段缺失做保护」
四项。已实测注入故障可被捕获。

实测五种场景(未配置令牌 / 已配置待初始化 / 初始化后 / 泄露检查 /
普通注册)行为均符合预期。
This commit is contained in:
Furrium Network committed 2026-09-21 20:33:29 +08:00
1 parent f1c9aca4c7
commit c6bf968178
4 files changed
+125 -3

No files matched your search

+1 -1
View File
@@ -362,7 +362,7 @@
<input type="text" id="regUsername" placeholder="用户名" />
<input type="email" id="regEmail" placeholder="邮箱" />
<input type="password" id="regPassword" placeholder="密码(至少6位)" />
<input type="password" id="regBootstrapToken" placeholder="管理员初始化令牌(仅首次部署,可选)" autocomplete="off" />
<input type="password" id="regBootstrapToken" placeholder="管理员初始化令牌" autocomplete="off" style="display:none;" />
<div class="captcha-row">
<span id="regCaptchaQuestion">3 + 5 = ?</span>
<input type="text" id="regCaptchaInput" placeholder="答案" style="width:80px;" />