fix(jwks): filter unsupported key types in fixJwksAlg#1333
Conversation
4afc506 to
5b837bf
Compare
julien-nc
left a comment
There was a problem hiding this comment.
Thanks a lot for this PR!
Why not filtering before the foreach loop? We skip the keys with the same condition as your filter anyway.
a488980 to
658f25f
Compare
@julien-nc , done :D thx for the idea ! |
Filter out keys with incompatible kty (e.g. P-521/OKP when expecting RSA) before the foreach loop, preventing Firebase PHP-JWT from crashing on unsupported curves. Fixes nextcloud#823 As suggested by @julien-nc, the filter is applied before iteration rather than after, removing the redundant continue condition. Signed-off-by: Strobel Pierre <strobelpierre@gmail.com>
2176c7c to
f3601c1
Compare
|
Hi @julien-nc 👋 I've rebased the branch on latest Thanks! |
|
Tested and works for us! |
|
@geoffspace , thx for testing ❤️ |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
Summary
Fixes #823 —
JWK::parseKeySet()crashes withDomainException: Unrecognised or unsupported EC curvewhen the OIDC provider's JWKS endpoint returns keys with types that Firebase JWT cannot parse (e.g. EC P-521 curve, certain OKP subtypes).Root cause
fixJwksAlg()already identifies the matching key by comparingkty(key type family), but it returns the entire JWKS — including keys with incompatible types. Firebase JWT'sparseKeySet()then iterates all keys and throws on the first unsupported one instead of skipping it (firebase/php-jwt#561).Fix
Filter the JWKS to only include keys matching the expected
ktybefore returning. This is a 5-line addition after the existing matching logic:This way
parseKeySet()never encounters unsupported key types.Why not just update Firebase JWT?
Firebase JWT v6 and v7 both have this behavior —
parseKey()throwsDomainExceptionfor unsupported curves instead of returningnull. The upstream issue (#561) has been open since 2023 with no fix merged.Supersedes
This PR supersedes the draft PR #868 which only hardcoded P-521 removal. This approach is more general (filters by
ktyfamily) and works against the currentmainbranch.Test plan
fixJwksAlgwith mixed key types (RSA + P-521 EC + OKP)