Avoid disabling the signature requirement of a JWT token | CAST Appmarq

Avoid disabling the signature requirement of a JWT token

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

Health Factor

  Total Quality Index


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.

Benchmark Statistics

Global Compliance

nan%

Total Violations
0
Total Opportunities
0
Average Violations / App.
nan
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Select from drop-down

85.71%

Insurance

100.00%