Skip to content

Spring Boot 2.3.x refuses JWT tokens with custom typ header #8730

@jrehwaldt

Description

@jrehwaldt

Spring Boot 2.3.x.RELEASE applies additional non-standard validation on JWT tokens due to upgrade to NimbusDS 8.x.

With Spring Boot 2.2.2.RELEASE a JWT token with header field typ: "JWS" validates fine. In Spring Boot 2.3.0.RELEASE such a token is rejected due to a breaking change in NimbusDS 8.x, which requires typ to be set to either JWT or omitted.

As per RFC 7515 there's no dedicated typ mandated.

The issue is that the builder design in NimbusJwtDecoder (in my case NimbusJwtDecoder.withPublicKey(publicKey).build()) does not allow to go back to the old behavior, nor does it allow to change the JWSTypeVerifier/JWETypeVerifier set in NimbusDS's DefaultJWTProcessor. Therefore, it is currently necessary to duplicate the complete builder code, which is making me uneasy considering it's a security relevant part and a future change in Spring Security/Nimbus might render my code insecure.

Current Behavior

JWT tokens with typ: JWS are refused since Spring Boot 2.3.x

Expected Behavior

Either one of:

Context

Dependency: org.springframework.security:spring-security-oauth2-jose:5.3.3.RELEASE
Class: org.springframework.security.oauth2.jwt.NimbusJwtDecoder

Unfortunately, I am not in control of the authorization server, which generates these custom JWTs. At the same time, I do not want to copy security relevant code.

Possible solutions:

  1. restore previous behavior by setting JWSTypeVerifier/JWETypeVerifier to no-op verifiers in the builder(s)
  2. allow to configure allowed types via config/builder
  3. keep as is and require users to duplicate the builder code to apply either 1. or 2.
Stacktrace
{
   "cause":null,
   "stackTrace":[
      {
         "classLoaderName":"app",
         "moduleName":null,
         "moduleVersion":null,
         "methodName":"authenticate",
         "fileName":"JwtAuthenticationProvider.java",
         "lineNumber":86,
         "nativeMethod":false,
         "className":"org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider"
      },
      {
         "classLoaderName":"app",
         "moduleName":null,
         "moduleVersion":null,
         "methodName":"authenticate",
         "fileName":"ProviderManager.java",
         "lineNumber":199,
         "nativeMethod":false,
         "className":"org.springframework.security.authentication.ProviderManager"
      },
      {
         "classLoaderName":"app",
         "moduleName":null,
         "moduleVersion":null,
         "methodName":"doFilterInternal",
         "fileName":"BearerTokenAuthenticationFilter.java",
         "lineNumber":124,
         "nativeMethod":false,
         "className":"org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter"
      }
      // ... [snip]
   ],
   "title":"Unauthorized",
   "status":"UNAUTHORIZED",
   "detail":"An error occurred while attempting to decode the Jwt: JOSE header \"typ\" (type) \"JWS\" not allowed"
}

Metadata

Metadata

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions