fix(session): reject asymmetric JWT algorithms the built-in serializer cannot sign - #92
Merged
Merged
Conversation
…r cannot sign JWTTokenSerializer signs and verifies with the secret_key string, so RS*, ES*, PS* and EdDSA were accepted by SessionConfig and then failed inside PyJWT on the first create_session(). The serializer now raises ValueError when it is built with one of them, so the SessionManager fails at startup with a message that points to the HMAC algorithms or a custom token_serializer. Configurations that pass their own serializer are unaffected. Closes #86
allen0099
force-pushed
the
fix/jwt-asymmetric-algorithms
branch
from
September 25, 2026 08:31
c604406 to
34b03dd
Compare
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.
Closes #86. This is option 1 from the issue: validate early.
Problem
SessionConfig.jwt_algorithmacceptsRS*,ES*,PS*andEdDSA, butJWTTokenSerializersigns and verifies with the singlesecret_keystring. Such a configuration started up fine, then the firstcreate_session()failed inside PyJWT (InvalidKeyError).Change
JWT_HMAC_ALGORITHMS(HS256/HS384/HS512) insession/config.pylists what the built-in serializer can use.JWTTokenSerializer.__init__raisesValueErrorfor any other algorithm. BecauseSessionManagerbuilds the serializer in its constructor, the error now appears at startup. The message names both fixes: use an HS algorithm, or pass a customtoken_serializer.SessionConfigstill accepts every algorithm it accepted before. ASessionManagerthat gets its owntoken_serializernever builds the built-in serializer, so it is unaffected.docs/JWT_CLAIMS.mdanddocs/SESSION.mddescribe the new behavior.CHANGELOG.mdgains a Fixed entry.Real key-pair support (option 2,
jwt_private_key/jwt_public_key) is left for a later feature.Tests
SessionManagerfails at construction for RS256.Note
Rebased onto master after #91 merged: the
### Fixedsection under[Unreleased]now holds both entries.