Fix EC JWKS authentication support#6106
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6106 +/- ##
==========================================
- Coverage 75.00% 74.99% -0.02%
==========================================
Files 452 452
Lines 29106 29111 +5
Branches 4382 4384 +2
==========================================
Hits 21832 21832
- Misses 5251 5252 +1
- Partials 2023 2027 +4
🚀 New features to boost your workflow:
|
|
@wheresNasha Can you please fix the Code Hygiene errors? Run |
| if (key.getClass() == OctetSequenceKey.class) { | ||
| if (key instanceof OctetSequenceKey) { | ||
| result = new DefaultJWSVerifierFactory().createJWSVerifier(jwt.getHeader(), key.toOctetSequenceKey().toSecretKey()); | ||
| } else if (key instanceof RSAKey) { |
There was a problem hiding this comment.
Can we write tests to hit all of these branches?
There was a problem hiding this comment.
I have already addded test coverage for the missing EC (ECKey) branch here.
I also looked into adding OCT (OctetSequenceKey) coverage, but the current JWKS authentication flow does not appear to successfully authenticate symmetric OCT keys in the existing test infrastructure (extractCredentials() returns null), so that test is currently failing.
RSA coverage is already present, so this PR focuses on covering the missing EC path.
There was a problem hiding this comment.
Would you mind filing an issue for missing OctetSequenceKey support in test setup. We can track and merge as a separate issue.
There was a problem hiding this comment.
Hello @DarshitChanpura ,
I have filled the issue: #6155
| .createJWSVerifier(jwt.getHeader(), key.toECKey().toECPublicKey()); | ||
| } else { | ||
| result = new DefaultJWSVerifierFactory().createJWSVerifier(jwt.getHeader(), key.toRSAKey().toRSAPublicKey()); | ||
| throw new IllegalArgumentException("Unsupported JWK key type: " + key.getClass()); |
There was a problem hiding this comment.
Not sure if it makes sense but should we keep the fallback logic in place?
Any idea what the entire universe of key types can be?
There was a problem hiding this comment.
I leaned toward explicit key type handling here since failing closed felt safer than broadly falling back and potentially masking unsupported JWK types.
From what I understand, Nimbus JWK currently supports symmetric (oct), RSA, EC, and additional types like OKP.
If preserving backward compatibility with prior RSA fallback makes more sense here, I’m happy to adjust it.
cbae25a to
4143730
Compare
PR Reviewer Guide 🔍(Review updated until commit 4f6202d)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 4f6202d Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit dfc12e9
Suggestions up to commit 5a130c0
Suggestions up to commit 4143730
|
|
@cwperks Thanks for the helpful guidance! Please let me know your thoughts, and if everything looks good from your side, I can rebase the branch. |
|
Persistent review updated to latest commit 5a130c0 |
|
Persistent review updated to latest commit dfc12e9 |
DarshitChanpura
left a comment
There was a problem hiding this comment.
thank you for adding this @wheresNasha ! Left a couple of comments. LGTM otherwise.
| } | ||
|
|
||
| @Test | ||
| public void testJwksAuthenticationWithEC() throws Exception { |
There was a problem hiding this comment.
can we add a unhappy path test here as well?
There was a problem hiding this comment.
Thanks for the review! I’ve added the unhappy path EC test and also fixed the formatting issues using spotlessApply.
I’ve now rebased the branch on latest main as well.
Can we merge this change please
Thanks!
| if (key.getClass() == OctetSequenceKey.class) { | ||
| if (key instanceof OctetSequenceKey) { | ||
| result = new DefaultJWSVerifierFactory().createJWSVerifier(jwt.getHeader(), key.toOctetSequenceKey().toSecretKey()); | ||
| } else if (key instanceof RSAKey) { |
There was a problem hiding this comment.
Would you mind filing an issue for missing OctetSequenceKey support in test setup. We can track and merge as a separate issue.
Signed-off-by: Sakshi Nasha <sakshinasha11@gmail.com>
Signed-off-by: Sakshi Nasha <sakshinasha11@gmail.com>
dfc12e9 to
4f6202d
Compare
|
Persistent review updated to latest commit 4f6202d |
Description
This PR fixes EC-based JWKS authentication support as part of issue #6045.
EC-based JWT verification using JWKS was not handled correctly, leading to authentication failures for EC-signed tokens.
Old behavior:
EC-signed JWTs using JWKS could fail validation due to missing or incorrect key handling.
New behavior:
EC JWKS keys are now properly parsed and used for JWT verification, enabling successful authentication for EC-signed tokens.
Issues Resolved
Fixes #6045
Is this a backport? If so, please add backport PR # and/or commits #, and remove
backport-failedlabel from the original PR.Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end? If so, please open a draft PR in the security dashboards plugin and link the draft PR here
Testing
Validated locally using EC-signed JWTs with JWKS
Tested token verification flow end-to-end
Confirmed backward compatibility with existing RSA-based flows
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.