Skip to content

Encrypt provider tokens that management saves - #252

Merged
tnkuehne merged 1 commit into
mainfrom
feat/encrypt-oauth-tokens
Nov 20, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
feat/encrypt-oauth-tokens

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Better Auth stores OAuth access and refresh tokens in plain text unless account.encryptOAuthTokens is set; its option documentation calls plain storage "a security risk if your database is compromised". Management saves them for company SSO and social sign-in but never reads them, so a database copy would carry usable grants to people's company and social accounts.

What changes

  • Management sets account.encryptOAuthTokens: true. Better Auth encrypts access and refresh tokens with the authentication secret (XChaCha20-Poly1305) and decrypts them where it reads them.
  • Tokens saved before stay readable (Better Auth recognizes plain values) and are replaced with encrypted ones at the next sign-in.
  • Better Auth keeps ID tokens unencrypted. The Entra migration in Let management assert a member's app identity to connectors #246 reads them, so this PR does not depend on the merge order.

Tests

  • The Entra login edge test checks that the saved access token differs from the issued one and decrypts to it with the authentication secret.
  • All Vitest suites pass, as do the edge, installation and Entra suites.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Management enables Better Auth’s encryption for saved provider access and refresh tokens.

  • Company and social sign-ins save provider access and refresh tokens encrypted.

Reviews (1) · Last reviewed commit: "Encrypt provider tokens that management ..." · Reviewed by Greptile

Better Auth stores OAuth access and refresh tokens in plain text unless
`account.encryptOAuthTokens` is set, so a database copy would carry usable
grants to people's company and social accounts. Management now lets
Better Auth encrypt them with the authentication secret. Tokens saved
before remain readable and are replaced with encrypted ones at the next
sign-in. Better Auth keeps ID tokens as they are.
@tnkuehne
tnkuehne merged commit c5eb6ee into main Nov 20, 2026
15 checks passed
@tnkuehne
tnkuehne deleted the feat/encrypt-oauth-tokens branch November 20, 2026 17:45
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