Repository navigation
fix(session): accept ES256 access tokens and ignore unknown JWKS keys - #589
Merged
Merged
Conversation
The session verifier accepted only RS256 access tokens. It read the JWKS through the generated JwksResponse model, which holds only the members of an RSA key. Thus one JWKS key of a different type made each session check fail. The verifier now accepts RS256 and ES256. The allow-list is a fixed constant. The SDK reads the JWKS as raw JSON and uses the `kid` header of the token to select the key. It ignores all other keys, also keys of a type that it does not know. The SDK does these checks before ruby-jwt verifies the signature, because not all permitted ruby-jwt versions do them: - RS256 uses only an RSA key. ES256 uses only an EC P-256 key. - If the key has an `alg` member, it must be the algorithm of the token. - If the key has a `use` member, it must be `sig`. - The comparison of the algorithm name is exact. - An ES256 signature must be 64 bytes long. - A token that has a `crit` header is not valid. A key or a signature that OpenSSL cannot use gives the result for a token that is not valid. A JWKS response that is not JSON, or that has no `keys` array, gives the same result. The SDK does not put such a response in the cache. An unknown `kid` causes a new JWKS request, but not more than one in 30 seconds. If that request fails, the SDK continues to use the cached keys. The minimum version of the jwt gem is now 3.3.1. The new tests make their keys at test time. They cover ES256 tokens, a JWKS with RSA and EC keys in the two sequences, keys of unknown types, algorithm confusion, ES256 signatures of an incorrect length, unknown key IDs, JWKS requests that fail, and JWKS responses that are not JSON. The algorithm confusion tests also use keys that have no `alg` member.
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryAdds ES256 access-token support while keeping RS256 support.
No actionable issues were found. As stated by
|
This was referenced Dec 1, 2026
nicknisi
approved these changes
Dec 2, 2026
nicknisi
left a comment
Member
There was a problem hiding this comment.
Reviewed by Riker for Nick, at this head. Checked: the accepted algorithms are exactly RS256 and ES256 (HS* and none stay rejected), the key is matched to the token's algorithm and key type, unknown or unusable JWKS entries don't break verification of valid tokens, RS256 behavior is unchanged, and the new tests cover those cases.
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
This change lets the session verifier accept ES256 access tokens. It also makes the verifier ignore JWKS keys that it cannot use.
Problem
JwksResponsemodel. That model holds only the members of an RSA key. Thus one JWKS key of a different type made each session check fail, also for RS256 tokens.Change
All changes are in hand-written files.
WorkOS::SessionManager::JWK_ALGORITHMSis now["RS256", "ES256"]. The list is a fixed constant. The SDK does not take it from the token, from the JWKS or from the caller.kidheader of the token selects the key. The SDK ignores all other keys. This includes keys of an unknown type (for exampleOKPorAKP) and keys that are not correct.jwtgem verifies the signature:algmember, it must be the algorithm of the token.usemember, it must besig.r || s).critheader is not valid (RFC 7515, section 4.1.11). The SDK implements no header extension.Session#authenticate. An error of the JWKS request (for example a TLS error) escapes as before.keysarray, gives the same result for the token. The SDK does not put such a response in the cache, so the subsequent session check sends a new JWKS request.kidcauses a new JWKS request, but not more than one in 30 seconds. If that request fails, the SDK continues to use the cached keys. The cache time of 5 minutes does not change.Compatibility
JWK_ALGORITHMSchanges. Its line inrbi/workos/session_manager.rbichanges also. The type staysT::Array[String].critheader and an algorithm name in lower case.JSON::ParserErrorbefore. It now gives theinvalid_jwtresult.SessionManager#decode_jwtraisesJWT::DecodeErrorfor it.Dependency
jwtgem is now 3.3.1 ("~> 3.3", ">= 3.3.1").Gemfile.lockmoves from 3.3.0 to 3.3.1.jwtgem.Tests
test/workos/test_session.rbhas 45 new tests. The tests make their keys at test time.OKP,AKPand unknown key types, entries that are not objects, and keys that are not correct.x5candx5t#S256.kidof the EC key, an ES256 header with thekidof the RSA key, HS256 with the public key as the secret, andalgnone.algmember, and with keys whosealgmember agrees with the token. These tests fail if the SDK does not bind the algorithm to the key type and to the curve.kidnames a P-384 key.kid, akidthat is not a string, and acritheader.kid: the cooldown, and requests that fail.script/ciis successful with Ruby 3.3, 3.4 and 4.0. The session tests are also successful with jwt 3.3.2.Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.