Skip to content

chore(security): move dev SQLite database out of source tree and scrub PII#240

Open
0xtsotsi wants to merge 2 commits into
CoreBunch:mainfrom
0xtsotsi:chore/move-dev-db
Open

chore(security): move dev SQLite database out of source tree and scrub PII#240
0xtsotsi wants to merge 2 commits into
CoreBunch:mainfrom
0xtsotsi:chore/move-dev-db

Conversation

@0xtsotsi

Copy link
Copy Markdown

Why

The dev SQLite database used to live at ./.tmp/dev.db, under the working tree. The file contained PII (user email, argon2id password hash, active sessions, audit events, AI provider credentials). The PII has been scrubbed; the database is now written to a platform-native per-user data directory outside the source tree.

Changes

  • New server/secrets/dataPaths.ts with perUserDataDir(), defaultDevDbPath(), and defaultDevDbUrl() (Linux: $XDG_DATA_HOME/instatic/dev.db, macOS: ~/Library/Application Support/instatic/dev.db, Windows: %LOCALAPPDATA%\instatic\dev.db).
  • server/config.ts defaults DATABASE_URL to defaultDevDbUrl() when DATABASE_URL is unset.
  • scripts/dev.ts uses the same default.
  • INSTATIC_DATA_DIR overrides the per-user data dir.
  • scripts/db-drop.ts continues to work — it parses the URL through parseSqlitePath and now targets the per-user path.
  • .env.example documents the new behaviour and INSTATIC_DATA_DIR override.

Files

  • server/secrets/dataPaths.ts (new)
  • server/config.ts
  • scripts/dev.ts
  • .env.example

Verification

  • bun run lint clean.
  • tsc -b clean.
  • INSTATIC_ALLOW_DEV_KEY_AUTOGEN=1 PORT=3999 bun run dev:server boots cleanly, creates ~/Library/Application Support/instatic/dev.db (no file under ./.tmp/), and serves on port 3999.
  • The existing ./.tmp/dev.db* files have been deleted from the working tree to scrub the PII.
  • Production SQLite mode (compose.sqlite.yml) is unaffected — it always wrote to /app/data/cms.db on a named volume.

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.

…b PII

The dev SQLite database used to live at ./.tmp/dev.db, under the
working tree. PII in that file (user email, argon2id password hash,
active sessions, audit events) is now written to a platform-native
per-user data directory:

  - Linux:   $XDG_DATA_HOME/instatic/dev.db
             (default ~/.local/share/instatic/dev.db)
  - macOS:   ~/Library/Application Support/instatic/dev.db
  - Windows: %LOCALAPPDATA%\instatic\dev.db

The new server/secrets/dataPaths.ts module is a sibling of the
master-key path helper from the previous commit and exposes
`perUserDataDir()`, `defaultDevDbPath()`, and `defaultDevDbUrl()`.
`INSTATIC_DATA_DIR` overrides the per-user data dir for operators
who want dev state on an external volume.

`bun run dev` no longer creates any file under `./.tmp/` for the
database. `scripts/db-drop.ts` continues to work because it
parses the URL through `parseSqlitePath`; it now targets the
per-user path.

The existing ./.tmp/dev.db* files have been deleted from the
working tree to scrub the PII. Production SQLite mode
(`compose.sqlite.yml`) is unaffected — it always wrote to
`/app/data/cms.db` on a named volume.
@0xtsotsi
0xtsotsi force-pushed the chore/move-dev-db branch from af3d5a5 to d36b352 Compare July 22, 2026 20:24
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