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.

Invalid validation of non-present expiration JWT claims

See original GitHub issue

The validators accepts nullable notBefore and expires DateTimes but return values from JsonWebToken ValidFrom and ValidTo properties return DateTime.MinValue if the claim is not present. So in my opinion JsonWebTokenHandler fails to properly convert it to nullable values.

https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/824068adaeb7b158df2b36d8787f689646e715e0/src/Microsoft.IdentityModel.Tokens/Validators.cs#L330

https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/824068adaeb7b158df2b36d8787f689646e715e0/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebToken.cs#L303-L313

https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/824068adaeb7b158df2b36d8787f689646e715e0/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs#L995-L1000

As a result SecurityTokenNoExpirationException with IDX10225 is never thrown.

The best way to handle this would be to change JsonWebToken results to nullable, but I guess it would be a big breaking change.

Note: the above code snippets are from 6.8.0 branch but dev is at the same state (as of authoring this issue).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brentschmaltzcommented, Dec 14, 2020

@shadow-cs @GeoK i think consistency between the two handlers would be a good thing. As you suggest @GeoK a simple change to JsonWebTokenHandler should do the trick.

0reactions
yori-scommented, Jan 4, 2021

Any chance this will make it into a 6.8.x?

I’m currently working around with a custom TokenValidationParameters.LifetimeValidator of the form

static bool ValidateLifetime(DateTime? nbf, DateTime? exp, SecurityToken token, TokenValidationParameters tvp)
{
    if (default(DateTime) == nbf) nbf = null;
    if (default(DateTime) == exp) exp = null;

    // undelegate
    var tvp2 = tvp.Clone();
    tvp2.LifetimeValidator = null;
    Validators.ValidateLifetime(nbf, exp, token, tvp2);
    return true;
}

but this feels awkward and brittle.

Also, I’m using JsonWebTokenHandler on 2 different projects and would rather not duplicate the above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Facing issue with Verify JWT Policy
They want to validate that the signature is correct for the JWT, and that the JWT is not expired, and that some expected...
Read more >
How To Validate a JWT Token
The "exp" (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The processing...
Read more >
How to validate bearer JWT access tokens
JWT claims check -- The JWT claims set is validated, to ensure the token has not expired and has the expected issuer, audience...
Read more >
Invalidating JSON Web Tokens
I'd implement by putting invalidated tokens in redis, memcached or another in-memory datastore that supports setting an expiration time on a key ...
Read more >
Azure API Management policy reference - validate-jwt
Reference for the validate-jwt policy available for use in Azure API ... Specifies whether an expiration claim is required in the token.
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