client_id authentication parameter must have printable ASCII characters
Closes gh-889
This commit is contained in:
@@ -118,6 +118,7 @@ public final class OAuth2ClientAuthenticationFilter extends OncePerRequestFilter
|
||||
this.authenticationDetailsSource.buildDetails(request));
|
||||
}
|
||||
if (authenticationRequest != null) {
|
||||
validateClientIdentifier(authenticationRequest);
|
||||
Authentication authenticationResult = this.authenticationManager.authenticate(authenticationRequest);
|
||||
this.authenticationSuccessHandler.onAuthenticationSuccess(request, response, authenticationResult);
|
||||
}
|
||||
@@ -201,4 +202,25 @@ public final class OAuth2ClientAuthenticationFilter extends OncePerRequestFilter
|
||||
this.errorHttpResponseConverter.write(errorResponse, null, httpResponse);
|
||||
}
|
||||
|
||||
private static void validateClientIdentifier(Authentication authentication) {
|
||||
if (!(authentication instanceof OAuth2ClientAuthenticationToken)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// As per spec, in Appendix A.1.
|
||||
// https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-07#appendix-A.1
|
||||
// The syntax for client_id is *VSCHAR (%x20-7E):
|
||||
// -> Hex 20 -> ASCII 32 -> space
|
||||
// -> Hex 7E -> ASCII 126 -> tilde
|
||||
|
||||
OAuth2ClientAuthenticationToken clientAuthentication = (OAuth2ClientAuthenticationToken) authentication;
|
||||
String clientId = (String) clientAuthentication.getPrincipal();
|
||||
for (int i = 0; i < clientId.length(); i++) {
|
||||
char charAt = clientId.charAt(i);
|
||||
if (!(charAt >= 32 && charAt <= 126)) {
|
||||
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user