Repository navigation
feat(auth): close auth-flow error-code gaps (G1-G6) + 9 catalog entries - #10
Merged
Merged
Conversation
修复 error-code-message-standardization 发版后遗留的认证流错误信息缺口: 注册/MFA/WebAuthn/设备授权/密码重置/邮箱验证/限流等控制器把多种不同失败 原因折叠进同一个笼统 Error_Code,导致用户看不出具体失败原因。 新增 9 条 Error_Catalog 条目(Req 8): VALIDATION_USERNAME_TAKEN(3006,409)/EMAIL_TAKEN(3007,409)/ CREDENTIAL_ALREADY_REGISTERED(3008,409)/RESET_TOKEN_INVALID(3009)/ VERIFICATION_TOKEN_INVALID(3010)/DEVICE_CODE_INVALID(3011)/ RATE_LIMITED(3012,429)/AUTH_MFA_CODE_INVALID(4004)/MFA_NOT_CONFIGURED(4005) 后端 gap 路由(G1-G5): - AuthService::registerUser 回调从自由文本改为结构化 errorCode;按 DB 约束名(users_username_key/idx_users_email_unique)路由到精确冲突码, 用户名冲突优先;基础设施失败改用 INTERNAL_ERROR。SessionController 直接转发 errorCode,不再硬编码 VALIDATION_INVALID_INPUT (G1) - MfaController::verifySetup 未配置→AUTH_MFA_NOT_CONFIGURED, TOTP 错误→AUTH_MFA_CODE_INVALID (G2) - WebAuthnController::registerFinish 检测 credential_id 唯一约束冲突→ VALIDATION_CREDENTIAL_ALREADY_REGISTERED (G3) - DeviceAuthController::approveDevice→VALIDATION_DEVICE_CODE_INVALID (G4) - PasswordReset/EmailVerification token 失效→专用码,保留防枚举行为 (G5) G6 Hodor 限流 Envelope 化: - main.cc 在确认 Hodor 加载后调用 setRejectResponseFactory,用 ErrorResponder::buildResponse + VALIDATION_RATE_LIMITED 取代纯文本 拒绝体;插件未加载时跳过,不阻断启动 (G6) - ErrorResponder::toDrogonStatus 新增 429 case(原 switch 不支持 429, 会落入 default→500,是本特性 429 码生效的前提) 前端同步(Req 9):OAuth2Frontend/OAuth2Admin zh-CN.ts 各追加相同 9 条 计划遗漏的必要同步(执行中发现并修复): - docs/backend/api-reference.md §5.1 表格追加 9 行 + 更新 override 说明 (被 ErrorCatalogDocTest 断言一一对应) - ErrorCatalogPropertyTest httpStatusOverrideFor() 加入 4 个新 override 码 - ErrorCatalogRegressionTest 总数断言 16→25 验证:后端 243 test cases / 56872 assertions 全过; 前端 messageCatalog + crossAppConsistency property 测试 5/5 全过。 G7(账户锁定防枚举)为刻意保留的设计,未改动。
- CLAUDE.md: 标注 run-backend/test-backend/full-test 的 Release/Debug 用法; 补充两个前端项目 (OAuth2Frontend/OAuth2Admin) 的 npx playwright test (E2E) 与 npm run test:unit (单元) 命令入口 - README.md: 后端启动路径默认改为 Release 构建产物
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
wangrh0909
approved these changes
Jul 7, 2026
voidvec
added a commit
that referenced
this pull request
Jul 29, 2026
) The authorization_code, refresh_token, and client_credentials paths left OAuth2AccessToken::issuedAt at its 0 default (only device_code and GitHub already set it). RFC 7662 introspection silently omits `iat` when issuedAt is 0, so introspected tokens had no issue timestamp and admin token listings sorted by issued_at were wrong. Set issuedAt = now at all three remaining issuance points. Test: TokenIssuedAtIntrospectionTest -- issue a client_credentials token, introspect it (Bearer passes the OAuth2AuthFilter gate; client creds in the body), assert `iat` is present, non-zero, and a recent timestamp. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
修复
error-code-message-standardization发版后遗留的认证流错误信息缺口:注册 / MFA / WebAuthn / 设备授权 / 密码重置 / 邮箱验证 / 限流等控制器把多种不同失败原因折叠进同一个笼统Error_Code(多为VALIDATION_INVALID_INPUT),导致用户看不出具体失败原因(如注册时看不出是用户名冲突还是邮箱冲突)。实现依据
.kiro/specs/auth-flow-error-code-gaps/(requirements / design / tasks)。改动内容
新增 9 条 Error_Catalog 条目(Req 8)
VALIDATION_USERNAME_TAKENVALIDATION_EMAIL_TAKENVALIDATION_CREDENTIAL_ALREADY_REGISTEREDVALIDATION_RESET_TOKEN_INVALIDVALIDATION_VERIFICATION_TOKEN_INVALIDVALIDATION_DEVICE_CODE_INVALIDVALIDATION_RATE_LIMITEDAUTH_MFA_CODE_INVALIDAUTH_MFA_NOT_CONFIGURED后端 gap 路由(G1–G5)
AuthService::registerUser回调从自由文本改为结构化errorCode;按 DB 约束名(users_username_key/idx_users_email_unique)路由到精确冲突码(用户名冲突优先),未识别约束兜底VALIDATION_INVALID_INPUT;基础设施失败改用INTERNAL_ERROR。SessionController直接转发errorCode,不再硬编码回退。MfaController::verifySetup未配置 →AUTH_MFA_NOT_CONFIGURED,TOTP 错误 →AUTH_MFA_CODE_INVALID。registerFinish检测credential_id唯一约束冲突 →VALIDATION_CREDENTIAL_ALREADY_REGISTERED,否则保留DB_QUERY_ERROR。approveDevice的affectedRows()==0→VALIDATION_DEVICE_CODE_INVALID。G6 Hodor 限流 Envelope 化
main.cc在确认 Hodor 加载后调用setRejectResponseFactory,用ErrorResponder::buildResponse+VALIDATION_RATE_LIMITED取代纯文本拒绝体;插件未加载时跳过,不阻断启动(Req 6.4–6.7)。关键缺陷修复:
ErrorResponder::toDrogonStatus原 switch 不支持 HTTP 429(落入 default → 500),新增case 429: k429TooManyRequests,这是VALIDATION_RATE_LIMITED能返回正确 429 的前提。前端同步(Req 9)
OAuth2Frontend/OAuth2Admin的zh-CN.ts各追加相同的 9 条词条(跨应用逐字一致)。G7 账户锁定(刻意保留,未改动)
AuthService::validateUser锁定分支继续返回与密码错误相同的AUTH_INVALID_CREDENTIALS,用于防止用户名枚举。计划执行中发现并修复的必要同步
docs/backend/api-reference.md§5.1:追加 9 行表格 + 更新 override 说明段ErrorCatalogPropertyTest::httpStatusOverrideFor():加入 4 个新 override 码ErrorCatalogRegressionTest:总数断言 16 → 25验证
./manage.ps1 full-test -debug(8 步全流程)npm run test:unit(vitest)npx playwright test(E2E)npm run test:unit(vitest)npx playwright test(E2E)0 失败。G6 Hodor 接线 + ErrorResponder 429 支持 + 各控制器路由在真实运行时环境与两个前端真实浏览器环境下均无回归。
注意
e24907c) 更新CLAUDE.md/README.md的构建/测试命令说明(标注 Debug/Release、补充前端测试入口),与错误码特性无功能关联,但属同一开发周期产物。