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: pass standard params to storage #791

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ func (a *Request) Merge(request Requester) {
}
}

var defaultAllowedParameters = []string{"grant_type", "response_type", "scope", "client_id"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my own code, I use the following list:

			"max_age", "prompt", "acr_values", "id_token_hint", "nonce",
			// PCRE.
			"code_challenge", "code_challenge_method",
			// Other fields.
			"display", "ui_locales", "login_hint",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this is not really a "default" list (you cannot set it to non-default) but an "always allowed list".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this is not really a "default" list (you cannot set it to non-default) but an "always allowed list".

True :)

I would probably drop id_token_hint because it contains a valid ID token

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, thanks. You are right. I am storing that to support logout. But I should just store the subject ID, not the whole token.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, id_token_hint is from this list in fosite: https://github.com/ory/fosite/blob/master/handler/openid/flow_explicit_auth.go#L29-L35

So if you are saying this should not be stored into the database? Because fosite currently does so:

	if err := c.OpenIDConnectRequestStorage.CreateOpenIDConnectSession(ctx, resp.GetCode(), ar.Sanitize(oidcParameters)); err != nil {
		return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
	}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this means that subject should be extracted out earlier from the id_token_hint instead of being passed to the store inside form?


func (a *Request) Sanitize(allowedParameters []string) Requester {
b := new(Request)
allowed := map[string]bool{}
for _, v := range allowedParameters {
for _, v := range append(allowedParameters, defaultAllowedParameters...) {
allowed[v] = true
}

Expand Down
14 changes: 11 additions & 3 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ func TestSanitizeRequest(t *testing.T) {
RequestedScope: Arguments{"asdff"},
GrantedScope: []string{"asdf"},
Form: url.Values{
"foo": []string{"fasdf"},
"bar": []string{"fasdf", "faaaa"},
"baz": []string{"fasdf"},
"foo": []string{"fasdf"},
"bar": []string{"fasdf", "faaaa"},
"baz": []string{"fasdf"},
"grant_type": []string{"code"},
"response_type": []string{"id_token"},
"client_id": []string{"1234"},
"scope": []string{"read"},
},
Session: new(DefaultSession),
}
Expand All @@ -92,6 +96,10 @@ func TestSanitizeRequest(t *testing.T) {
assert.Equal(t, "fasdf", a.GetRequestForm().Get("bar"))
assert.Equal(t, []string{"fasdf", "faaaa"}, a.GetRequestForm()["bar"])
assert.Equal(t, "fasdf", a.GetRequestForm().Get("baz"))
assert.Equal(t, "code", a.GetRequestForm().Get("grant_type"))
assert.Equal(t, "id_token", a.GetRequestForm().Get("response_type"))
assert.Equal(t, "1234", a.GetRequestForm().Get("client_id"))
assert.Equal(t, "read", a.GetRequestForm().Get("scope"))
}

func TestIdentifyRequest(t *testing.T) {
Expand Down
Loading