Skip to content

fix(server): treat expired JWT as no-auth instead of 401 - #2

Open
22f wants to merge 1 commit into
mainfrom
fix/http-jwt-expiry-deadlock
Open

fix(server): treat expired JWT as no-auth instead of 401#2
22f wants to merge 1 commit into
mainfrom
fix/http-jwt-expiry-deadlock

Conversation

@22f

@22f 22f commented Mar 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • HTTP auth middleware now treats expired Bearer tokens as equivalent to no token (anonymous session) instead of rejecting with 401
  • Fixes deadlock where clients with expired JWTs cannot call signin() or invalidate() because the middleware blocks the request before reaching the endpoint handler
  • Uses existing is_expired_token_error() helper from core::iam

Changed files

  • surrealdb/server/src/ntw/auth.rs — catch ExpiredToken in check_auth(), fall back to unauthenticated session
  • tests/http_integration.rs — new test expired_jwt_does_not_block_signin

Test plan

  • CI passes (fmt, clippy, tests)
  • New test expired_jwt_does_not_block_signin passes
  • Existing auth tests unaffected

🤖 Generated with Claude Code

When an HTTP client's Bearer JWT expires, the auth middleware rejected
ALL requests with 401 — including signin and invalidate, which are the
operations needed to recover. This created a deadlock where the client
could not obtain a fresh token without creating a brand new connection.

The fix treats an expired Bearer token as equivalent to no token,
falling back to an unauthenticated session. This lets recovery
endpoints (signin, invalidate) proceed normally while other endpoints
still enforce permissions via their handlers. WebSocket connections
were unaffected as they handle auth per-RPC-method.

Uses the existing `is_expired_token_error()` helper from core::iam.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@22f

22f commented Mar 31, 2026

Copy link
Copy Markdown
Owner Author

@claude review

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant