Repository navigation
fix(frontends): close gap-analysis P0 breaks + P1 quick wins (admin MFA login, WebAuthn contract, logout, device approval) - #140
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Code Review — RFC/正确性复核后的确认问题经过对后端代码链路和 OAuth2/OIDC 相关 RFC 的严格复核,以下是确认的真实问题。 Critical: 用户门户 logout 竞态 — access token 同时被撤销和被用作 Bearer 认证文件:
后端证据链:
如果 对比 admin store ( 修复建议:移除对 access token 的单独 const revokes: Promise<Response>[] = []
if (access) {
// /oauth2/logout handles AT revocation + session cleanup + backchannel RP fanout
revokes.push(fetch('/oauth2/logout', {
method: 'POST',
headers: { Authorization: `Bearer ${access}` },
keepalive: true,
}))
}
if (refresh) {
revokes.push(fetch('/oauth2/revoke', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: body(refresh),
keepalive: true,
}))
}
await Promise.allSettled(revokes)Warning: e2e 测试 mock 使用旧的
|
…k envelopes, RT retention
Review triage (4 items, objective verdicts against RFCs and code):
1. Critical, real bug, fixed as suggested: user logout() sent the same
access token concurrently to /oauth2/revoke and /oauth2/logout (Bearer).
Whichever landed first invalidated the other's credentials — logout's
OAuth2AuthFilter would 401, skipping the server-side session clear and
the backchannel RP fanout. The access token now goes only to
/oauth2/logout (which revokes it server-side, SessionController::logout),
mirroring the admin store; refresh token stays on /oauth2/revoke. e2e
now asserts revokes carry only the refresh token.
2. Warning, accepted with a factual correction: the two account.spec
authorized-apps mocks used the fictional {apps:...} envelope. The tests
did NOT fail (reviewer's 'may not pass' was wrong) because
AuthorizedAppsPage has its own .apps first fallback and never calls the
service layer — but they were exercising a dead branch instead of the
real contract. Mocks now use {authorized_apps, total} and the page's
dead .apps fallback is removed.
3. Warning, problem real but proposed fix rejected on RFC grounds:
setTokens(access) with no refresh field did leave memory/storage
divergent. The suggested localStorage.removeItem() violates RFC 6749 §6
— when the server issues no new refresh token, the old one remains valid
and must be KEPT; deleting it logs the user out. setTokens now leaves
the refresh-token state untouched when the field is absent, and replaces
it only when the server actually rotates it.
4. Warning, real, fixed with a corrected placement: stale successMessage
was never cleared. Clearing inside fetchTokens (as suggested) wipes the
message the bulk-revocation actions set right before calling it — each
action now owns the banner lifecycle (clear up front, show outcome),
fetchTokens no longer touches banners.
Also replaces the remaining token literals in auth.spec MFA mocks with the
generated-placeholder idiom (Mimosa L3 finding).
评审意见逐条裁定(RFC/代码事实复核)感谢评审——4 条全部核实。裁定:1 条真 bug(采纳修法)、2 条问题成立(修法/现象判断有修正)、1 条修法违反 RFC(采纳问题、否决修法)。修复已随 1. logout 竞态(Critical)✅ 真 bug,采纳修法复核属实,且是本 PR 引入的回归: 2. authorized-apps 旧信封 mock(Warning)
|
The endpoint is declared admin-gated in openapi.yaml (AuthorizationFilter), but no rbac_rules entry existed for its path — and AuthorizationFilter denies by default when no rule matches, so device approval returned 403 to every role including admin. The user-portal page calling it was also wired to a nonexistent /oauth2/device/verify path; approval UI moves to the admin console in the following commits (gap-analysis user E2).
…ser honesty fixes Gap-analysis P0/P1 round for the admin console: - MFA login loop (E2): an mfa_required response used to dead-end — the LoginPage ignored it and bounced back to /login forever, and the stashed PKCE verifier had no consumer. login()/verifyMfa() now share applySession(); verifyMfa() consumes the one-shot verifier and calls POST /oauth2/mfa/verify (mfa_token+code+client_id+redirect_uri+code_verifier); LoginPage gains the 6-digit code view with error-banner retry. - CallbackPage (E1): removed — the json-mode login flow never redirects, and the page called a nonexistent auth.handleCallback (guaranteed TypeError). The registered redirect_uri string stays (login/token still send it). - Device approval (E2): new /devices page + nav entry posting form-urlencoded user_code+user_id to /oauth2/device/approve (admin-audience now reachable thanks to the config rbac rule); replaces the broken user-portal page. - Dashboard (E3): /health/ready rendered honestly — degraded status shows amber, component dots follow actual values, no hardcoded 'Connected' fallback; stats gain the previously dropped logs_today card. - Logs: actor_id filter input (backend-supported, never exposed) and a Target column (target_type/target_id were fetched but never rendered). - Users: create form gains email_verified/mfa_enabled; roles_failed/warning and delete-time tokens_revoked=false now surface as errors instead of a blanket success. - Tokens: bulk revocation reports the backend count instead of silence; console.error residue cleaned. - e2e: MFA flow end-to-end tests, device approval, logs/users/tokens click-throughs (first-ever delete/disable/revoke-by-client executions), dashboard honest-rendering cases; mocks for mfa/verify + device/approve.
…backup codes
Gap-analysis P0/P1 round for the user portal:
- WebAuthn registration (E1, was 100% broken): begin now reads the nested
{options} envelope and base64url-decodes challenge/user.id (atob threw on
the -_ alphabet); finish posts the backend contract {credential_id,
public_key, name} instead of the raw browser attestation envelope.
base64UrlDecode added next to the existing encoder in utils/pkce.ts.
Credential list renders credential_id/name/sign_count (E4 — cred.id and
created_at never existed server-side); copy no longer promises working
passwordless sign-in while assertion verification is unimplemented.
- Logout protocol (E3): end_session carried client_id (not a parameter) and
post_logout_redirect_uri without id_token_hint — a guaranteed 400 issued
BEFORE session clear, so neither the server session nor backchannel RP
notification ever happened, silently swallowed by an empty catch. Logout
now keeps the two revokes and adds POST /oauth2/logout with the Bearer
token (revokes + clears session + fans out logout_token), mirroring the
admin store.
- Consent (E7): user_id prefers the server-provided query value over the
racy store sub; /consent route gains the auth guard (fullPath redirect);
with neither source present the actions disable instead of submitting a
guaranteed-500 user_id=''.
- http.ts: the blanket '/oauth2/' no-refresh exclusion dropped userinfo from
the auto-refresh path, freezing the UI as 'User' until an unrelated /api/*
401 — replaced with an explicit credential-endpoint whitelist.
- MFA backup codes: the 10 one-time recovery codes were discarded, leaving
no self-service recovery; they now show in a blocking one-time layer with
copy/download before 'I have safely saved my codes'.
- Service/type contracts (E5/E6): getAuthorizedApps reads authorized_apps;
setupMfa types otpauth_uri; TokenResponse.refresh_token optional (no more
persisting 'undefined'); fictional User.mfa_enabled removed.
- DeviceVerifyPage deleted (nonexistent endpoint + admin-only audience);
e2e mocks aligned to real contracts (otpauth_uri, authorized_apps,
credential shapes, /oauth2/logout) and new specs cover the WebAuthn flow,
backup codes, MFA disable, consent actions, and logout request shape.
Self-review catch during PR review: verifyMfa() cleared the stashed code_verifier before the first attempt, so a wrong TOTP code burned it — every retry then hit the token exchange with an empty verifier and failed PKCE (TokenService rejects an empty code_verifier whenever a challenge is bound to the code), turning the old login loop into a retry loop. The verifier is now removed only after a successful verification, in both the admin store and the user portal's authService. e2e regression test asserts both attempts carry the same verifier.
…k envelopes, RT retention
Review triage (4 items, objective verdicts against RFCs and code):
1. Critical, real bug, fixed as suggested: user logout() sent the same
access token concurrently to /oauth2/revoke and /oauth2/logout (Bearer).
Whichever landed first invalidated the other's credentials — logout's
OAuth2AuthFilter would 401, skipping the server-side session clear and
the backchannel RP fanout. The access token now goes only to
/oauth2/logout (which revokes it server-side, SessionController::logout),
mirroring the admin store; refresh token stays on /oauth2/revoke. e2e
now asserts revokes carry only the refresh token.
2. Warning, accepted with a factual correction: the two account.spec
authorized-apps mocks used the fictional {apps:...} envelope. The tests
did NOT fail (reviewer's 'may not pass' was wrong) because
AuthorizedAppsPage has its own .apps first fallback and never calls the
service layer — but they were exercising a dead branch instead of the
real contract. Mocks now use {authorized_apps, total} and the page's
dead .apps fallback is removed.
3. Warning, problem real but proposed fix rejected on RFC grounds:
setTokens(access) with no refresh field did leave memory/storage
divergent. The suggested localStorage.removeItem() violates RFC 6749 §6
— when the server issues no new refresh token, the old one remains valid
and must be KEPT; deleting it logs the user out. setTokens now leaves
the refresh-token state untouched when the field is absent, and replaces
it only when the server actually rotates it.
4. Warning, real, fixed with a corrected placement: stale successMessage
was never cleared. Clearing inside fetchTokens (as suggested) wipes the
message the bulk-revocation actions set right before calling it — each
action now owns the banner lifecycle (clear up front, show outcome),
fetchTokens no longer touches banners.
Also replaces the remaining token literals in auth.spec MFA mocks with the
generated-placeholder idiom (Mimosa L3 finding).
5f1b6ac to
cc10022
Compare
… and hooks Consolidates the recurring lessons from the 2026-08/09 engineering sessions (previously only in AI-session memory) into versioned, tool-agnostic assets: - skills: ci-gate-sync (sync-point policies for error codes/endpoints/ migrations/headers), ci-failure-triage (cross-compiler WERROR blind spots, flake taxonomy), release-engineering (six-point + ~15 version carriers, tag recovery, PyPI first publish), pr-workflow (rebase-merge repair, rebase value-loss audit, PAT permission boundary), local-env-runbook (Windows/WSL/Docker/Mimosa/multi-session rules), test-methodology (two test layers, mock injection seam, Playwright pitfalls), and benchmark-methodology (wrk Lua model, A/B discipline, measurement-artifact taxonomy). - rules (path-scoped): sync-points (8-point error-code and 5-point endpoint hard checklists), frontend-contract (verified frontend/backend contract facts), async-cpp-gotchas (traps beyond db-operations: Session::insert no-overwrite, callback double-move, ::drogon:: shadowing). - commands: /preflight (local gate sweep before pushing), /ci-triage (failure classification workflow). - hooks: local-gates.sh (wired to the git-commit PreToolUse hook, replacing the broken full-ctest gate), port-guard.sh, redis-watchdog.ps1. Provenance (source retrospectives): ci-gate-sync/rules.sync-points from PR #115/#141/#149/#157/#179/#180 CI post-mortems; release-engineering from the v1.0.0-v1.1.0 release runs; test-methodology from the coverage push (48.5%->57.2%) and PR #140/#156 e2e work; benchmark-methodology from the four-product comparison campaign; local-env-runbook from environment incident records. AGENTS.md indexes the new rules and skills.
背景
frontend-backend-gap-analysis(2026-08-26 快照,docs-local)在 #108 大改版后逐项复核(基线 382cb71):P0 六项全部仍在。本 PR 修复 P0 全部 + P1 快赢;Phase 2 项(组织管理页、Passkey 登录、Google/WeChat 绑定、spec 治理四项)另行处理。
修复清单
admin 控制台
mfa_required分支接通POST /oauth2/mfa/verify(mfa_token+code+client_id+redirect_uri+一次性 code_verifier),login()/verifyMfa()共用applySession(),登录页增加 6 位码视图 + 错误横幅重试auth.handleCallback,且 json 登录流不经过该页——删除页面与路由(redirect_uri 参数保留)/health/ready三态渲染(ok/degraded/unhealthy → 绿/琥珀/红)、组件圆点按实际值着色、删除 'Connected' 兜底;stats 补logs_today卡片/devices(表单 user_code+user_id),承接从用户门户迁出的审批流roles_failed/warning、删除时tokens_revoked=false透传为错误提示用户门户
{options}+ base64url 解码 challenge/user.id(原 atob 遇-_必炸);finish 改发后端契约{credential_id, public_key, name}(原发浏览器 attestation 信封必 400);凭据列表改渲染credential_id/name/sign_count(原cred.id/created_at后端不存在);文案降级(登录入口待后端断言验证上线)POST /oauth2/logout(Bearer,吊销+清会话+backchannel 通知),与 admin store 对齐isOauthRoute黑名单改显式端点白名单,userinfo 过期可自动刷新(原 UI 冻结为占位用户)config(后端行为修复,1 行规则 ×5 文件)
/oauth2/device/approve补 rbac 规则——原规则缺失 + AuthorizationFilter 默认 DENY = 含 admin 在内全员 403(端点休眠;openapi 如实声明 admin 审批)测试
测试证据
full-test8/8 PASS(rbac 变更无回归;OAuth2 端点 + admin 端点 55/55)openapi / SDK / 版本影响
评审新发现(本 PR 只登记,随 Phase 2 跟进)
/oauth2/consent无认证(高):路由无 filter、不校验 session 用户与 user_id 关系——知道 user_id 的匿名请求可代批/代拒;deny 分支不校验 redirect_uri(approve 校验,不对称)verification_uri默认指后端 origin 无页面(中);options.user.id非 base64url 字节(低);logs 信封total为当前页行数(低)