Generate valid secrets in the CLI bootstrap#3619
Generate valid secrets in the CLI bootstrap#3619dipeshbabu wants to merge 1 commit intosimstudioai:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview These generated values are injected into the Written by Cursor Bugbot for commit 96370cc. This will update automatically on new commits. Configure here. |
Greptile SummaryThis PR replaces hardcoded placeholder secrets ( Key issues found:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI as CLI (index.ts)
participant Docker
participant DB as PostgreSQL Container
participant RT as Realtime Container
participant App as App Container
User->>CLI: npx simstudio
CLI->>CLI: generateHexSecret() x4<br/>(betterAuthSecret, encryptionKey,<br/>internalApiSecret, apiEncryptionKey)
CLI->>Docker: cleanupExistingContainers()
Docker-->>CLI: old containers removed
CLI->>Docker: run pgvector/pgvector:pg17
Docker-->>DB: start (volume: ~/.simstudio/data/postgres)
CLI->>Docker: run migrations container
Docker-->>CLI: migrations complete
CLI->>Docker: run realtime container<br/>-e BETTER_AUTH_SECRET<br/>-e INTERNAL_API_SECRET
Docker-->>RT: start
CLI->>Docker: run app container<br/>-e BETTER_AUTH_SECRET<br/>-e ENCRYPTION_KEY<br/>-e INTERNAL_API_SECRET<br/>-e API_ENCRYPTION_KEY
Docker-->>App: start
Note over CLI,App: ⚠️ On restart: new secrets are<br/>generated, but DB volume persists.<br/>Old encrypted data becomes unreadable.
Last reviewed commit: 96370cc |
| const betterAuthSecret = generateHexSecret() | ||
| const encryptionKey = generateHexSecret() | ||
| const internalApiSecret = generateHexSecret() | ||
| const apiEncryptionKey = generateHexSecret() |
There was a problem hiding this comment.
Secrets regenerated on every restart — encrypted data becomes unreadable
New secrets are generated on every invocation of npx simstudio. Because cleanupExistingContainers() stops and removes the old containers but the PostgreSQL data volume at ~/.simstudio/data/postgres is persisted on disk, the next startup uses a different ENCRYPTION_KEY and API_ENCRYPTION_KEY against a database that already has data encrypted under the previous keys. This will silently make any previously-encrypted credential/secret rows unreadable.
Similarly, BETTER_AUTH_SECRET changing on every restart will invalidate all existing user sessions, forcing re-authentication every time the CLI is re-run.
The fix is to persist the generated secrets to disk the first time they are created and reload them on subsequent runs. A simple approach:
// Persist/load secrets from ~/.simstudio/secrets.json
// On first run: generate all four values and write the file with mode 0o600
// On subsequent runs: read the file and reuse the same valuesKey requirements:
- The secrets file should only be created once (no regeneration if the file already exists)
- The file permissions should be restricted to owner-only (
0o600) to avoid leaking secrets to other users on the same machine - The
~/.simstudio/directory already exists at this point in the flow (thedataDirmkdirruns earlier), so writing there is safe
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| const betterAuthSecret = generateHexSecret() | ||
| const encryptionKey = generateHexSecret() | ||
| const internalApiSecret = generateHexSecret() | ||
| const apiEncryptionKey = generateHexSecret() |
There was a problem hiding this comment.
Secrets regenerated on restart, corrupting persisted encrypted data
High Severity
ENCRYPTION_KEY, API_ENCRYPTION_KEY, BETTER_AUTH_SECRET, and INTERNAL_API_SECRET are freshly generated on every CLI invocation, but the PostgreSQL database is persisted across runs via a host volume at ~/.simstudio/data. On a second boot, the new random secrets won't match the ones used to encrypt existing data, making all previously encrypted values (credentials, API keys, auth sessions) unreadable. The secrets need to be persisted to disk (e.g., alongside the data directory) and reused on subsequent runs.


Summary
Generate valid runtime secrets for the
simstudioDocker bootstrap instead of passing placeholder values.Problem
The CLI currently starts the app with placeholder secrets:
BETTER_AUTH_SECRET=your_auth_secret_hereENCRYPTION_KEY=your_encryption_key_hereThis can break the one-command startup flow because the app expects real secrets, and the encryption layer requires a 64-character hex key.
Changes
BETTER_AUTH_SECRETat runtimeENCRYPTION_KEYas a 32-byte hex stringINTERNAL_API_SECRETandAPI_ENCRYPTION_KEYfor parity with local compose defaultsValidation
cd packages/cli && bun run type-checknpx simstudioon a clean Docker setup and confirm the app boots successfully