Repository navigation
fix(session): accept ES256 access tokens and ignore unknown JWKS keys - #126
Open
gjtorikian wants to merge 1 commit into
Open
gjtorikian wants to merge 1 commit into
gjtorikian wants to merge 1 commit into
Conversation
`WorkOS.Session.authenticate/1` accepted only RS256 access tokens. It read the JWKS through the generated `WorkOS.JwksResponse` model, which holds RSA members only. Thus an EC key did not verify a token. An OKP or AKP key in the JWKS caused a `FunctionClauseError` for all tokens. The verifier now has a fixed allow-list of RS256 and ES256: - It reads the raw JWKS document and selects the key by `kid`. - RS256 verifies only with an RSA key. ES256 verifies only with an EC key on the P-256 curve. - An `alg` member of the key must be equal to the token algorithm. A `use` member of the key must be `sig`. - It skips each key that it cannot use. Such a key is not an error. - An ES256 signature must be exactly 64 bytes. - It rejects a token that has a `crit` header member. - A malformed key or signature gives the `invalid_jwt` result. The requirement for jose does not change. The SDK makes the signature length check itself. Thus the check does not depend on the jose release. Public functions, types and failure reasons do not change. The new tests make their keys at test time. They include RS256 and ES256 tokens, a mixed JWKS in the two orders and unknown key types. They also include algorithm confusion, a P-384 key, an unknown `kid`, and ES256 signatures with a changed value or an incorrect length.
[High impact] The PR appears safe to merge; no actionable issues were established. SummaryAdds ES256 support to
No actionable issues were established. Tests were not run during this review.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
WorkOS.Session.authenticate/1accepted only RS256 access tokens. It read the JWKS through the generatedWorkOS.JwksResponsemodel, which holds RSA members only. Thus an EC key did not verify a token. An OKP or AKP key in the JWKS caused aFunctionClauseErrorfor all tokens.This change gives the verifier a fixed allow-list of RS256 and ES256. The verifier ignores the keys that it cannot use.
Changes
lib/workos/session.ex. The token, the JWKS and the caller cannot change it.jose. RS256 verifies only with an RSA key. ES256 verifies only with an EC key on the P-256 curve.algmember, it must be equal to the token algorithm. If the key has ausemember, it must besig. The comparison of the algorithm name is exact.kid. It skips keys with an unknown type or curve, keys without akidand malformed keys. Such a key is not an error.nande, orcrv,xandy.kid. If two keys of one type share akid, the verifier uses the first key.critheader member (RFC 7515, section 4.1.11).invalid_jwtresult. It does not raise.authenticate/1now names the two algorithms.The JWKS cache and the 30-second refetch interval for an unknown
kiddo not change. The expiry check, the token type check and the:jwt_issuercheck also do not change.Dependencies
The requirement for
josedoes not change (~> 1.11). There is no new dependency.jose 1.11.13 rejects an ECDSA signature that does not have the canonical length. The SDK does not require that release, because jose 1.11.11 and later do not compile on Erlang/OTP 25. Elixir 1.18 supports Erlang/OTP 25. Thus the SDK makes the length check itself, and the check does not depend on the jose release. The test suite passes on Elixir 1.18 with Erlang/OTP 25 and jose 1.11.10.
Compatibility
No public function, parameter, return type or failure reason changes. RS256 tokens that verified before still verify.
Tests
The new tests are in
test/workos/session_test.exs. They make all keys at test time.alg,use,x5candx5t#S256members.kidof the EC key. An ES256 header has thekidof the RSA key.algnone.kidof a P-384 key. A token has an unknownkid.critheader member. A key is malformed. The JWKS response is not a JWKS.Each rejected token gives the
invalid_jwtresult and does not raise.script/cipasses: compile with warnings as errors, format, Credo, Dialyzer and 573 tests.