Skip to content

fix(token): use safe type assertions for JWT claims [H2]#551

Merged
lakhansamani merged 1 commit intomainfrom
fix/h2-safe-type-assertions
Apr 4, 2026
Merged

fix(token): use safe type assertions for JWT claims [H2]#551
lakhansamani merged 1 commit intomainfrom
fix/h2-safe-type-assertions

Conversation

@lakhansamani
Copy link
Copy Markdown
Contributor

Summary

  • H2 (High): Unguarded type assertions on JWT claims caused panics on malformed tokens
  • Replaced with comma-ok pattern in 3 functions: ValidateAccessToken, ValidateRefreshToken, GetUserIDFromSessionOrAccessToken
  • Missing sub claim now returns error instead of panic

Test plan

  • Package compiles
  • Verify normal token validation still works
  • Verify tokens with missing claims return error (not panic)

Unguarded type assertions like claims["sub"].(string) panic if the
claim is missing or the wrong type. An attacker could craft a valid-
signature token with missing claims to crash the server.

Replaced with comma-ok pattern in ValidateAccessToken,
ValidateRefreshToken, and GetUserIDFromSessionOrAccessToken.

Fixes: H2 (High)
@lakhansamani lakhansamani merged commit b65433c into main Apr 4, 2026
@lakhansamani lakhansamani deleted the fix/h2-safe-type-assertions branch April 4, 2026 05:44
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