Skip to content

chore(security): rotate MCP connector token (local dev)#238

Open
0xtsotsi wants to merge 1 commit into
CoreBunch:mainfrom
0xtsotsi:chore/rotate-mcp-token
Open

chore(security): rotate MCP connector token (local dev)#238
0xtsotsi wants to merge 1 commit into
CoreBunch:mainfrom
0xtsotsi:chore/rotate-mcp-token

Conversation

@0xtsotsi

Copy link
Copy Markdown

Adds bun run security:rotate-mcp to swap the connector in ./.env for a fresh bearer without printing either secret.

Why

The dev MCP connector token in ./.env was committed in plaintext. Even though the file is gitignored, it lived under the working tree and would be swept up by any backup/sync tool. The rotation helper:

  • Reads the old INSTATIC_MCP_TOKEN from ./.env.
  • Looks up the matching row in ai_mcp_connectors by hash (so an operator cannot rotate a token they don't already possess).
  • Generates a new token, opens a transaction that creates the replacement row, deletes the old one, and verifies both hashes inside the same transaction.
  • Writes the new token to ./.env (mode 0600) atomically via a temp file + rename(2).
  • Restores the old ./.env value on rollback only when the database proves the rollback happened — never overwrites after an ambiguous database outcome.

This is the local-dev rotation helper. The admin endpoint that returns the plaintext once is the production path. ./.env remains gitignored.

Files

  • scripts/rotate-mcp-token.ts (new)
  • package.json (one new script: security:rotate-mcp)

Verification

  • bun run security:rotate-mcp on a fresh checkout rotates the token and writes the new bearer to ./.env.
  • Old token returns 401 against the dev MCP endpoint; new token returns 200.
  • bun run lint clean.
  • tsc -b clean.

Adds `bun run security:rotate-mcp` to swap the connector in `.env`
for a fresh bearer. Reads the old hash from `ai_mcp_connectors`, runs
a transaction that creates the replacement row, deletes the old one,
and verifies both inside the same transaction. Restores the old
`INSTATIC_MCP_TOKEN` value on rollback only when the database still
proves the rollback happened.

This is the local-dev rotation helper; the admin endpoint that returns
the plaintext once is the production path. The .env file remains
gitignored.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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