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

Allow JWKSet with single key without kid set. #3

Merged
merged 2 commits into from
Jan 12, 2022

Conversation

MaPePeR
Copy link
Contributor

@MaPePeR MaPePeR commented Jun 11, 2021

Fixes SocialConnect/auth#139.

Sadly I couldn't find any tests for verifySignature to extend for this case, so this is untested.

@ghost
Copy link

ghost commented Aug 10, 2021

any idea when this could be merged ?

@MaPePeR
Copy link
Contributor Author

MaPePeR commented Aug 17, 2021

From my point of view the PR is finished and "ready to be merged" until further feedback. Maybe @ovr or @ADmad know more.

@ADmad
Copy link
Contributor

ADmad commented Jan 9, 2022

I checked another popular JWT handling lib firebase/php-jwt and it too requires the kid to be specified regardless of how many keys the JWKS contains. https://github.com/firebase/php-jwt/blob/edda0f9ee45b8367699804f792a9be6d5175e816/src/JWT.php#L397-L407

Even though a JWKS might only have 1 key, the key could change in future and hence your JWT header must always have the kid. So that when the key in JWSK is changed the existing JWT using the older kid get invalidated and proper error message can be provided on auth failure.

So I don't think this change should be merged.

@MaPePeR
Copy link
Contributor Author

MaPePeR commented Jan 9, 2022

I checked another popular JWT handling lib firebase/php-jwt and it too requires the kid to be specified regardless of how many keys the JWKS contains. https://github.com/firebase/php-jwt/blob/edda0f9ee45b8367699804f792a9be6d5175e816/src/JWT.php#L397-L407

That check is only done if there is an array of keys and not a single key. See the first 3 lines in the method.

The JWK specification says:

The "kid" value is a case-sensitive string. Use of this member is OPTIONAL.

The JWT specification has no mention of kid at all.

Even though a JWKS might only have 1 key, the key could change in future and hence your JWT header must always have the kid. So that when the key in JWSK is changed the existing JWT using the older kid get invalidated and proper error message can be provided on auth failure.

So I don't think this change should be merged.

I agree, that, not having the kid set, is bad, because its needed to properly change a key. But that is a problem/decision of the identity provider, that we probably cannot fix in all identity providers out there.
If this would be an identity provider library that exposes a keyset and my proposal was to not set the kid when there is only a single key: I'd totally agree with you. That would be stupid.
But: That's not the case. This is a library that tries to interface with other (possibly non-ideal) implementations and configurations out there and therefore should not refuse to do something that is valid according to the specification.

src/JWKSet.php Outdated Show resolved Hide resolved
src/JWKSet.php Outdated Show resolved Hide resolved
src/JWT.php Outdated Show resolved Hide resolved
@ADmad
Copy link
Contributor

ADmad commented Jan 9, 2022

But that is a problem/decision of the identity provider, that we probably cannot fix in all identity providers out there.

Fair enough, we can't control what various providers do.

@ADmad
Copy link
Contributor

ADmad commented Jan 9, 2022

@ovr The testsuite CI is not hooked to show the results for commit/PRs?

@ovr
Copy link
Member

ovr commented Jan 9, 2022

The testsuite CI is not hooked to show the results for commit/PRs?

You are right! I forget to connect this repo to GitLab CI as an external repo. I migrated this repo to GitHub actions. We need to rebase this PR to affect changes. Can you please rebase your PR @MaPePeR?

Thanks

@ADmad
Copy link
Contributor

ADmad commented Jan 10, 2022

@ovr You need to allow the workflow to run. I don't have write perms on this repo 🙂.

@ovr
Copy link
Member

ovr commented Jan 12, 2022

@ADmad Done, I've added you as a collaborator to this repository to allow that too. I'm sorry for late reply.

@ADmad ADmad merged commit 2508626 into SocialConnect:master Jan 12, 2022
@ADmad
Copy link
Contributor

ADmad commented Jan 12, 2022

@ovr Should I do a new minor release?

@ovr
Copy link
Member

ovr commented Jan 12, 2022

@ADmad yeah, minor or path. It's really hard to classify this change.

@ADmad
Copy link
Contributor

ADmad commented Jan 12, 2022

It's a feature addition IMO and since the public API has changed a new minor 1.3.0 would be better.

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.

OpenIdConnect JWT "kid" is not optional for single key keysets.
3 participants