-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
JWT with JSON body seen as plaintext JWT #687
Comments
Hi Maxime! Out of curiosity, what made you believe That said, I'm not sure that Compact JWT bodies can represent both plaintext as well as JSON, so we have to use heuristics (the line you quoted) to do our best to try and figure out if it might be JSON or not. Based on this issue, we need to update our code to ignore any whitespace before or after the first and last And while we need to do that, I do have to say: The entire point of compact JWTs is to save space: whatever library that produced your JWT should not be using whitespace anywhere in the JSON structure (other than in JSON member names and values themselves as necessary) - it should be as flat and minimal as possible with no extra whitespace anywhere as that only defeats the purpose of the notion of 'compact'. Could you reach out to whoever produced that JWT to see if they can fix it on their end as well? |
Hi @lhazlewood, I just found out that a JWT body created by JJWT (+compact) will have a leading whitespace character ( // Edit: It was JSON-B on OpenLiberty. They need an extra "sstrip()" call. |
This issue has been automatically marked as stale due to inactivity for 60 or more days. It will be closed in 7 days if no further activity occurs. |
This was resolved via 760c542 by jjwt/impl/src/main/java/io/jsonwebtoken/impl/DefaultJwtParser.java Lines 509 to 517 in a6792d9
and https://github.com/jwtk/jjwt/blob/a6792d938fd89b96fb38d22268962cfb8e742552/impl/src/main/java/io/jsonwebtoken/impl/DefaultJwtParser.java#L230C11-L230C11 |
Hi,
We are facing a this behavior when using the latest release of jjwt (
0.9.1
):When parsing the claims of a token that has a JSON body using
Jwts.parser().[...].parseClaimsJws(token)
, the token is seen as a plaintext JWT. Here is what the token contains:Header:
Payload
Apparently, the token payload contains an extra \r\n at the end, which makes it interpreted as a plaintext jwt, see this line:
jjwt/impl/src/main/java/io/jsonwebtoken/impl/DefaultJwtParser.java
Line 333 in 3e6c9e9
Is it a normal behavior ? Should the JWT be seen as plaintext when it doesn't end exactly with } ?
Thank you !
The text was updated successfully, but these errors were encountered: