Repository navigation
Raise JWT::JWKError for EC JWK coordinates not on the curve - #789
Merged
Merged
Conversation
create_point let OpenSSL::PKey::EC::Point::Error escape when a JWK's x/y coordinates were not a valid point on the curve named in crv, for example a P-256 key labelled P-384. That error is not a JWT::Error, so callers rescuing JWT errors around JWKS-based decoding did not catch it. Re-raise it as JWT::JWKError, keeping the OpenSSL error as the cause. Fixes jwt#788
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the EC JWK error-handling change.
No open issues 🎉
What changed in this PR
Addresses #788 by making malformed EC JWK coordinates raise JWT::JWKError, allowing callers to handle these failures through the library’s error hierarchy.
Changes:
- Wraps OpenSSL point errors while preserving the original exception as the cause.
- Adds regression tests for mismatched curves and off-curve points through direct key use and JWKS-based decoding.
- Documents the fix in the changelog.
| File | Description |
|---|---|
spec/jwt/jwk/ec_spec.rb |
Tests malformed EC coordinates and error propagation. |
lib/jwt/jwk/ec.rb |
Converts OpenSSL point errors to JWT::JWKError. |
CHANGELOG.md |
Records the error-handling fix and PR reference. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #788.
When an EC JWK's
x/ycoordinates aren't a valid point on the curve named incrv, for example a P-256 key labelledP-384or an off-curve point,JWT::JWK::EC#create_pointletOpenSSL::PKey::EC::Point::Errorescape fromverify_key,private?,exportand JWKS-basedJWT.decode. That error isn't aJWT::Error, so a malformed key in a remote JWKS surfaced as an OpenSSL exception in application code.create_pointnow rescues it and raisesJWT::JWKError, "Invalid EC point for curve <crv>". Ruby keeps the original OpenSSL error ascause. This matches how other invalid JWK input is already handled: an unknowncrvraisesJWT::JWKError, and invalid base64 raisesJWT::Base64DecodeError.The specs cover a mismatched curve and an off-curve point, both when using the key directly and when decoding with
jwks:. Without the fix, the 4 new examples fail.Out of scope: a private JWK whose
ddoesn't belong to itsx/yis still accepted without an error. That's a separate consistency check, and I can file it as its own issue.Checklist
Before the PR can be merged be sure the following are checked:
Posted by Claude on behalf of @anakinj.