Skip to content

sec(auth): stop leaking MFA enrollment via login error responses (closes #388)#886

Open
cristim wants to merge 1 commit into
feat/multicloud-web-frontendfrom
fix/388-wave21
Open

sec(auth): stop leaking MFA enrollment via login error responses (closes #388)#886
cristim wants to merge 1 commit into
feat/multicloud-web-frontendfrom
fix/388-wave21

Conversation

@cristim
Copy link
Copy Markdown
Member

@cristim cristim commented May 30, 2026

Summary

  • Add ErrMFANotConfigured sentinel to internal/auth/errors.go and wrap it in verifyPasswordAndMFA. Map it to "mfa_required" in the login handler (same as ErrMFARequired) so an attacker cannot distinguish "MFA enrolled and working" from "MFA enrolled but secret missing" via the 401 response.
  • Replace the bare err.Error() fallthrough in the login handler with a fixed "invalid credentials" string so no internal error message ever reaches the client.
  • Coordinates with PR refactor(auth/mfa): use sentinel errors in mapMFAServiceError #883 (sentinel errors for MFA management operations): ErrMFANotConfigured message string is identical to the pre-sentinel literal, so mapMFAServiceError's substring fallback still fires correctly until refactor(auth/mfa): use sentinel errors in mapMFAServiceError #883 lands.

Test plan

  • TestLogin_FailedAuth_ResponseEquivalence positively asserts that wrong-password for a no-MFA user and wrong-password for an MFA-enrolled user both return HTTP 401 + "invalid credentials" -- identical bodies.
  • TestLogin_MFANotConfigured_ReturnsMFARequired asserts ErrMFANotConfigured produces 401 + "mfa_required", not the internal error string.
  • TestLogin_MFARequired_And_NotConfigured_ProduceSameResponse cross-checks ErrMFARequired and ErrMFANotConfigured produce the exact same status code and response body.
  • TestLogin_WithMFA_NoSecret (auth package) updated to use errors.Is(err, ErrMFANotConfigured) -- a stronger assertion than Contains.
  • Full suite: go test ./internal/auth/... ./internal/api/... -- 1857 tests pass.

 #388)

The login handler previously forwarded err.Error() verbatim for any
auth failure not matching ErrMFARequired or ErrInvalidMFACode. This
included "MFA is enabled but not configured", which revealed to an
attacker that credentials were correct and MFA was enrolled (but
broken). Two attack vectors were closed:

1. Add ErrMFANotConfigured sentinel to internal/auth/errors.go and
   return it (wrapped via %w) from verifyPasswordAndMFA. Map it to
   "mfa_required" in the login handler -- identical to ErrMFARequired
   -- so "MFA enrolled + working" is indistinguishable from "MFA
   enrolled + broken secret" in the HTTP response.

2. Replace the bare err.Error() fallthrough in the login handler with
   a fixed "invalid credentials" string so no internal error message
   ever reaches the client.

Tests positively assert response equivalence: ErrMFARequired and
ErrMFANotConfigured produce the same 401 + "mfa_required" body; all
wrong-password paths produce the same 401 + "invalid credentials" body.
@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy urgency/this-quarter Within the quarter impact/few Limited audience effort/m Days type/security Security finding labels May 30, 2026
@cristim
Copy link
Copy Markdown
Member Author

cristim commented May 30, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 41ae072b-ce99-478a-a8c8-2882aeae1ea6

📥 Commits

Reviewing files that changed from the base of the PR and between 4956d66 and 904fe51.

📒 Files selected for processing (5)
  • internal/api/handler_auth.go
  • internal/api/handler_auth_test.go
  • internal/auth/errors.go
  • internal/auth/service.go
  • internal/auth/service_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/388-wave21

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/few Limited audience priority/p2 Backlog-worthy triaged Item has been triaged type/security Security finding urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant