Skip to content

Return 401 on Malformed JWTs#7633

Merged
achamayou merged 5 commits intomainfrom
fix_7631
Feb 2, 2026
Merged

Return 401 on Malformed JWTs#7633
achamayou merged 5 commits intomainfrom
fix_7631

Conversation

@achamayou
Copy link
Member

@achamayou achamayou commented Jan 30, 2026

Closes #7631 - @ivarprudnikov can you have a look please?

Copilot AI review requested due to automatic review settings January 30, 2026 15:22
@achamayou achamayou requested a review from a team as a code owner January 30, 2026 15:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses issue #7631 by improving error handling for malformed JWT tokens. Previously, when a JWT token contained invalid base64url encoding, the system would return a 500 Internal Server Error with an obscure OpenSSL error message. With these changes, the system now returns a 401 Unauthorized response with clearer, user-friendly error messages.

Changes:

  • Added error handling for base64url decoding failures in JWT parsing with specific error messages for each component (header, payload, signature)
  • Added comprehensive test coverage for various malformed JWT token formats
  • Test validates that all malformed tokens return 401 status codes with appropriate error messages

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/http/http_jwt.h Introduced parse_jwt_b64url helper function to catch base64url decoding exceptions and convert them to 401 errors with clear error messages
tests/jwt_test.py Added test_malformed_tokens function to verify malformed JWTs return 401 with correct error messages, including test cases for wrong number of parts and invalid base64url in each component

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@achamayou achamayou enabled auto-merge (squash) January 30, 2026 16:02
@achamayou achamayou merged commit 7853f2a into main Feb 2, 2026
17 checks passed
@achamayou achamayou deleted the fix_7631 branch February 2, 2026 22:49
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.

Incorrectly encoded auth token yields 500 decoder error to the end user

3 participants