sec(api/auth): return opaque 401 in login catch-all instead of err.Error() (closes #937)#938
Conversation
…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.
|
@coderabbitai review |
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
✅ Action performedReview finished.
|
Summary
Fixes #937. Salvaged from closed #886.
login()catch-all error path was forwarding raw service errors verbatim viaNewClientError(401, err.Error()), potentially exposing internal account state (lock status, user IDs, timestamps) to unauthenticated callers."invalid credentials"so all non-sentinel auth failures (wrong password, account not found, locked, etc.) collapse to the same opaque 401 response.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 existingContainsassertion.TestHandler_login_*tests unchanged and passing.go test ./internal/api/... -count=1passes (1404 tests).gofmt -landgo vet ./internal/api/...clean.