[PR #6274] feat(jwt): support manual rotation, rotation on /jwks and cooldown #14806

Open
opened 2026-04-13 09:38:54 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6274
Author: @Bekacru
Created: 11/24/2025
Status: 🔄 Open

Base: nextHead: fix/rotation


📝 Commits (6)

  • 9c07001 feat(jwt): support manual rotation, rotation on /jwks and cooldown
  • 2082671 feat(jwt): enhance JWT key rotation with cooldown and manual control features
  • 7c5d0c2 refactor(jwt): improve key rotation logic and test cases for cooldown handling
  • 984ee0c Merge branch 'canary' into fix/rotation
  • 08a5804 lint
  • 983d2bb add util

📊 Changes

15 files changed (+502 additions, -108 deletions)

View changed files

📝 packages/better-auth/src/client/plugins/infer-plugin.ts (+8 -7)
📝 packages/better-auth/src/cookies/index.ts (+1 -1)
📝 packages/better-auth/src/db/field.ts (+64 -58)
📝 packages/better-auth/src/plugins/admin/admin.ts (+2 -3)
📝 packages/better-auth/src/plugins/admin/client.ts (+2 -3)
📝 packages/better-auth/src/plugins/device-authorization/index.ts (+1 -1)
📝 packages/better-auth/src/plugins/jwt/adapter.ts (+6 -6)
📝 packages/better-auth/src/plugins/jwt/index.ts (+55 -7)
📝 packages/better-auth/src/plugins/jwt/rotation.test.ts (+255 -4)
📝 packages/better-auth/src/plugins/jwt/sign.ts (+16 -6)
📝 packages/better-auth/src/plugins/jwt/types.ts (+14 -0)
📝 packages/better-auth/src/plugins/jwt/utils.ts (+70 -0)
📝 packages/better-auth/src/plugins/organization/client.ts (+2 -3)
📝 packages/better-auth/src/plugins/organization/organization.ts (+2 -3)
📝 packages/core/src/env/logger.ts (+4 -6)

📄 Description

Summary by cubic

Adds manual JWT key rotation, automatic rotation during /jwks and signing, and a cooldown to prevent rapid key creation. Improves reliability and control over key lifecycle.

  • New Features

    • Exported rotateJwk() with cooldown (default 5 minutes) and optional force.
    • Added POST /rotate-jwk to trigger rotation; accepts force and cooldown; returns rotated and keyId.
    • Automatic rotation now runs on /jwks and signJWT unless jwks.disableAutomaticRotation is true.
    • New option: jwks.disableAutomaticRotation to manage rotation manually.
  • Migration

    • If jwks.disableAutomaticRotation is enabled, create a key first via /rotate-jwk or rotateJwk() before signing or serving /jwks.
    • Adjust cooldown when rotating if you need faster rotations.

Written for commit 983d2bb6a8. Summary will update automatically on new commits.


🔄 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/6274 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 11/24/2025 **Status:** 🔄 Open **Base:** `next` ← **Head:** `fix/rotation` --- ### 📝 Commits (6) - [`9c07001`](https://github.com/better-auth/better-auth/commit/9c0700134e43a1549b9a6e494a3a1ed48cc8b69a) feat(jwt): support manual rotation, rotation on /jwks and cooldown - [`2082671`](https://github.com/better-auth/better-auth/commit/2082671c36339e6fbdb5f928634e040ec5a2f80c) feat(jwt): enhance JWT key rotation with cooldown and manual control features - [`7c5d0c2`](https://github.com/better-auth/better-auth/commit/7c5d0c2cf3fe82c35fec020853daed8a14e20eb5) refactor(jwt): improve key rotation logic and test cases for cooldown handling - [`984ee0c`](https://github.com/better-auth/better-auth/commit/984ee0c4e2fe3c8e3b59826d8e0b4b599d165a1d) Merge branch 'canary' into fix/rotation - [`08a5804`](https://github.com/better-auth/better-auth/commit/08a5804cfe4fca4e11384594af0d7f4b29192796) lint - [`983d2bb`](https://github.com/better-auth/better-auth/commit/983d2bb6a8a8921431a2b1d79c816879777441a5) add util ### 📊 Changes **15 files changed** (+502 additions, -108 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/client/plugins/infer-plugin.ts` (+8 -7) 📝 `packages/better-auth/src/cookies/index.ts` (+1 -1) 📝 `packages/better-auth/src/db/field.ts` (+64 -58) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+2 -3) 📝 `packages/better-auth/src/plugins/admin/client.ts` (+2 -3) 📝 `packages/better-auth/src/plugins/device-authorization/index.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/jwt/adapter.ts` (+6 -6) 📝 `packages/better-auth/src/plugins/jwt/index.ts` (+55 -7) 📝 `packages/better-auth/src/plugins/jwt/rotation.test.ts` (+255 -4) 📝 `packages/better-auth/src/plugins/jwt/sign.ts` (+16 -6) 📝 `packages/better-auth/src/plugins/jwt/types.ts` (+14 -0) 📝 `packages/better-auth/src/plugins/jwt/utils.ts` (+70 -0) 📝 `packages/better-auth/src/plugins/organization/client.ts` (+2 -3) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+2 -3) 📝 `packages/core/src/env/logger.ts` (+4 -6) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds manual JWT key rotation, automatic rotation during /jwks and signing, and a cooldown to prevent rapid key creation. Improves reliability and control over key lifecycle. - **New Features** - Exported rotateJwk() with cooldown (default 5 minutes) and optional force. - Added POST /rotate-jwk to trigger rotation; accepts force and cooldown; returns rotated and keyId. - Automatic rotation now runs on /jwks and signJWT unless jwks.disableAutomaticRotation is true. - New option: jwks.disableAutomaticRotation to manage rotation manually. - **Migration** - If jwks.disableAutomaticRotation is enabled, create a key first via /rotate-jwk or rotateJwk() before signing or serving /jwks. - Adjust cooldown when rotating if you need faster rotations. <sup>Written for commit 983d2bb6a8a8921431a2b1d79c816879777441a5. Summary will update automatically on new commits.</sup> <!-- 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-04-13 09:38:54 -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#14806