Skip to content

feat(backend): encrypt stored GitHub access tokens - #536

Draft
marcalexiei wants to merge 3 commits into
stats-organization:masterfrom
marcalexiei:crypto
Draft

feat(backend): encrypt stored GitHub access tokens#536
marcalexiei wants to merge 3 commits into
stats-organization:masterfrom
marcalexiei:crypto

Conversation

@marcalexiei

Copy link
Copy Markdown

  • authenticated_users.access_token is AES-256-GCM encrypted when TOKEN_ENCRYPTION_KEY is set (AccessTokenCipher), with user_id as AAD;
    without a key it stays plaintext and a warning is logged on boot.
  • Reads accept legacy plaintext. An unreadable token comes back as token: null:
    /api/user-access and /api/downgrade drop the row so the user logs in again, cards fall back to the public PAT.
    A bad key fails on the token paths only, not on import.
  • TOKEN_ENCRYPTION_KEY=<new>,<old> rotates: first key encrypts, all decrypt.
  • pnpm --filter ./apps/backend run encrypt-access-tokens re-encrypts the rows not yet on the first key, with compare-and-swap, and exits non-zero on unreadable ones or a missing key.

@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@marcalexiei is attempting to deploy a commit to the martin-mfg's projects Team on Vercel.

A member of the Team first needs to authorize it.

@marcalexiei
marcalexiei marked this pull request as draft August 28, 2026 12:48
Comment thread apps/backend/src/common/tokenEncryption.js
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.

Access tokens stored in plaintext in Postgres

1 participant