Skip to content

Accept versioned Better Auth secrets - #449

Merged
tnkuehne merged 3 commits into
mainfrom
feat/better-auth-secret-versions
Nov 27, 2026
Merged

tnkuehne merged 3 commits into
mainfrom
feat/better-auth-secret-versions

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

BETTER_AUTH_SECRET is the only key for the values Better Auth encrypts, such as provider tokens in account, the private JWT signing key in jwks and OAuth replay responses. Its ciphertexts name no version, so the secret could not be replaced without losing them.

Changes

  • Configuration. BETTER_AUTH_SECRETS takes Better Auth's version list, current first, as comma-separated <version>:<secret> entries, read as Better Auth reads them (surrounding whitespace ignored; an empty value counts as unset). Secrets need 32 or more characters, and duplicate or unsafe version numbers fail configuration, so deploy-hosted stops before it changes anything. The control plane passes the list as Better Auth's secrets option.
  • Earlier values. BETTER_AUTH_SECRET stays and remains Better Auth's fallback, so values written before versions still open. New values carry their version ($ba$<version>$).
  • Hosted. deploy-hosted requires BETTER_AUTH_SECRETS, validates it with the rest of the configuration, deploys it to the control plane and redacts each version in its logs.
  • Self-hosted. Compose passes BETTER_AUTH_SECRETS to the control plane. Without it, installations keep the single authentication key; with it, the earliest version must hold that key.

Upgrade

  • Hosted: set BETTER_AUTH_SECRETS to 1: followed by the current BETTER_AUTH_SECRET, which must contain no comma and no surrounding whitespace. Nothing changes for signed-in users.

Retiring a version later still needs more: the JWT signing key and provider tokens of inactive users are not written again, and signed session cookies follow the current version only. That is a separate change.

Testing

  • svelte-check (control plane), oxlint, oxfmt
  • apps/control-plane: better-auth-secrets.test.ts (values from before versions and under an earlier version open after rotation, new values carry the current version, entries parse as Better Auth parses them, malformed lists are rejected; fails without the option), social-sign-in.test.ts

BETTER_AUTH_SECRET was the only key for Better Auth's encrypted values,
such as provider tokens and the JWT signing key, and had no version, so it
could not be replaced. BETTER_AUTH_SECRETS passes Better Auth's own version
list, current first. New values carry the version; values written before
still open with BETTER_AUTH_SECRET. Hosted deployments require it.
Whitespace around versions and secrets is ignored as Better Auth's own
parser ignores it, an empty setting counts as unset, and duplicate or
unsafe version numbers fail configuration instead of authentication
startup, so deploy-hosted stops before it changes anything. Compose passes
the setting to the control plane, and deploy logs redact each version on
its own. The test opens a value under an earlier version after rotation.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 65ad6e1 Nov 27 2026, 11:13 AM

Better Auth treats only an empty value as unset and reads the variable itself
when the option is unset, so a blank value passed configuration but failed
authentication startup after a Hosted deployment.
@tnkuehne
tnkuehne merged commit 7082283 into main Nov 27, 2026
15 of 17 checks passed
@tnkuehne
tnkuehne deleted the feat/better-auth-secret-versions branch November 27, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant