Skip to content

sec(api/auth): return opaque 401 in login catch-all instead of err.Error() (closes #937)#938

Merged
cristim merged 1 commit into
feat/multicloud-web-frontendfrom
sec/937-login-opaque-401
Jun 3, 2026
Merged

sec(api/auth): return opaque 401 in login catch-all instead of err.Error() (closes #937)#938
cristim merged 1 commit into
feat/multicloud-web-frontendfrom
sec/937-login-opaque-401

Conversation

@cristim

@cristim cristim commented Jun 3, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #937. Salvaged from closed #886.

  • The login() catch-all error path was forwarding raw service errors verbatim via NewClientError(401, err.Error()), potentially exposing internal account state (lock status, user IDs, timestamps) to unauthenticated callers.
  • Replaced with the opaque hardcoded string "invalid credentials" so all non-sentinel auth failures (wrong password, account not found, locked, etc.) collapse to the same opaque 401 response.
  • The typed-sentinel arms above (ErrMFARequired -> "mfa_required", ErrInvalidMFACode -> "invalid_mfa_code") are unchanged.

Test plan

  • TestHandler_login_OpaqueError_HidesInternalMessage (new): service returns "internal: user 42 locked since ...", response body is exactly "invalid credentials", no internal substring present.
  • TestHandler_login_AuthError (existing): still passes - opaque message "invalid credentials" satisfies the existing Contains assertion.
  • All other TestHandler_login_* tests unchanged and passing.
  • go test ./internal/api/... -count=1 passes (1404 tests).
  • gofmt -l and go vet ./internal/api/... clean.

…ror() (closes #937)

The login() catch-all error path was forwarding raw service errors verbatim
via NewClientError(401, err.Error()), potentially exposing internal account
state (e.g. lock status, user IDs, timestamps) to unauthenticated callers.

Replace it with the opaque hardcoded string "invalid credentials" so all
non-sentinel auth failures (wrong password, account not found, locked, etc.)
collapse to the same response, regardless of what the service returns.

The typed-sentinel arms above (ErrMFARequired -> "mfa_required",
ErrInvalidMFACode -> "invalid_mfa_code") are unchanged.

Adds TestHandler_login_OpaqueError_HidesInternalMessage as a regression test
that pins the service returning a distinctive internal message and asserts
the 401 body is "invalid credentials" with no internal detail leaking through.

Salvaged from closed #886.
@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/this-quarter Within the quarter impact/few Limited audience effort/xs Trivial / one-liner type/security Security finding labels Jun 3, 2026
@cristim

cristim commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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 34 minutes and 53 seconds. 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: 8d64b5dc-dadf-46b6-82fa-9be0e60a911e

📥 Commits

Reviewing files that changed from the base of the PR and between c00445c and 098f230.

📒 Files selected for processing (2)
  • internal/api/handler_auth.go
  • internal/api/handler_auth_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sec/937-login-opaque-401

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

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

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.

@cristim cristim merged commit 623758c into feat/multicloud-web-frontend Jun 3, 2026
4 checks passed
@cristim cristim deleted the sec/937-login-opaque-401 branch June 3, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/few Limited audience priority/p3 Polish / idea / may never ship severity/low Minor harm 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