Setting the Microsoft.IdentityModel.Tokens.TokenValidationParameters
properties RequireExpirationTime
, ValidateAudience
, ValidateIssuer
, or ValidateLifetime
to false
.
Token validation checks ensure that while validating tokens, all aspects are analyzed and verified. Turning off validation can lead to security holes by allowing untrusted tokens to make it through validation.
More details about best practices for token validation can be found on the library's wiki.
How to fix violationsSet the Microsoft.IdentityModel.Tokens.TokenValidationParameters
properties RequireExpirationTime
, ValidateAudience
, ValidateIssuer
, and ValidateLifetime
to true
. Or, remove the assignment to false
because the default value is true
.
In the vast majority of cases, this validation is essential to ensure the security of the consuming app. However, there are some cases where this validation is not needed, especially in non-standard token types. Before you disable this validation, be sure you have fully thought through the security implications. For information about the trade-offs, see the token validation library's wiki.
Suppress a warningIf you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA5404
// The code that's violating the rule is on this line.
#pragma warning restore CA5404
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA5404.severity = none
For more information, see How to suppress code analysis warnings.
Pseudo-code examplesusing System;
using Microsoft.IdentityModel.Tokens;
class TestClass
{
public void TestMethod()
{
TokenValidationParameters parameters = new TokenValidationParameters();
parameters.RequireExpirationTime = false;
parameters.ValidateAudience = false;
parameters.ValidateIssuer = false;
parameters.ValidateLifetime = false;
}
}
Solution
using System;
using Microsoft.IdentityModel.Tokens;
class TestClass
{
public void TestMethod()
{
TokenValidationParameters parameters = new TokenValidationParameters();
parameters.RequireExpirationTime = true;
parameters.ValidateAudience = true;
parameters.ValidateIssuer = true;
parameters.ValidateLifetime = true;
}
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4