Security icon indicating copy to clipboard operation
Security copied to clipboard

JwtBearer does not return any useful info when failing to validate/accept a token

Open vibronet opened this issue 10 years ago • 10 comments

It is currently very challenging to troubleshoot validation failures originated in the JwtBearer middleware. The client doesn't get back the reasons for which the token failed the validation, which makes it very tough to identify common error situations (such as audience mismatch, untrusted issuers, and so on). I suggest that the JwtBearer middleware should return some indication about the failure in the response, and specifically in the WWW-Authenticate header. It goes without saying that the kind of information returned should undergo rigorous security reviews to ensure that the middleware does not leak information that could be used for refining an attack against the protected service.

vibronet avatar Apr 12 '16 21:04 vibronet

@blowdart

Tratcher avatar Apr 12 '16 21:04 Tratcher

The first problem is getting meaningful errors out of ValidateToken. See https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/312.

Tratcher avatar Apr 12 '16 21:04 Tratcher

If we can get the information then we should return it somehow.

blowdart avatar Apr 12 '16 22:04 blowdart

Need to get a grasp on what the top hard-to-debug/hard-to-diagnose issues are.

Some problem areas:

  • Audience mismatch
  • Issuers that the app doesn't like
  • Tokens outside of valid window (e.g. expired, not yet valid)
  • Signature failures (e.g. key not found)

Some of these already have specific exceptions associated with them.

Eilon avatar Apr 14 '16 22:04 Eilon

Should look into what's valid in the WWW-Authenticate header to transmit the diagnostic message. http://www.ietf.org/rfc/rfc2617.txt

Eilon avatar Apr 14 '16 22:04 Eilon

Definitely a good idea (FWIW, we'll implement a similar thing in the aspnet-contrib validation and introspection middleware in the next version).

That said, it might be interesting to provide an option to turn off these details, for people who don't want to disclose them (we had a similar discussion with @MonkeyJamboree about ASOS' introspection endpoint, and whether we should tell the caller why the token was invalid: https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server/issues/157)

kevinchalet avatar Apr 15 '16 02:04 kevinchalet

@PinpointTownes good point!

Eilon avatar Apr 15 '16 17:04 Eilon

@brentschmaltz can you add a comment here with which exceptions are thrown for the cases we are concerned about?

Eilon avatar Apr 21 '16 22:04 Eilon

Ping @brentschmaltz

Eilon avatar May 12 '16 22:05 Eilon

Problem Exception
Audience mismatch SecurityTokenInvalidAudienceException
Issuers that the app doesn't like SecurityTokenInvalidIssuerException
Tokens outside of valid window (e.g. expired, not yet valid) SecurityTokenNoExpirationException, SecurityTokenInvalidLifetimeException, SecurityTokenNotYetValidException, SecurityTokenExpiredException
Signature failures (e.g. key not found) SecurityTokenInvalidSignatureException, SecurityTokenSignatureKeyNotFoundException

Anything else we should be reporting to users @brentschmaltz @vibronet?

Tratcher avatar May 24 '16 18:05 Tratcher