You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix NPE parsing an EC JWK with a missing x or y coordinate - #52297
JWKParser#createECPublicKey read the x/y fields with get() (which returns null for a missing key) instead of path() (a non-null MissingNode, as crv and the RSA path already use). So a JWK missing a coordinate threw NullPointerException before the null-guard - which explicitly lists crv, x and y as nullable - could run.
Read x/y with path() too, so a malformed externally-supplied EC JWK fails with the intended Fail to retrieve ... message instead of an NPE.
Added JWKTest#toPublicKeyEcMissingCoordinate, verified in the crypto modules (DefaultCryptoJWKTest) fails-before / passes-after.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Fixes a NullPointerException when parsing malformed EC JWKs missing x or y by retrieving coordinates via path() (returning a non-null MissingNode) rather than get() (returning null), and adds a regression test to ensure the error is surfaced as the intended “Fail to retrieve …” message.
Changes:
Switch EC JWK coordinate retrieval from get() to path() in JWKParser#createECPublicKey.
Add a regression test ensuring missing EC coordinates fail with a descriptive error (not an NPE).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
The regression test only omits x, so it would still pass if this y lookup remained get(...); the missing-y half of the reported failure is therefore uncovered. Please exercise both omitted-coordinate cases (for example, with a small loop or parameterized test).
@mposolda Thanks for the follow-up commit. I've addressed the remaining review points and squashed everything into a single commit:
Missing y is now covered. The test exercises both a missing x and a missing y. Previously only x was omitted, so the test still passed if the y lookup stayed on get(). I verified it now fails with the NPE in that case.
assertThrows instead of try/catch. The test asserts the thrown exception is not a NullPointerException and checks the exact message, Fail to retrieve ECPublicJWK.CRV, ECPublicJWK.X or ECPublicJWK.Y field.
This replaces the message.toLowerCase().contains("x") check from the autofix commit, which always passed because the message itself contains ECPublicJWK.X.
DefaultCryptoJWKTest and ElytronCryptoJWKTest pass.
If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.
java.lang.RuntimeException: Could not create statement
at org.jboss.arquillian.junit.Arquillian.methodBlock(Arquillian.java:307)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:160)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:344)
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:48)
...
JWKParser.createECPublicKey read the "crv" field with path() (which
returns a non-null MissingNode) but read "x" and "y" with get() (which
returns null for an absent key). The subsequent guard explicitly treats
crv, x and y as nullable and throws a descriptive RuntimeException, but
for a missing x or y it was never reached: get(...) returned null and
.asText(null) dereferenced it, throwing NullPointerException instead.
Read x and y with path() as well, mirroring crv and the RSA path in
createRSAPublicKey, so a malformed externally-supplied EC JWK fails with
the intended "Fail to retrieve ..." message rather than an NPE.
Add a regression test covering both a missing x and a missing y
coordinate, asserting the descriptive error is thrown rather than a
NullPointerException.
Closeskeycloak#52294
Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
Rebased onto latest main to re-trigger CI. The previous failures were unrelated to this change: Maven could not resolve tools.jackson:jackson-bom:pom:3.2.4 while processing the POMs.
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
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.
Closes #52294
JWKParser#createECPublicKeyread thex/yfields withget()(which returnsnullfor a missing key) instead ofpath()(a non-nullMissingNode, ascrvand the RSA path already use). So a JWK missing a coordinate threwNullPointerExceptionbefore the null-guard - which explicitly listscrv,xandyas nullable - could run.Read
x/ywithpath()too, so a malformed externally-supplied EC JWK fails with the intendedFail to retrieve ...message instead of an NPE.Added
JWKTest#toPublicKeyEcMissingCoordinate, verified in the crypto modules (DefaultCryptoJWKTest) fails-before / passes-after.