Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultJwtParser ignores custom base64 parser it was built with in a scenario #947

Closed
mbomeara opened this issue Jun 16, 2024 · 2 comments
Closed
Milestone

Comments

@mbomeara
Copy link

mbomeara commented Jun 16, 2024

In cases where a JwtParser is built using b64Url() to provide a custom base64 decoder, the expectation is that all base64 decoding will use the custom decoder:

Jwts.parser()
    .verifyWith(publicKey)
    .b64Url(decoder) // expect this decoder to be used for all base64 operations of parseSignedClaims()
    .build()
    .parseSignedClaims(jwt);

However due to

jwt = new DefaultJws<>(jwsHeader, body, base64UrlDigest.toString());
a new DefaultJws is constructed. The constructor for DefaultJws is hard-coded to use its own base64 decoder (namely Decoders.BASE64URL):

super(header, payload, Decoders.BASE64URL.decode(signature), DIGEST_NAME);

This violates the expectation that the custom base64 decoder will be used for all decoding. This behavior has changed somewhere between 0.11.5 and 0.12.5 which in turn breaks our application if we update our jjwt dependency version to the latest.

@lhazlewood
Copy link
Contributor

Thanks for creating the issue!

While I agree we should correct this, it's not clear to me how this could 'break' an application.

The only thing the DefaultJws constructor does is take a Base64URL string and decodes it to a raw digest byte array so that array is then available via jws.getDigest(). And that DefaultJws instance is only returned from the parser if the signature is verified successfully first.

So as long as the signature string is actually Base64URL, JJWT's default decoder will accurately obtain the digest byte array, even if your specified Decoder isn't used.

So yes, we should change the implementation to decode using the specified Decoder, but I don't see how this could cause something to break in the application. Could you please explain how this occurs? Thanks!

@lhazlewood lhazlewood added this to the 0.12.6 milestone Jun 16, 2024
lhazlewood added a commit that referenced this issue Jun 16, 2024
@lhazlewood
Copy link
Contributor

@mbomeara please see #948

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

No branches or pull requests

2 participants