-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
When an /oauth2/authorize endpoint is hit without any response_type parameter it is redirecting to login screen
According to spec error response of /authorize should redirect to redirect url and state the error message in query param
some thing like this
HTTP/1.1 302 Found
Location: **https://client.example.com/cb?error=access_denied&state=xyz
https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
But this is redirect to login screen
To Reproduce
Steps to reproduce the behavior.
You can check with above code base
Expected behavior
Proper error message should be displayed along with redirect_uri
I have analyzed the code and figured out the problem
OAuth2AuthorizationCodeRequestAuthenticationConverter class which is responsible for validating the input request throws exception if there is response_type param
String responseType = request.getParameter(OAuth2ParameterNames.RESPONSE_TYPE); if (!StringUtils.hasText(responseType) || parameters.get(OAuth2ParameterNames.RESPONSE_TYPE).size() != 1) { throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.RESPONSE_TYPE); } else if (!responseType.equals(OAuth2AuthorizationResponseType.CODE.getValue())) { throwError(OAuth2ErrorCodes.UNSUPPORTED_RESPONSE_TYPE, OAuth2ParameterNames.RESPONSE_TYPE); }
and no authentication object is created due to error and this error is handed by sendErrorResponse method
this method has below condition which will be true for all validations done in converter regardless of invalid redirect uri
As per Spec if the client Id is missing or redirect uri is incorrect then we should not redirect to invalid redirect uri
below condition holds good for such case
`
if (authorizationCodeRequestAuthentication == null ||
!StringUtils.hasText(authorizationCodeRequestAuthentication.getRedirectUri())) {
response.sendError(HttpStatus.BAD_REQUEST.value(), error.toString());
return;
}
This will redirect to /error
Since there is no authentication object created AnonymousAuthenticationFilter creates AnonymousAuthenticationToken
This /error is intercepted by AuthorizationFilter which makes the access decision since this anonymous this willl throw AccessDeniedException
This exception is handled by ExceptionTranslationFilter which calls LoginUrlAuthenticationEntryPoint.commence which will redirect to /login and Login screen after entering credentials we get 400 bad request with whitelabel error page
`