-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
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:
- unusual, but not forbidden types are allowed
- Builder allows to specify custom allowed types
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:
- restore previous behavior by setting
JWSTypeVerifier
/JWETypeVerifier
to no-op verifiers in the builder(s) - allow to configure allowed types via config/builder
- 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"
}