Repository navigation
feat(security): IAM hardening tranche 1 — consent auth gates, admin bootstrap, password policy - #141
Conversation
…word policy (IAM hardening tranche 1)
Consent authentication closure (F1, highest-severity protocol gap):
POST /oauth2/consent previously accepted anonymous submissions that
trusted the form's user_id — anyone knowing a user id could approve or
deny authorizations on their behalf, and the deny branch 302'd to an
unvalidated redirect_uri (open redirect). Four fail-closed gates now run
before any plugin call:
1. authenticated session required (new AUTH_SESSION_REQUIRED, 4007)
2. user_id must equal the session identity (internal id; reuses
AUTHZ_ACCESS_DENIED 5001)
3. server-minted one-shot CSRF nonce (consent_csrf, TTL 600s) —
deliberately NOT the client-chosen state, which is attacker-known;
authorize mints it into the session and the consent URL
4. deny redirect_uri validated like approve (RFC 6749 §3.1.2.2;
validateRedirectUri only — validateClient with an empty secret
false-rejects CONFIDENTIAL clients)
SPA ConsentPage echoes consent_csrf; orphan consent.csp removed;
openapi consent gains 400/401/403.
Admin bootstrap (#103): on first start, when no user holds the admin
role, create 'admin' with a PBKDF2-SHA256 password from
FULLA_BOOTSTRAP_ADMIN_PASSWORD or randomly generated and printed to the
log exactly once. Idempotent (role-existence check + username unique
constraint); dev seeds make it a no-op. README/deployment docs stop
publishing admin/admin and the sha256sum admin-creation recipe.
Password policy (#103): /api/register gains a server-side minimum
length (auth.min_password_length, default 8; change/reset already
hardcoded 8 and now read the same setting), with new
VALIDATION_PASSWORD_TOO_SHORT (3014) replacing VALIDATION_FORMAT_ERROR
for short passwords. Legacy unsalted-SHA256 verification gains a
configuration gate (auth.allow_legacy_hash, default true = migration
window; rehash-on-login already existed). Frontend hints 6 -> 8.
Tests: new ConsentAuthGateHttpTest (no-session 401, wrong-user 403,
missing-nonce 400, deny-unregistered-uri, authorize-mints-nonce
happy path + one-shot replay). Localized duplicate-key consent insert
treated as success. full_test 8/8 PASS; user/admin e2e green
(107/180); spec governance green.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…legacy gate); oasdiff errata for register password minLength - api-diff: RuleSet.h static policy and AuthService.h setter/member are pure additive declarations — baseline updated per policy. - oasdiff: register password minLength 0->8 is an intentional security tightening (#103, NIST SP 800-63B floor); only caller is this repo's SPA (updated in the same PR), SDKs regenerated. Errata entry added with justification per the ignore-file policy.
DROGON_TEST names now carry the required scope/priority segments (Integration_P1_Consent_*). oasdiff errata backticks unescaped so the gate's text matcher can actually hit the entry.
…ntion) The three new settings (bootstrap_admin.enabled, allow_legacy_hash, min_password_length) were initially written to a root-level auth block. All product knobs in this repo live under custom_config.* — the code reads them via app().getCustomConfig(), and custom_config.auth is the established home (require_pkce_for_public, rate_limit, ...). The root-level block was therefore dead config: parseable JSON whose values the server never read (defaults masked it in tests).
代码评审(三视角:完整性 / 正确性 / 影响面,已逐条对照代码核实)范围: 总体:四道门主体、AdminBootstrapper、密码策略均真实落地且规则合规(Mapper+Criteria+async callback、独立 try-catch、失败均回调)。以下按严重度列出核实后的发现。 🔴 严重问题(MUST FIX)1. 新必填参数
|
…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).
评审意见逐条处置评审已全部核实并修复(1ddc2d0)。逐条结论: MUST-FIX
SHOULD-FIX
CONSIDER
测试本地复跑:OAuth2Tests(含重构后的 consent 用例)全绿;后端构建零警告错误;门预演(治理门/命名/bool-check)通过。CI 运行中。 |
…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).
- Version sync across all six points (Version.cmake, CMakeLists.txt, conanfile.py, frontends package.json x2, openapi.yaml, pyproject.toml). - LICENSE: GNU Affero General Public License v3.0 for this and future versions; v1.0.0 remains MIT. Open-core: enterprise features ship in a separate commercial distribution. - CLA.md framework added (individual + entity terms, dual-license grant). - CHANGELOG: v1.0.1 section with the consent/bootstrap/password-policy security fixes from PR #141 and the license-change statement. - README x2 badges/footer, website footer, pyproject license field updated. - .gitignore: deliverables/ local ignore.
- Version sync across all six points (Version.cmake, CMakeLists.txt, conanfile.py, frontends package.json x2, openapi.yaml, pyproject.toml). - LICENSE: GNU Affero General Public License v3.0 for this and future versions; v1.0.0 remains MIT. Open-core: enterprise features ship in a separate commercial distribution. - CLA.md framework added (individual + entity terms, dual-license grant). - CHANGELOG: v1.0.1 section with the consent/bootstrap/password-policy security fixes from PR #141 and the license-change statement. - README x2 badges/footer, website footer, pyproject license field updated. - .gitignore: deliverables/ local ignore.
… 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.
背景
IAM Core 加固计划首批(M2.1 + M1.3):先修最高 severity 的协议缺口。实施于独立 worktree(
../authforge-hardening),方案与计划经双子代理深度评审(抓到 2 个阻断级事实错误:authorize 下发的 user_id 是 internal id 而非 public sub;deny 分支 validateClient 空 secret 会误杀 CONFIDENTIAL 客户端)后修订落地。1. consent 认证四道门(F1,Critical)
现状(代码核实):
POST /oauth2/consent路由无 filter、handler 信任表单 user_id——知道 user_id 的匿名请求可代批/代拒授权;deny 分支 302 到未校验的 redirect_uri(开放重定向)。修复(全部 fail-closed,在 plugin 调用前):
AUTH_SESSION_REQUIRED(新码 4007)——OIDC Core §3.1.2.1;AUTHZ_ACCESS_DENIED;validateRedirectUri校验(与 approve 对称,修开放重定向;不调 validateClient——空 secret 会误拒 CONFIDENTIAL 客户端,评审抓到的坑)。配套:SPA ConsentPage 回传 consent_csrf;删孤儿 consent.csp;openapi consent 补 400/401/403。
2. bootstrap 管理员(#103)
首启时若无 admin 角色用户 → 创建
admin(PBKDF2-SHA256 310k,与生产哈希同格式):密码取FULLA_BOOTSTRAP_ADMIN_PASSWORD,未设则随机生成并日志打印一次。幂等(角色存在性检测 + 用户名唯一约束);dev seed 使其在 dev/test/bench 全部 no-op;空库 + auto-migrate 竞态以延迟探测软失败、下次重启重试。3. 密码策略 + 遗留哈希门(#103)
/api/register补服务端最小长度(auth.min_password_length,默认 8);改密/重置既有 8 位硬编码统一读同一配置;短密码新码VALIDATION_PASSWORD_TOO_SHORT(3014,替换 VALIDATION_FORMAT_ERROR)。auth.allow_legacy_hash(默认 true=迁移窗口;rehash-on-login 既有,评审核实)——确认全量迁移后可关。4. 已知限制与登记项(评审发现,本批不修)
oauth2_subject_mappings行 → 走 authorize→consent 会 500(存量 bug,与四门正交);测试证据
ConsentAuthGateHttpTest(进程内真实 HTTP):无会话 401 / 错 user 403 / 缺 nonce 400 / deny 未注册 URI / authorize 造 nonce → approve 302 带 code → nonce 重放 400;openapi / SDK / 文档 / 版本