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

Check if session key exists before accessing it #251

Merged
merged 1 commit into from
Nov 20, 2021

Conversation

erikdsjostrom
Copy link
Contributor

I ran into this issue when trying to set up a basic OAuth flow using
this library and Keycloak. The issue was introduced by ce97230 which
checks for PKCE support, the way it does this is to call the function
getCodeVerifier() which in turn calls getSessionKey() which returns a
specified key from _SESSION. This will fail when setting up a client
without PKCE because the key will not exist.

With this commit a sanity check is introduced which first checks if the
key exists in _SESSION before returning it, otherwise just returning
false. This should not affect existing library functionality.

Signed-off-by: Erik Sjöström [email protected]

I ran into this issue when trying to set up a basic OAuth flow using
this library and Keycloak. The issue was introduced by ce97230 which
checks for PKCE support, the way it does this is to call the function
getCodeVerifier() which in turn calls getSessionKey() which returns a
specified key from _SESSION. This will fail when setting up a client
without PKCE because the key will not exist.

With this commit a sanity check is introduced which first checks if the
key exists in _SESSION before returning it, otherwise just returning
false. This should not affect existing library functionality.

Signed-off-by: Erik Sjöström <[email protected]>
@azmeuk azmeuk merged commit 6b33751 into jumbojett:master Nov 20, 2021
@jenkoian
Copy link
Contributor

Just a heads up, this broke my implementation, due to this line:

&& ($claims->nonce === $this->getNonce())
previously if $claims didn't have a nonce (which is optional according to the spec) it would be null and thus the check with getNonce() which calls getSessionKey() would also return null and it would all be fine. With this change null !== false.

This change is probably a good one though. I'd suggest we change the line I linked to so it becomes:

!isset($claims->nonce) || $claims->nonce === $this->getNonce()

Which also brings it inline with the other checks in this method. I'll put up a pull request with that change shortly if you're happy with it, but let me know otherwise 👍

@azmeuk
Copy link
Collaborator

azmeuk commented Nov 23, 2021

Hi. Thank you for your report. This is great if you want to provide a patch! Would you consider writing a small test describing your usecase too?

jenkoian pushed a commit to jenkoian/OpenID-Connect-PHP that referenced this pull request Nov 24, 2021
Nonce is optional according to the open ID spec, so we shouldn't throw
an exception if a nonce is null (or not set) within the claims.

This was working previously but a change to how session keys are checked
here: jumbojett#251 meant
that the nonce check was now strict and `null !== false`.

This fixes by checking first that the nonce is set before checking it
matches the nonce in the session.
@jenkoian
Copy link
Contributor

Done: #280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants