Skip to content

fix(security): harden MFA TOTP replay/rate-limit (P2-4a), SSRF, HTTP timeout, and password-reset session revocation - #400

Merged
voidvec merged 2 commits into
masterfrom
fix/core-security-concurrency-hardening
Dec 2, 2026
Merged

voidvec merged 2 commits into
masterfrom
fix/core-security-concurrency-hardening

Conversation

@voidvec

@voidvec voidvec commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • MFA / TOTP (P0):
    • Add constant-time TotpUtils::verifyCodeWithStep and enforce RFC 6238 §5.2 single-use monotonic step tracking under mutex in MfaService::verifyLoginCode and verifyAndEnable (blocks 90s-window and concurrent TOTP replay).
    • Wire P2-4a async IFailureRateLimiter into MfaController::verifyLogin (injected from IdentityAssembly with process-local fallback) to block TOTP/backup-code brute force with 429 + Retry-After.
  • SSRF & Outbound HTTP Hardening (P1):
    • Harden RuleSet::validateBackchannelLogoutUri against IPv6/IPv4-mapped/hex/decimal/CGNAT/multicast/*.localhost/*.local/zone-id bypass forms.
    • Add explicit 10s outbound timeout and CT_APPLICATION_X_FORM in DrogonOAuthHttpClient.
  • Password Reset Session Revocation (P1, P2-4b compatible):
    • Wire ISessionStore into PasswordResetController / PasswordResetService to revoke all tracked browser sessions and clear current session on confirmReset.
  • Tests:
    • Add MfaServiceTest replay/concurrency GTests and CoreSecurityConcurrencyHardeningTest integration tests.
    • Update PasswordLoginSessionStateHttpTest to use a distinct TOTP step / backup code after MFA enrollment under RFC 6238 replay protection.

Verification

  • .\manage.ps1 build-backend (Windows MSVC Release): PASS
  • MfaServiceTest + TotpUtilsTest (43/43) & CoreSecurityConcurrencyHardeningTest (3/3): PASS
  • ctest -C Release (config.ci.json): 767/768 passed (only Health Live/Ready 503 due to local Redis stopped)
  • Local gates (api_diff.py, check_spec_governance.py, migration_check.py, naming_validator.sh): PASS

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T10:04:44.502833Z 404d93a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 404d93a964

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +317 to +318
store->revokeAllForUser(
std::to_string(userId),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Revoke browser sessions using the public subject

When a user resets their password, this passes the internal numeric user ID to ISessionStore::revokeAllForUser, but that API expects the public subject. Both MemorySessionStore and RedisSessionStore index sessions by publicSub, so this lookup revokes zero sessions while returning success. Other browsers, including one holding a stolen cookie, therefore retain their authenticated sessions despite the response claiming that all sessions were revoked. Capture and pass the publicSub already available in the enclosing callback instead.

Useful? React with 👍 / 👎.

voidvec and others added 2 commits December 2, 2026 12:35
…timeout, and password-reset session revocation

- MFA / TOTP (P0):
  - Add constant-time TotpUtils::verifyCodeWithStep (avoids timeStep==0 underflow) and enforce RFC 6238 section 5.2 single-use monotonic step tracking under mutex in MfaService::verifyLoginCode and verifyAndEnable (prevents 90s-window and concurrent TOTP replay).
  - Wire P2-4a async IFailureRateLimiter into MfaController::verifyLogin (injected from IdentityAssembly for Redis multi-replica parity, with process-local RateLimiter fallback) to block 6-digit TOTP/backup-code brute force with 429 + Retry-After.
- SSRF & outbound HTTP hardening (P1):
  - Upgrade RuleSet::validateBackchannelLogoutUri to full 8-hextet IPv6 + IPv4-mapped/compatible hex/dotted-quad + single-label decimal/hex IP + CGNAT/multicast + *.localhost/*.local + zone-id stripping.
  - Add explicit 10s outbound timeout and CT_APPLICATION_X_FORM in DrogonOAuthHttpClient.
- Password reset session revocation (P1, P2-4b compatible):
  - Wire ISessionStore into PasswordResetController/PasswordResetService (from IdentityAssembly) and revoke all tracked browser sessions + clear current session on confirmReset (propagates cleanly through P2-4b RedisSessionStateBridge).
- Tests:
  - Add 3 Domain GTests in MfaServiceTest (same-step replay, 8-thread concurrent race, setup replay/disable reset).
  - Add 3 integration tests in CoreSecurityConcurrencyHardeningTest (SSRF bypass vectors, sync RateLimiter 429, and P2-4a async IFailureRateLimiter 429).
  - Update PasswordLoginSessionStateHttpTest to use distinct TOTP step / backup code after MFA enrollment under RFC 6238 replay protection.
@voidvec
voidvec force-pushed the fix/core-security-concurrency-hardening branch from 404d93a to 463544d Compare December 2, 2026 13:56
@voidvec
voidvec merged commit 31419b8 into master Dec 2, 2026
16 checks passed
@voidvec
voidvec deleted the fix/core-security-concurrency-hardening branch December 2, 2026 15:01
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.

1 participant