Skip to content

Auth: answer 401 with a sanitized message when /auth/refresh rejects an expired or rotated refresh credential #31346

Closed

Description

@siddhant1

Affected module

Backend

Describe the bug

When the stored refresh credential is expired or has been rotated away, POST/GET /api/v1/auth/refresh answers HTTP 500 on the Basic, LDAP and confidential-OIDC paths (catch (Exception e) → SC_INTERNAL_SERVER_ERROR). The SAML path already answers 401 for the expiry case.

Two problems with the 500:

  1. Wrong semantics — the server is rejecting the caller's credentials, which is a 401. Any API client (SDKs, scripts, reverse proxies with retry-on-5xx policies) reads the 500 as a transient server fault and retries a request that can never succeed. Server-side, a routine credential expiry lands in error logs/alerting as if the service were failing.
  2. Token leak — the 500 body echoes e.getMessage(), which embeds the refresh token UUID ("Expired token. Please login again : <uuid>").

After #31103, the UI signs out on any failed refresh, so the browser UX is not affected — this is about correct HTTP semantics for the endpoint itself and keeping credentials out of response bodies.

Expected behavior

  • Expired refresh token (CustomExceptionMessage, 400), rotated-away/unknown token (EntityNotFoundException, 404), empty token (BadRequestException) → 401 with a fixed, sanitized message.
  • Genuine server faults (JWT signing failure, DB unavailable) → 500, unchanged — a backend outage must never read as "your session is invalid".
  • Full exception detail (including the UUID) stays in server logs.

Verified reproduction

On a live stack: log in (basic auth), UPDATE user_tokens SET json = JSON_SET(json,'$.expiryDate',1000), call /api/v1/auth/refresh with the session cookie → 500 with the token UUID in the body. With a stopped DB the same call also answers 500 — the two cases are indistinguishable to clients today.

Activity

  1. added theissue type on Aug 26, 2026
  2. added
    bug
    on Aug 26, 2026
  3. added this to Shipping and removed this from Roadmapon Aug 26, 2026
  4. moved this to Release Backlog 🚧 in Shippingon Aug 26, 2026
  5. moved this from Release Backlog 🚧 to In Progress 🏗️ in Shippingon Oct 9, 2026
  6. moved this from In Progress 🏗️ to Done ✅ in Shippingon Oct 9, 2026
  7. added a commit that references this issue on Oct 9, 2026
    2444b4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

backendbug

Type

Projects

  • Status
    Done ✅

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions