CRITICAL
Rule Definition
If the expiration time validation is disabled, a JWT token will be valid beyond its expiry time. An attacker would be able to authenticate with an expired token.
Remediation
Do not disable the expiration time validation of a JWT token.
Violation Code Sample
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = false, // issue
RequireSignedTokens = true,
RequireExpirationTime = true,
ValidateIssuerSigningKey = true,
};
});
Fixed Code Sample
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true, // OK
RequireSignedTokens = true,
RequireExpirationTime = true,
ValidateIssuerSigningKey = true,
};
});
Reference
CWE-613: Insufficient Session Expiration
https://cwe.mitre.org/data/definitions/613.html
Related Technologies
Technical Criterion
Secure Coding - Weak Security Features
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.