Skip to content

handle malformed JWT tokens gracefully with 401 instead of 502 - #32

Merged
karelyrodri merged 1 commit into
v0.1.1from
updates/authz
Jun 17, 2026
Merged

handle malformed JWT tokens gracefully with 401 instead of 502#32
karelyrodri merged 1 commit into
v0.1.1from
updates/authz

Conversation

@karelyrodri

Copy link
Copy Markdown
Collaborator

Root cause: jwt.get_unverified_header() in get_claims() threw unhandled JWTError for malformed tokens, bubbling up through the validated decorator's generic except Exception re-raise and crashing the Lambda (HTTP 502).

  • Wrap get_unverified_header() in try/except JWTError → ClaimException
  • Add dedicated except ClaimException handler in validated() returning 401
  • Poll records left to expire via TTL on auth failures

Root cause: jwt.get_unverified_header() in get_claims() threw unhandled
JWTError for malformed tokens, bubbling up through the validated decorator's
generic except Exception re-raise and crashing the Lambda (HTTP 502).

- Wrap get_unverified_header() in try/except JWTError → ClaimException
- Add dedicated except ClaimException handler in validated() returning 401
- Poll records left to expire via TTL on auth failures
@karelyrodri
karelyrodri merged commit 374e02e into v0.1.1 Jun 17, 2026
3 checks passed
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.

1 participant