CRITICAL
Rule Definition
If the signature requirement is disabled, there is no guarantee about the integrity data of a JWT token. An attacker would be able to authenticate with other user accounts or other resources.
Remediation
Do not disable the signature requirement of a JWT token.
Violation Code Sample
// .NET
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
RequireSignedTokens = false, // issue
RequireExpirationTime = true,
ValidateIssuerSigningKey = true,
};
});
// Java
Jwts.parser().setSigningKey(key).parse(authToken); // avoid use 'parse' method
Fixed Code Sample
// .NET
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
RequireSignedTokens = true, // OK
RequireExpirationTime = true,
ValidateIssuerSigningKey = true,
};
});
// Java
Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jws); // OK
Reference
CWE-287: Improper Authentication
https://cwe.mitre.org/data/definitions/287.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.