Repository navigation
Description
Problem / motivation
When MCPProxy signs in to an upstream MCP server over OAuth (Linear, Notion, GitHub, any DCR server), the access token, the refresh token and the dynamically registered client secret are stored as plain JSON in the oauth_tokens bucket of config.db (storage.OAuthTokenRecord, BoltDB.SaveOAuthToken, internal/storage/bbolt.go). The file is created 0600 in a 0700 directory, which is the only protection. A copy of config.db (a backup, a volume snapshot, a copied data directory) yields working long-lived refresh tokens for every connected account. A refresh token is worth more than the proxy's own API key: it keeps working after the key is rotated.
This is the same in both editions. internal/storage has no build tags, so the Server edition writes the identical plaintext rows. The Server edition's AES-256-GCM store (internal/serveredition/broker/bbolt_aes.go, key from server_edition.credential_encryption_key) covers a different thing, the per-user credentials in user_upstream_credentials, so a single-operator deployment (either edition) has no way to encrypt the tokens the proxy itself holds. The other secrets are fine: agent tokens are stored hashed, and server secrets can be ${env:} references.
Proposed solution
An edition-neutral, opt-in setting, for example oauth_token_encryption_key (a ${env:...} / ${keyring:...} reference, or a base64 32-byte key, same format as credential_encryption_key). Sketch:
- With a key set,
SaveOAuthTokenseals the record with AES-256-GCM (random nonce per record, server name bound as additional data so rows cannot be swapped) and writes a versioned envelope (enc:v1:...). Reads accept both envelope and legacy plaintext, so enabling it needs no migration step; plaintext rows are re-sealed on their next write, and a one-shot rewrite at boot (ormcpproxy auth encrypt-tokens) can finish the job. - No key set: behaviour exactly as today.
- Encrypted rows but no key (or a wrong key): the server reports "stored OAuth token cannot be decrypted: key missing/wrong" in its status and doctor output and does not delete or overwrite the row, so a missing environment variable is a fix-the-env problem and not a silent re-login of every server.
- Reuse the Server edition's AES code by moving the small seal/open helpers into an untagged package (the broker store keeps using it). The key source could be
${env:}and${keyring:}today; a${file:/run/secrets/x}provider (already suggested indocs/research/server-edition-2026-09-14) would make it work with Docker/Kubernetes secrets, where${keyring:}has no backend.
What this does and does not buy: it protects copies of the database file and backups. It does not protect against someone who can read the running process's environment or memory, because the key has to be available to the process. That is the same bar as credential_encryption_key.
I'm happy to implement it as a PR if the design is acceptable. I'd like your view first on the key setting name, whether enc:v1 envelopes in the existing bucket (versus a new bucket) fit your migration rules, and whether the shared helper should live under internal/secret or a new package.
Alternatives considered
- Rely on disk or volume encryption and file permissions. Fine for a laptop, but it does not help backups, snapshots or images, and it is not visible to the operator as a control.
- Store the tokens in the OS keyring. The keyring has no backend in a headless Linux box or a container, which is where the Server edition and Docker image run.
- Stop persisting refresh tokens. Forces a browser re-login for every upstream on each restart, which defeats unattended use.
Which edition?
Both (personal and server).
- I searched existing issues and discussions for a similar request (nothing found for OAuth token encryption; related:
docs/features/idp-token-storage.mdcovers the Server edition's per-user store only)
Activity
Dumbris commentedon Oct 20, 2026
Thanks, this is a well-scoped proposal, and it also exposed that our own docs claim the tokens are encrypted in the keyring, which they are not; that gets fixed either way. Before we settle the design, which threat are you mainly after: copies of the database in backups and snapshots, or something running next to the proxy as the same user? The first is what this protects; the second needs the data-directory work in #1704 as well, so it changes how we word it. And would you hold the key in an env var, a mounted file, or the keyring? I would sequence this after the ${file:} provider in #1706 so containers have a way to deliver the key.
james-crowley commentedon Oct 20, 2026
Thanks. The threat I am after is copies of the database: disk snapshots and images of the VM (we run on cloud instances), backups, and a disk that is mounted elsewhere. Something running next to the proxy as the same user is a separate problem that I now think is handled by #1704 (docker isolation, socket off), so wording it as 'protects copies at rest, not a process with the key' is right for us. For the key, a mounted file read through
${file:}fits best (systemdLoadCredential, Docker or Kubernetes secrets); an env var would be acceptable as a fallback, and the keyring does not exist on a headless box. Sequencing it after #1706 makes sense to me.Dumbris commentedon Nov 11, 2026
Thanks for answering both questions, and sorry for the slow reply. The design is settled in Spec 123 (#1886).
Threat. A copy of
config.dbat rest: backups, disk or VM snapshots, images, a disk mounted elsewhere. It does not cover anything that can read the key, such as a same-user process. A snapshot is only protected if the key is not readable on that same disk, for exampleLoadCredentialEncrypted=, tmpfs secrets or a secret store.Key. Opt-in
oauth_token_encryption_key, normally a${file:/run/...}reference.MCPPROXY_OAUTH_TOKEN_ENCRYPTION_KEYand..._FILEoverride it. The keyring is optional.What is encrypted. Each whole
oauth_tokensrecord (access token, refresh token, DCR client secret), AES-256-GCM, bound to its row, asenc:v1envelopes in the existing bucket. The helper is a new leaf package, separate from the broker store.Migration. Existing rows are sealed at startup. Older backups stay plaintext. A wrong or missing key is reported and never deletes tokens. A decrypt command is the downgrade path.
Out of scope for now. One-step rotation, the broker store, other secrets.
The docs that say tokens are in the keyring are wrong. That correction ships first as its own PR.
docs(spec): address round-2 review of oauth token encryption spec
docs(spec): Spec 123 encrypt upstream OAuth tokens at rest (#1886)
docs(oauth): correct where upstream OAuth tokens are stored (#1887)
feat(oauth): opt-in encryption of upstream OAuth tokens at rest (#1888)
feat(auth): doctor section, auth tokens commands and login pre-flight…
Dumbris commentedon Nov 22, 2026
Shipped as Spec 123: opt-in encryption of the upstream OAuth rows (#1888) and the operator surfaces, the doctor section and the
auth tokenscommands (#1891). Docs: https://docs.mcpproxy.app/features/oauth-token-encryption/ — one caveat from there: a disk snapshot is protected only when the key does not live on the same disk.