Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: double-decoding of client credentials in request body #434

Merged
merged 5 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions client_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,5 @@ func clientCredentialsFromRequestBody(form url.Values, forceID bool) (clientID,
return "", "", errors.WithStack(ErrInvalidRequest.WithHint("Client credentials missing or malformed in both HTTP Authorization header and HTTP POST body."))
}

if clientID, err = url.QueryUnescape(clientID); err != nil {
return "", "", errors.WithStack(ErrInvalidRequest.WithHint(`The client id in the HTTP authorization header could not be decoded from "application/x-www-form-urlencoded".`).WithDebug(err.Error()))
} else if clientSecret, err = url.QueryUnescape(clientSecret); err != nil {
return "", "", errors.WithStack(ErrInvalidRequest.WithHint(`The client secret in the HTTP authorization header could not be decoded from "application/x-www-form-urlencoded".`).WithDebug(err.Error()))
}

return clientID, clientSecret, nil
}
10 changes: 10 additions & 0 deletions client_authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func TestAuthenticateClient(t *testing.T) {
barSecret, err := hasher.Hash(context.TODO(), []byte("bar"))
require.NoError(t, err)

// a secret containing literal characters that would be affected by double-URL-decoding.
percentSecret, err := hasher.Hash(context.TODO(), []byte("%66%6F%6F"))
pjcdawkins marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

key := internal.MustRSAKey()
jwks := &jose.JSONWebKeySet{
Keys: []jose.JSONWebKey{
Expand Down Expand Up @@ -127,6 +131,12 @@ func TestAuthenticateClient(t *testing.T) {
form: url.Values{"client_id": []string{"foo"}},
r: new(http.Request),
},
{
d: "should pass with client ID and secret containing literal % characters",
client: &DefaultOpenIDConnectClient{DefaultClient: &DefaultClient{ID: "foo%20bar", Secret: percentSecret}, TokenEndpointAuthMethod: "client_secret_post"},
form: url.Values{"client_id": []string{"foo%20bar"}, "client_secret": []string{"%66%6F%6F"}},
r: new(http.Request),
},
{
d: "should fail because auth method is not none",
client: &DefaultOpenIDConnectClient{DefaultClient: &DefaultClient{ID: "foo", Public: true}, TokenEndpointAuthMethod: "client_secret_basic"},
Expand Down