[GH-ISSUE #8923] Support asymmetric jwt for session cookies #19869

Open
opened 2026-04-15 19:13:35 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @wallzero on GitHub (Apr 2, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8923

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

Is your feature request related to a problem? Please describe.

This comment suggest asymmetric keys for jwt session cookies are unsupported.

I discovered this after trying to verify the JWT session cookie using the JWKS keys.

Describe the solution you'd like

I'd like an option to generate jwt session cookies with asymmetric keys. I understand there are tradeoffs but it would also be more secure to share public keys among my services instead of secrets. Also the JWKS end point is easier to use than sharing secrets.

Describe alternatives you've considered

For now one can continue using secrets for jwt session cookies.

Additional context

I was following the JWKS example and I could not get the JWKS example to work. After trying to verify with jwt from the session cookie, jose it throws this error: Unsupported "alg" value for a JSON Web Key Set. I now know this is because the session cookies are using secrets and not using asymmetric keys.

Alternatively, I tried with hono/jwt and jwtVerify and I recieve the error JwtHeaderRequiresKid: required "kid" in jwt header: {"alg":"HS256"}. This makes sense now that I know the jwt session cookie does not use asymmetric keys.

It'd be helpful if the documentation made this distinction for now.

Originally created by @wallzero on GitHub (Apr 2, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8923 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. [This comment suggest](https://github.com/better-auth/better-auth/discussions/7672#discussioncomment-15635068) asymmetric keys for jwt session cookies are unsupported. I discovered this after trying to verify the JWT session cookie using the JWKS keys. ### Describe the solution you'd like I'd like an option to generate jwt session cookies with asymmetric keys. I understand there are tradeoffs but it would also be more secure to share public keys among my services instead of secrets. Also the JWKS end point is easier to use than sharing secrets. ### Describe alternatives you've considered For now one can continue using secrets for jwt session cookies. ### Additional context [I was following the JWKS example](https://better-auth.com/docs/plugins/jwt#example-with-local-jwks) and I could not get the JWKS example to work. After trying to verify with jwt from the session cookie, `jose` it throws this error: `Unsupported "alg" value for a JSON Web Key Set`. I now know this is because the session cookies are using secrets and not using asymmetric keys. Alternatively, I tried with `hono/jwt` and `jwtVerify` and I recieve the error `JwtHeaderRequiresKid: required "kid" in jwt header: {"alg":"HS256"}`. This makes sense now that I know the jwt session cookie does not use asymmetric keys. It'd be helpful if the documentation made this distinction for now.
GiteaMirror added the securityenhancement labels 2026-04-15 19:13:35 -05:00
Author
Owner

@GautamBytes commented on GitHub (Apr 3, 2026):

Will be working on it!

<!-- gh-comment-id:4183196606 --> @GautamBytes commented on GitHub (Apr 3, 2026): Will be working on it!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19869