[PR #5510] [MERGED] feat(session): use JWE for cookie cache by default #6050

Closed
opened 2026-03-13 12:45:49 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5510
Author: @himself65
Created: 10/23/2025
Status: Merged
Merged: 10/23/2025
Merged by: @himself65

Base: canaryHead: himself65/2025/10/22/jwt


📝 Commits (3)

  • 8300f10 feat(session): use JWE with A256CBC-HS512 and HKDF for cookie cache by default
  • 0dde5e6 fix: import
  • 38ad4cc test: fix

📊 Changes

7 files changed (+538 additions, -56 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session-api.test.ts (+163 -0)
📝 packages/better-auth/src/api/routes/session.ts (+60 -21)
📝 packages/better-auth/src/cookies/cookies.test.ts (+134 -0)
📝 packages/better-auth/src/cookies/index.ts (+71 -34)
📝 packages/better-auth/src/crypto/jwt.ts (+100 -1)
📝 packages/core/src/types/init-options.ts (+9 -0)
📝 packages/telemetry/src/detectors/detect-auth-config.ts (+1 -0)

📄 Description

Closes: https://github.com/better-auth/better-auth/pull/5396


Summary by cubic

Default the session cookie cache to encrypted JWE (A256CBC-HS512 + HKDF) for stronger security, with a configurable strategy to keep legacy behavior. Adds JWT/JWE encode/decode helpers and updates tests and telemetry.

  • New Features

    • Cookie cache now defaults to strategy "jwt" using symmetric JWE.
    • Legacy "base64-hmac" strategy remains available via config.
    • New helpers: symmetricEncodeJWT/symmetricDecodeJWT and verifyJWT.
    • getCookieCache supports strategy selection and returns null on invalid JWT.
    • Telemetry now reports the cookie cache strategy.
  • Migration

    • No change needed for most users; default is secure JWE.
    • To keep previous behavior, set session.cookieCache.strategy: "base64-hmac".

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5510 **Author:** [@himself65](https://github.com/himself65) **Created:** 10/23/2025 **Status:** ✅ Merged **Merged:** 10/23/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/10/22/jwt` --- ### 📝 Commits (3) - [`8300f10`](https://github.com/better-auth/better-auth/commit/8300f10ce6653e73158747f34f3e5b0b899401ab) feat(session): use JWE with A256CBC-HS512 and HKDF for cookie cache by default - [`0dde5e6`](https://github.com/better-auth/better-auth/commit/0dde5e61ad5480fa1cb64594527fe1ce1ab580d7) fix: import - [`38ad4cc`](https://github.com/better-auth/better-auth/commit/38ad4ccffbd95f7402ccc97cde87e1eadda0a321) test: fix ### 📊 Changes **7 files changed** (+538 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session-api.test.ts` (+163 -0) 📝 `packages/better-auth/src/api/routes/session.ts` (+60 -21) 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+134 -0) 📝 `packages/better-auth/src/cookies/index.ts` (+71 -34) 📝 `packages/better-auth/src/crypto/jwt.ts` (+100 -1) 📝 `packages/core/src/types/init-options.ts` (+9 -0) 📝 `packages/telemetry/src/detectors/detect-auth-config.ts` (+1 -0) </details> ### 📄 Description Closes: https://github.com/better-auth/better-auth/pull/5396 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Default the session cookie cache to encrypted JWE (A256CBC-HS512 + HKDF) for stronger security, with a configurable strategy to keep legacy behavior. Adds JWT/JWE encode/decode helpers and updates tests and telemetry. - **New Features** - Cookie cache now defaults to strategy "jwt" using symmetric JWE. - Legacy "base64-hmac" strategy remains available via config. - New helpers: symmetricEncodeJWT/symmetricDecodeJWT and verifyJWT. - getCookieCache supports strategy selection and returns null on invalid JWT. - Telemetry now reports the cookie cache strategy. - **Migration** - No change needed for most users; default is secure JWE. - To keep previous behavior, set session.cookieCache.strategy: "base64-hmac". <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:45:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6050