Skip to content

client_id and client_secret provided via query parameters are accepted for client_secret_post #1378

@idotobi

Description

@idotobi

Describe the bug
When a client has the authentication method client_secret_post enabled, token requests like the following succeed:

POST /oauth2/token?client_id=messaging-client&client_secret=secret&grant_type=client_credentials

However, according to The OAuth 2.1 Authorization Framework specification they must not.

Including the client credentials in the request content using the two parameters is NOT RECOMMENDED and SHOULD be limited to clients unable to directly utilize the HTTP Basic authentication scheme (or other password-based HTTP authentication schemes). The parameters can only be transmitted in the request content and MUST NOT be included in the request URI.

To Reproduce

  1. Adapt the samples/default-authorizationserver/src/main/resources/application.yml
     oauth2:
       authorizationserver:
         client:
           messaging-client:
             registration:
               client-id: "messaging-client"
               client-secret: "{noop}secret"
               client-authentication-methods:
             registration:
               client-id: "messaging-client"
               client-secret: "{noop}secret"
               client-authentication-methods:
                 - "client_secret_basic"
+                - "client_secret_post"
               authorization-grant-types:
                 - "authorization_code"
                 - "refresh_token"
                 - "client_credentials"
  1. Start the default sample server ./gradlew -b samples/default-authorizationserver/samples-default-authorizationserver.gradle bootRun
  2. Execute curl -X POST "http://localhost:9000/oauth2/token?client_id=messaging-client&client_secret=secret&grant_type=client_credentials"

Expected behavior
The specification does not directly say what should be returned in this case.

I would think that one of the following two responses would be reasonable (with a slight preference for 1):

  1. Bad request, to be very specific
HTTP/1.1 400
{
    "error": "invalid_request",
    "error_description": "OAuth 2.0 Parameter: client_id and client_secret not allowed as query parameter",
    "error_uri": "https://datatracker.ietf.org/doc/html/rfc6749#section-5.2"
}
  1. Unauthorized, as credentials are not found in any of the supported/expected ways
HTTP/1.1 401

Further Notes
As far as I understand, this is caused by the usage of OAuth2EndpointUtils.getParameters(request) in

, which calls jakarta.servlet.ServletRequest#getParameterMap, which according to the docs includes both body and query parameters in the returned map.

Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions