Skip to content

Fix: Don't tell clients to re-authorise when we failed to validate - #412

Merged
rafaeljusto merged 1 commit into
mainfrom
fix/auth
Jul 29, 2026
Merged

Fix: Don't tell clients to re-authorise when we failed to validate#412
rafaeljusto merged 1 commit into
mainfrom
fix/auth

Conversation

@rafaeljusto

Copy link
Copy Markdown
Contributor

Description

GetBearerInfo collapsed every non-200 from /launchpad/v1/userinfo.json into ErrBearerInfoUnauthorized, so a 500 or 502 was indistinguishable from a rejected token. The middleware turned that into 401 plus WWW-Authenticate, which per RFC 9728 tells the client to discard its token — costing a full re-authorisation, and an MFA prompt where MFA is enabled, over what may have been a momentary upstream failure.

Now split three ways: ErrBearerInfoUnauthorized (401/403 only, still challenges), ErrBearerInfoUnavailable (503, no challenge), ErrBearerInfoCanceled (our request context died because the client hung up — logged at debug, no response written). That last case accounts for the overwhelming majority of these errors in practice: clients closing their stream on GET /, previously reported as server errors of ours.

classifyAuthStatus isolates the status decision; the sweep over 100-599 asserts nothing outside 401/403 can read as a rejection.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

  • Tests pass locally (go test -v ./...)
  • Added/updated tests for new functionality

Checklist

  • Code follows project style guidelines
  • Self-reviewed the code
  • Added necessary documentation
  • No new warnings or errors

`GetBearerInfo` collapsed every non-200 from `/launchpad/v1/userinfo.json`
into `ErrBearerInfoUnauthorized`, so a 500 or 502 was indistinguishable from
a rejected token. The middleware turned that into 401 plus
`WWW-Authenticate`, which per RFC 9728 tells the client to discard its token
— costing a full re-authorisation, and an MFA prompt where MFA is enabled,
over what may have been a momentary upstream failure.

Now split three ways: `ErrBearerInfoUnauthorized` (401/403 only, still
challenges), `ErrBearerInfoUnavailable` (503, no challenge),
`ErrBearerInfoCanceled` (our request context died because the client hung up
— logged at debug, no response written). That last case accounts for the
overwhelming majority of these errors in practice: clients closing their
stream on `GET /`, previously reported as server errors of ours.

`classifyAuthStatus` isolates the status decision; the sweep over 100-599
asserts nothing outside 401/403 can read as a rejection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@rafaeljusto
rafaeljusto requested a review from a team as a code owner July 28, 2026 20:09
@rafaeljusto
rafaeljusto merged commit 5700918 into main Jul 29, 2026
3 checks passed
@rafaeljusto
rafaeljusto deleted the fix/auth branch July 29, 2026 11:19
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.

2 participants