Skip to content

fix(auth): issue tokens from MFA login verification (U-MFA-002) - #9

Merged
wangrh0909 merged 4 commits into
masterfrom
fix/mfa-verify-issue-token
Jul 6, 2026
Merged

wangrh0909 merged 4 commits into
masterfrom
fix/mfa-verify-issue-token

Conversation

@voidvec

@voidvec voidvec commented Jul 3, 2026 •

Copy link
Copy Markdown
Owner

背景

E2E 测试用例 U-MFA-002(MFA 验证成功后登录阻断)失败:MfaController::verifyLogin 在 TOTP 校验通过后只把 mfa_verified 写入服务端 Session,响应体里没有 access_token/refresh_token。前端 SPA 是无状态的(不发 Cookie),拿不到 token,导致二次验证通过后登录卡死。

后续对该改动的安全评审又发现两个 P0 缺陷(跨客户端授权混淆),在本 PR 一并修复。


改动

1. 基础修复:MfaController::verifyLogin 发 token(U-MFA-002)

  • 接收 client_id/redirect_uri(前端 authService.ts 已经在传,未改前端)
  • TOTP 验证通过后,调用 OAuth2Plugin::generateAuthorizationCode 生成授权码,再 exchangeCodeForToken 立即兑换,把 access_token/refresh_token/id_token 直接放进响应体
  • 不引入 Session 跨步骤依赖、不引入 302 跳转、不改前端和其它端点,最小化改动范围
  • 首因子 /oauth2/login 本身不走 PKCE,因此这一步兑换也不做 PKCE 校验,代码注释里说明了原因

2. 安全加固:修复 P0-1 / P0-2(跨客户端授权混淆)

规格文档见 .kiro/specs/mfa-cross-client-auth-fix/(bugfix.md / design.md / tasks.md)

问题:verifyLogin 发 token 时只校验 client_id/redirect_uri 非空,从不校验客户端是否注册、redirect_uri 是否在该客户端白名单内,也不校验它们是否与首因子 /oauth2/login 产生该 mfa_token 时用的是同一对。由于 mfa_token 只是 std::to_string(internalId)、无任何客户端绑定,攻击者拿到一个有效 mfa_token + 正确 TOTP 后,可改用另一个已注册客户端的 client_id/redirect_uri 领到绑定到那个客户端的 token(P0-1);redirect_uri 在这条调用链上根本未过白名单(P0-2)。

修复:

  • V022 迁移:users 表新增可空列 mfa_pending_client_id / mfa_pending_redirect_uri,作为首因子登录会话绑定的载体。
  • SessionController::login:返回 mfa_required 之前,先把本次请求的 client_id/redirect_uri 写入绑定列;UPDATE 失败则 fail-closed(DB_QUERY_ERROR,不发 mfa_token),避免 verifyLogin 拿到陈旧/缺失的绑定。
  • MfaController::verifyLogin:TOTP 校验通过后(顺序保持不变),依次执行 validateClient → validateRedirectUri → 待定绑定相等性比对;三层校验任一失败都以 AUTH_INVALID_CREDENTIALS(401)拒绝,使未注册客户端、非白名单 redirect_uri、不匹配的绑定、错误 TOTP 码在外部不可区分(无客户端注册探针)。完全成功的验证后,best-effort 把绑定清回 NULL(token 已签发无法撤回,故仅尽力清理)。
  • ORM 模型重生成:按项目 orm-gen 惯例,Users.h/Users.cc 重生成以匹配新列(原项目中 Users.cc 缺失,现已补齐)。

明确不在本次范围:mfa_token 的格式/有效期/随机性、verifyLogin 的 scope 校验、MFA 第二步的 PKCE、以及 consumeAuthCode 在通用 authorization_code 流程上的现有 redirect_uri 相等性逻辑。

3. PRD/mfa_auth_code_pkce_design.md

追加评审补充章节,指出原方案(Authorization Code + PKCE + 后端托管登录页)里缺失的会话状态传递清单、CSRF/open-redirect 风险点、与现有 GitHub 登录/consent 流程的兼容性问题、受影响测试清单,并将该架构迁移拆分为独立的后续提案(本 PR 不实施)。


验证

  • OAuth2Test_test.exe:243/243 用例,56035 断言全过(含本次新增 15 个 MFA 跨客户端修复测试,零回归)
  • scripts/backend/test-oauth2-endpoints.ps1:55/55(含 MFA 相关 Test 21-24)
  • scripts/backend/test-admin-endpoints.ps1:0 failed
  • 前端 Playwright e2e(auth.spec.ts):19/19
  • 前端 vitest:15/15
  • 手动跑通真实后端全链路:注册→登录→MFA setup→二次登录触发 mfa_required→提交 TOTP→拿到 access_token→用该 token 访问 /api/me 成功

安全修复专项测试(新增 15 个 DROGON_TEST)

采用 bug-condition 方法论(先在未修复代码上探索反例 → 固化基线 → 实现修复 → 复核):

  • 探索/反例(Property1):未注册客户端 / 非白名单 redirect_uri / 跨客户端混淆 / 空绑定边界。已在未修复代码上坐实 P0-1/P0-2(Case 2/3 确实签发了真实 token)。
  • DB 状态(Property 5/6):login 持久化绑定、覆盖语义、成功后清空、拒绝时保留。
  • 保留基线(Property7):匹配绑定的签发、错误 TOTP、未知 mfa_token、缺字段、非 MFA 登录——修复前后行为一致。
  • 集成测试:端到端 happy-path + 跨客户端拒绝(确认被拒尝试不产生 oauth2_access_tokens 行)。

MfaController::verifyLogin only stored mfa_verified in a server-side
session and never returned access_token/refresh_token. The stateless SPA
client never sends cookies, so after entering a correct TOTP code the
frontend had no way to authenticate and login got stuck (U-MFA-002).

verifyLogin now accepts client_id/redirect_uri (already sent by
authService.ts) and, after TOTP succeeds, generates an authorization code
via OAuth2Plugin::generateAuthorizationCode and immediately exchanges it
for tokens via exchangeCodeForToken, returning access_token/refresh_token
in the same response. No PKCE on this leg since the first-factor
/oauth2/login step does not use PKCE today.

Also appends a review addendum to PRD/mfa_auth_code_pkce_design.md
documenting the session-state/CSRF gaps in the proposed Authorization
Code + PKCE + hosted-login-page architecture, and splits that broader
migration out as a separate follow-up (not implemented here).

Verified: OAuth2Test_test.exe 228/228 cases (55933 assertions), backend
E2E scripts test-oauth2-endpoints.ps1 (55/55) and test-admin-endpoints.ps1
(0 failed), frontend Playwright e2e (19/19) and vitest (15/15), plus a
manual real-backend run of the full register->login->mfa-setup->
mfa-verify->access-protected-resource flow.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@voidvec

voidvec commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

代码审查结论

整体方向正确——TOTP 验证通过后服务端直接生成 auth code 并兑换 token,符合 §7 最小修复方案的设计,且前端 verifyMfa() 已在传 client_id/redirect_uri,无需改前端。但发现 2 个 P0 必须修复 + 1 个 P1 建议项,下方均附 file:line 与代码事实依据。


🔴 P0-1:client_id 未校验,可对任意 client 签发 token(授权混淆)

MfaController.cc:302-316 只检查 clientId/redirectUri 非空,未校验该 client 是否存在、是否启用、是否允许走这条 MFA 路径。TokenService::generateAuthorizationCode(TokenService.cc:25-62)同样完全不校验 clientId 是否注册,直接 saveAuthCode。

后果:攻击者用合法 mfa_token(见 P1)+ 任意图的 client_id(例如 admin-console-client)请求 /oauth2/mfa/verify,就能拿到绑定到该 client 的 token,绕过客户端隔离。exchangeCodeForToken 里的 validateClient(TokenService.cc:95)虽然会校验 client,但这是后续步骤,且即便它拒绝,auth code 已被写入存储。

修复:在 verifyLogin 调用 generateAuthorizationCode 之前,先 storage->getClient(clientId, ...)(或复用 validateRedirectUri)确认 client 存在、是 vue-client 这类首方 PUBLIC client,并把传入的 redirectUri 与该 client 注册的 redirect_uri 做白名单匹配(见 P0-2)。

🔴 P0-2:redirect_uri 未做白名单校验 → 本端点独有的 open-redirect 风险面

TokenService::generateAuthorizationCode 不校验 redirectUri。consumeAuthCode(PostgresOAuth2Storage.cc:467-476)虽在兑换时比对 redirectUri == storedRedirectUri,但两端都接受同一攻击者注入的值(生成时来自请求体,兑换时也来自同一请求体),比对恒为真,校验形同虚设。

由于本 PR 是服务端内部兑换(不 302),这个 redirectUri 不会直接跳转,所以当前不构成可利用的 open redirect——但它会被绑定进 auth code 记录,若后续有任何路径基于该字段做跳转或日志回显,即成漏洞。更重要的是它违反了 RFC 6749 §3.1.2.3(redirect_uri 必须与注册值匹配)。

修复:调用 plugin->validateRedirectUri(clientId, redirectUri, ...)(OAuth2Plugin.cc:175-182 已有此 API,委托给 ClientService::validateRedirectUri 做注册白名单匹配),失败则拒绝签发。

🟠 P1:mfa_token 是裸 internal user id(既存问题,但本 PR 放大了影响面)

SessionController.cc:426 生成 mfa_token = std::to_string(internalId)——纯数字、无签名、无 TTL 字段、无绑定 client/state。MfaController.cc:332 直接拿它当 WHERE id = $1 查询主键。这是既存设计(代码注释里也写了 "in production, this should be a signed short-lived JWT"),本 PR 没有引入它。

但本 PR 把通过该字段的后果从 "session flag" 升级为 "真 access_token",使猜测/枚举 internal id 的收益从 "session 标记" 变为 "可用的访问令牌"。internalId 若是自增整数(需确认 users.id 是否 sequential),枚举成本极低。

建议:不在本 PR 强制修(属 §6.2 已记录的会话状态传递清单),但应在本 PR 描述或代码注释里显式标注"依赖 mfa_token 强度"这一前提,并在 §6.2 的 pending_user_internal_id 行补一句"当前实现为裸 id,枚举风险,需在 §6 方案里替换为签名 token"。否则该 PR 的"最小修复"描述低估了它对攻击面的放大。


✅ 正确的部分

  • TOTP 通过 → generateAuthorizationCode → exchangeCodeForToken 的服务端内部兑换链路逻辑正确,消除了 SPA 无状态拿不到 token 的根因。
  • scope 默认 "openid profile email" 合理。
  • error 处理统一走 ErrorResponder/respondError,与既有风格一致。
  • AuditLogger::log("mfa_verified", "success", ...) 保留,审计可观测。
  • PRD §6 评审补充章节质量很高——明确列出会话字段清单、open-redirect/CSRF 风险、GitHub/consent 兼容性、测试清单,并把架构迁移正确地拆为独立提案,避免了与本次 bug fix 混入。

⚠️ 顺带指出(既存、非本 PR 引入)

MfaController.cc:418-422 的 backup code 分支实际只返回 "TOTP incorrect",注释写 "simplified: in production parse JSON array"——即 backup code 登录从未实现。本 PR 未触碰它,但若 U-MFA 测试用例里有用 backup code 的路径,需确认是否被覆盖。


结论:P0-1(client_id 校验)和 P0-2(redirect_uri 白名单)必须在合入前修复——两者都是 generateAuthorizationCode 之前缺一道校验的问题,修复成本低(复用已有 validateRedirectUri + getClient),不修复则该端点成为 "用 mfa_token + 任意 client_id 换任意 client token" 的跳板。修完这两点即可批准。

注:GitHub 不允许仓库 owner 对自己的 PR 提 "request changes",故以评论形式提交评审。

@voidvec

voidvec commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

评审意见自我复核(修正 P0-1 表述)

对刚才的评审做了一次代码复核,发现 P0-1 表述有误,需更正;P0-2 和 P1 经核对准确。修正如下:

P0-1 修正:不是"任意 client_id",而是"任意已注册的 PUBLIC client_id"

原评审说"用合法 mfa_token + 任意 client_id 即可拿到 token"——这是过度表述。实际链路是:

  1. generateAuthorizationCode(TokenService.cc:25)确实不校验 clientId,直接写 auth code。
  2. 但 exchangeCodeForToken(TokenService.cc:95)会调用 storage->validateClient,PostgresOAuth2Storage::validateClient(PostgresOAuth2Storage.cc:221-243)执行 WHERE client_id = $1 查询,未注册的 client 会被 findOne 拒绝。
  3. 因此攻击者无法用 "完全不存在" 的 client_id 换 token。

真正的风险是:用合法 mfa_token(来自用户自己的首因子登录)+ 另一个已注册的 PUBLIC client_id(如 admin-console,见 OAuth2Server/sql/seed/dev_admin_console_client.sql:7,8 确认是 PUBLIC 类型),MFA 验证通过后会签发绑定到该 client 的 token。这是跨 client 授权混淆——MFA 端点应只为用户当前登录的那个 client(vue-client)签发 token,而不是任意已注册 client。严重度仍为高(授权混淆是 OWASP A01 类),但比"任意 client"低。

修复不变:在 generateAuthorizationCode 前校验传入的 client_id 与首因子登录时绑定的 client 一致(这需要 mfa_token 里携带 client 绑定信息,正是 P1 指出的 mfa_token 强度问题);或在最小修复层面,至少限制只允许 vue-client 这一首方 client 走这条 MFA 路径。

额外澄清:scope 越权不成立(我复核时排除了一项误报)

复核时曾担心请求体里 scope=admin 会导致越权,但核对 AuthorizationFilter.cc:147-150:/api/admin/* 的鉴权读的是 DB 里的 user roles(getUserRoles(at->userId)),不是 token 的 scope 字段。所以即便攻击者拿到 scope=admin 的 token,也拿不到 admin 权限(除非该用户本身在 DB 里有 admin role)。这一点 PR 无责,特此排除。

P0-2 / P1 复核结论:准确

  • P0-2:consumeAuthCode(PostgresOAuth2Storage.cc:467-476)的 redirect_uri 比对确实形同虚设(生成端和兑换端的值都来自同一请求体)。本 PR 服务端内部兑换不 302,所以当前无可利用 open redirect,但违反 RFC 6749 §3.1.2.3。表述准确。
  • P1:SessionController.cc:426 确认 mfa_token = std::to_string(internalId),裸 id 无签名。表述准确。

修正后的合入建议:P0-1(client_id 一致性校验,严重度从"任意 client"下调为"跨已注册 PUBLIC client 授权混淆")和 P0-2(redirect_uri 白名单)仍建议修,但 P0-1 的紧急度因"需已注册 client + 需用户自己有效的 mfa_token"两个前提而低于最初表述。

voidvec added 3 commits July 6, 2026 12:47
- OAuth2Admin/package-lock.json, OAuth2Frontend/package-lock.json: npm
  audit fix output (security/dependency updates).
- OAuth2Admin/src/main.ts: remove top-level await on restoreSession().
  The router beforeEach guard already awaits the deduped
  ensureSessionRestored() before protected routes, so the one-shot
  session restore completes before first render regardless. Top-level
  await broke the Vite es2020 build target (esbuild transpile error).
  Mirrors the OAuth2Frontend fire-and-forget pattern.
Regenerate the Drogon ORM model for the users table so it matches the
V022 migration's mfa_pending_client_id / mfa_pending_redirect_uri
columns. The Users.cc model was previously absent from the project
(only a stale backup existed); it is now generated with getter/setter
coverage for both new nullable columns, consistent with the orm-gen
project convention of regenerating ORM models after any schema change.
PR #9's MfaController::verifyLogin issued OAuth2 tokens after a correct
TOTP check but never verified the second-factor request's client_id /
redirect_uri against the first-factor login that produced the mfa_token.
Because mfa_token is just std::to_string(internalId) with no client
binding, an attacker holding a valid mfa_token + correct TOTP code
could substitute any other registered client's client_id / redirect_uri
and receive a token minted for that other client (P0-1), and
redirect_uri was never checked against the whitelist on this leg (P0-2).

Fix (per .kiro/specs/mfa-cross-client-auth-fix):
- V022 migration: add mfa_pending_client_id / mfa_pending_redirect_uri
  nullable columns on users (substrate for the login-session binding).
- SessionController::login: when returning mfa_required, persist the
  request's client_id / redirect_uri as the pending binding BEFORE the
  response is sent; fail closed (DB_QUERY_ERROR) if the UPDATE fails so
  verifyLogin never runs against a stale/missing binding.
- MfaController::verifyLogin: after the TOTP check (ordering preserved),
  run validateClient -> validateRedirectUri -> pending-binding equality;
  all three reject with AUTH_INVALID_CREDENTIALS (401) so an
  unregistered client, a non-whitelisted redirect_uri, a mismatched
  binding, and a wrong TOTP code are indistinguishable from the outside
  (no client-registration oracle). On a fully successful verification,
  clear the pending binding back to NULL (best-effort; tokens are
  already issued and cannot be un-issued).

Tests (15 new DROGON_TEST cases, all green; full suite 243 cases /
56035 assertions pass with zero regressions):
- Property1 exploratory: unregistered client / non-whitelisted
  redirect_uri / cross-client confusion / null-binding edge case
  (confirmed the bug on unfixed code: cases 2 & 3 issued real tokens).
- Property5/6: DB-state coverage of pending-binding persist (login),
  overwrite, clear-on-success, and keep-on-reject.
- Property7: preservation baseline (matching-binding issuance, wrong
  TOTP, unknown mfa_token, missing fields, non-MFA login).
- Integration: happy-path end-to-end + cross-client rejection confirms
  no oauth2_access_tokens row is created for rejected attempts.

Out of scope (unchanged): mfa_token format/lifetime/randomness, scope
validation in verifyLogin, PKCE on the MFA leg, and consumeAuthCode's
existing redirect_uri equality logic for the general authorization_code
grant flow.
@voidvec

voidvec commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

两条 P0 已在最新推送中修复(commit 377a42e + ab59b89),P1 按你建议作为已知接受限制保留。逐项回应如下。

P0-1(跨已注册 client 授权混淆)— 已修复 ✅

你第 3 条评论里的自我修正是对的:真正的风险是跨已注册 PUBLIC client,不是"任意 client_id"。我在写探索测试时实测验证了这条链路,和你的复核完全一致:

  • Case 1(未注册 client)实测:verifyLogin 用 client_id="not-a-real-client" 请求,返回 HTTP 500(存储层 WHERE client_id = $1 findOne 失败报错),不会签发 token——印证了你说的"exchangeCodeForToken→validateClient 会拒绝未注册 client"。所以未注册 client 路径只是"500 而非干净的 401",不是授权混淆。
  • Case 3(跨 client 混淆)实测:以 vue-client 登录拿 mfa_token,再用 admin-console 自己合法的 client_id/redirect_uri(http://localhost:5174/admin/callback,确在白名单)请求 verifyLogin,未修复代码直接 200 签发绑定到 admin-console 的 token——这是真实的 P0-1。

修复方案(commit ab59b89,规格见 .kiro/specs/mfa-cross-client-auth-fix/):在 verifyLogin 的 TOTP 校验通过后、生成 auth code 之前,加一层首因子登录会话绑定——

  1. V022 迁移给 users 表加 mfa_pending_client_id / mfa_pending_redirect_uri 两列;
  2. SessionController::login 返回 mfa_required 前先把本次请求的 client_id/redirect_uri 写入这两列(fail-closed,UPDATE 失败则 DB_QUERY_ERROR,不发 mfa_token);
  3. verifyLogin 读取该绑定,与第二因子请求的 client_id/redirect_uri 比对,不等即拒。

修复后 Case 3 由 200 签发变为 401 AUTH_INVALID_CREDENTIALS(Property1_MfaCrossClientAuthFix_CrossClientConfusion 已验证)。

P0-2(redirect_uri 白名单)— 已修复 ✅

修复在同一 commit:verifyLogin 在绑定比对之前先 plugin->validateRedirectUri(clientId, redirectUri, ...),复用 OAuth2StandardController::authorize 已有的白名单校验。Case 2(vue-client + 非白名单 redirect_uri)实测由未修复的 200 签发变为修复后的 401(Property1_MfaCrossClientAuthFix_NonWhitelistedRedirectUri)。

关于 no-oracle:三层新增校验(validateClient → validateRedirectUri → 绑定比对)任一失败都用 AUTH_INVALID_CREDENTIALS(401),与"错误 TOTP"不可区分,不引入客户端注册探针。

P1(mfa_token = 裸 id 无签名)— 按建议保留为已知限制 ⚠️

认同这是真实的 P1。本次未改 mfa_token 格式/有效期/随机性,理由同你的判断——它牵涉首因子 /oauth2/login 的契约变更,应作为独立提案,不塞进这个 hotfix。已在 .kiro/specs/.../bugfix.md 明确列为"不在范围/已知接受限制",并注明一个相关副作用:因为 mfa_token 无 nonce,同一用户并发登录会相互覆盖 pending 绑定列——这是本次修复引入的两列继承自 mfa_token 的已知限制,不在本次解决。

验证

完整套件 243/243 用例、56035 断言全过(新增 15 个 MFA 跨客户端修复测试,零回归)。采用 bug-condition 方法论:先在未修复代码上跑探索测试坐实 P0-1/P0-2(Case 2/3 确签发真实 token),实现修复后复跑全部转绿。

另外 ORM 模型也按项目 orm-gen 惯例随 V022 重生成(Users.h/Users.cc,原项目里 Users.cc 缺失,已补齐含两新列的 getter/setter)。

@wangrh0909
wangrh0909 merged commit ba49b86 into master Jul 6, 2026
3 checks passed
voidvec added a commit that referenced this pull request Jul 29, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
voidvec added a commit that referenced this pull request Jul 29, 2026
…) + comment #4/#8/#9

P1 #6 (RFC 6749 §5.1): expires_in / id_token exp / device refresh TTL were
hardcoded 3600/2592000; now use configured access_token_ttl/refresh_token_ttl
(OAuth2Plugin getAccessTokenTtl()/getRefreshTokenTtl() accessors). 6 sites:
TokenService auth_code expires_in + id_token exp + refresh expires_in;
client_credentials + device_code issuance in TokenEndpointController.

P1 #5 (RFC 8628 §3.4): device_code redemption now authenticates by client_type
-- CONFIDENTIAL clients require a valid client_secret (validateClient); PUBLIC
clients keep the client_id-vs-device-row binding. Lookup wrapped in a local
lambda captured BY VALUE (not [&]) because it runs from getClient's async
callback after token() has returned -- [&] would dangle deviceCodeHash/dbClient.

P1 #3 (RFC 6749 §4.1.2 single-use): device-code redemption check-then-delete
was non-atomic (two concurrent redemptions both issued). Replaced with a
pre-issue atomic UPDATE...WHERE status='approved' RETURNING; affected-row gate
makes exactly one concurrent winner issue, loser gets invalid_grant (fail-
closed). UPDATE...RETURNING is a db-operations.md raw-SQL exemption.

Comment-only (#4 [this] capture, #8 validateAccessToken no-self, #9 JWKS empty
response): document existing-correct behavior, deter repeat review reports.

Tests (live-server integration, PG+Redis): TokenExpiryTtlConfigTest,
DeviceCodeClientAuthTest (conf no-secret rejects / conf secret ok / pub ok),
DeviceCodeRaceConditionTest (concurrent redemption -> exactly one wins).
All pass + no regressions (RFC6749 compliance 4504 assertions, auth_code E2E,
refresh rotation, authorize PKCE passthrough).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@voidvec
voidvec deleted the fix/mfa-verify-issue-token branch July 31, 2026 06:17
voidvec added a commit that referenced this pull request Aug 30, 2026
…loor, bootstrap self-heal, review cleanups

Address PR #141 review (1 must-fix, 8 should-fix, quick considers):

- #1 consent_csrf declared as a required query parameter in openapi.yaml
  and the C++ endpoint doc registration; apps/server/docs/api/openapi.json
  regenerated from a live server run; Python/Go clients regenerated.
- #2 nonce one-shot is now atomic: the find/verify/erase sequence is
  serialized by a process-wide mutex (consent traffic is tiny; in-process
  session storage).
- #3 identity AuthService no longer captures this in the async validateUser
  callback — the legacy-hash policy flag is value-captured
  (db-operations rule 4).
- #4/#12 AdminBootstrapper reworked as ensure-* steps: an existing admin
  user row is reused and role/mapping completed (partial failures self-heal
  on restart); the random password is printed only after the insert
  succeeded; a mapping failure no longer reports created=true.
- #5 POST /api/admin/users enforces auth.min_password_length
  (VALIDATION_PASSWORD_TOO_SHORT) — closing the admin bypass.
- #6 consent integration tests reworked: missing-nonce now drives the real
  authorize-minted slot (400), deny-to-unregistered-uri (400, no Location)
  and deny-to-registered-uri (302 access_denied) branches are covered.
- #7/#8 deployment.md: auto-bootstrap wording fixed, bogus ADMIN_SALT
  removed (PBKDF2 keeps salt empty); website i18n error table mirrored
  (3014/4007).
- #9 main.cc bootstrap probes with backoff (5 attempts) and LOG_WARN on
  failure instead of a single silent 2s probe.
- #13 unique-violation detection layered (SqlError 23505 -> constraint
  name -> english/zh localized text), mirroring the
  PostgresSocialAccountRepository pattern.
- #11 gate-4 comment corrected; #15 CHANGELOG duplicate Unreleased merged;
  #17 AGENTS.md consent.csp entry removed.

Considered-but-not-taken: #10 multi-slot nonces (tracked follow-up), #14
admin UI hardcode (server now enforces; hint stays), #18 MFA-pending
session through consent (pre-existing authorize behavior, tracked).
voidvec added a commit that referenced this pull request Aug 30, 2026
…loor, bootstrap self-heal, review cleanups

Address PR #141 review (1 must-fix, 8 should-fix, quick considers):

- #1 consent_csrf declared as a required query parameter in openapi.yaml
  and the C++ endpoint doc registration; apps/server/docs/api/openapi.json
  regenerated from a live server run; Python/Go clients regenerated.
- #2 nonce one-shot is now atomic: the find/verify/erase sequence is
  serialized by a process-wide mutex (consent traffic is tiny; in-process
  session storage).
- #3 identity AuthService no longer captures this in the async validateUser
  callback — the legacy-hash policy flag is value-captured
  (db-operations rule 4).
- #4/#12 AdminBootstrapper reworked as ensure-* steps: an existing admin
  user row is reused and role/mapping completed (partial failures self-heal
  on restart); the random password is printed only after the insert
  succeeded; a mapping failure no longer reports created=true.
- #5 POST /api/admin/users enforces auth.min_password_length
  (VALIDATION_PASSWORD_TOO_SHORT) — closing the admin bypass.
- #6 consent integration tests reworked: missing-nonce now drives the real
  authorize-minted slot (400), deny-to-unregistered-uri (400, no Location)
  and deny-to-registered-uri (302 access_denied) branches are covered.
- #7/#8 deployment.md: auto-bootstrap wording fixed, bogus ADMIN_SALT
  removed (PBKDF2 keeps salt empty); website i18n error table mirrored
  (3014/4007).
- #9 main.cc bootstrap probes with backoff (5 attempts) and LOG_WARN on
  failure instead of a single silent 2s probe.
- #13 unique-violation detection layered (SqlError 23505 -> constraint
  name -> english/zh localized text), mirroring the
  PostgresSocialAccountRepository pattern.
- #11 gate-4 comment corrected; #15 CHANGELOG duplicate Unreleased merged;
  #17 AGENTS.md consent.csp entry removed.

Considered-but-not-taken: #10 multi-slot nonces (tracked follow-up), #14
admin UI hardcode (server now enforces; hint stays), #18 MFA-pending
session through consent (pre-existing authorize behavior, tracked).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants