question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[JWT] MaximumTokenSizeInBytes usage is surprising

See original GitHub issue

I have a well-formed JWS : [base64url-encoded header].[base64url-encoded payload].[base64url-encoded signature]. This token is about 1.7MB in its compact serialization form. When I try to validate this token, I have an error IDX12709 saying that my token is malformed and should a JWE or a JWE… The error message is not very useful. When I look at the source code, I see many usage of the same error message :

  • The token has 2 ‘.’ but does not match the JWS regex
  • The token has 4 ‘.’ but does not match the JWE regex
  • The token has something else than 2 or 4 ‘.’
  • The token cannot be read:
    • The token is empty
    • The token length * 2 > MaximumTokenSizeInBytes
    • Others validations already done previously

My token length is 1.7MB: token.length (1.7MB) * 2 > MaximumTokenSizeInBytes (2MB) == True

I found my problem! MaximumTokenSizeInBytes should be renamed HalfMaximumTokenSizeInBytes and the workaround is just to double this value. 🙄

This is strange because there is an error for the token too big (IDX10209) but this error is raised when token length >MaximumTokenSizeInBytes

My points are:

  • The error message is unclear
  • Two validations for the same data (token.length) with the same parameter (MaximumTokenSizeInBytes) produce two different behaviours
  • I expect that my token length can be of 2MB if I set the maximum to 2MB

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brentschmaltzcommented, May 23, 2018

@ycrumeyrolle sorry for the hassle, will fix in 5.2.3

0reactions
brentschmaltzcommented, Jun 9, 2018

@ycrumeyrolle you are correct, the time to account for doubling, is before we move the bytes into a string. When we take the bytes of the wire.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the maximum size of JWT token?
As a JWT is included in a HTTP header, we've an upper limit (SO: Maximum on http header values) of 8K on the...
Read more >
"JSON Web Token (JWT) — the only explanation you'll ...
JWTs are stateless as access tokens, refresh tokens aren't but are still not stored at the application level so they are just as...
Read more >
The Ultimate Guide to handling JWTs on frontend clients ...
JWTs (JSON Web Token, pronounced 'jot') are becoming a popular way of handling auth. This post aims to demystify what a JWT is,...
Read more >
Components of JWTs Explained
Technically, a JWT is merely a token that contains base64 encoded JSON. It can be used in many different use cases including authentication...
Read more >
JwtSecurityTokenRequirement.MaximumTokenSizeInBytes ...
Gets or sets the maximum size of a JwtSecurityToken the JwtSecurityTokenHandler will read and validate. Namespace: System.IdentityModel.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found