Conversation
config.db stores OAuth access/refresh tokens and DCR client secrets as plain JSON, but was created with mode 0644 and backed up with 0644. - Open the database 0600. - Tighten an existing group/world-readable database on open, clearing only the 0o077 bits so a stricter owner mode is never widened. This is best-effort: failures are logged at debug level and never block startup. - Stage Backup in an owner-only temp file next to the destination and rename it into place. bbolt's Tx.CopyFile opens with O_CREATE|O_TRUNC, so its mode argument is ignored for an existing destination and the database bytes would land in whatever permissions a stale backup carried. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Deploying mcpproxy-docs with
|
| Latest commit: |
f623533
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0170deba.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-db-file-mode-0600.mcpproxy-docs.pages.dev |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 35814351800 --repo smart-mcp-proxy/mcpproxy-go
|
tightenFilePermissions logged both its failure branches (stat and chmod) at Debug, which sits below the project's default zap level (Info). On a legacy 0644 config.db where chmod cannot succeed (read-only mount, macOS uchg/schg flag, SELinux/AppArmor denial), mcpproxy started normally and the DB - which holds OAuth tokens and DCR client secrets - stayed silently world-readable with no operator-visible signal that the migration didn't take effect. Not failing startup is still correct; the log level wasn't. Bump the two failure branches to Warn and the one-time successful-migration message to Info so this is visible in default-level logs, per second-lens review of PR #1342. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Second-lens review (zcode/GLM per the current maintainer directive) verified two findings against the code; applied the one that was small and low-risk, left the other as an out-of-diff follow-up: Applied: Not applied (out of scope for this PR): Verified: |
What
~/.mcpproxy/config.dbstores OAuth access/refresh tokens and DCR client secrets as plain JSON (internal/storage/models.go), but was created with mode0644and backed up with0644. This PR makes the database and its backups owner-only.bbolt.Opennow passes0600.0o077bits so a stricter owner mode is never widened. The mode argument tobbolt.Openapplies only at creation and bbolt never chmods an existing file, so this migration is the entire fix for anyone who already has a database.Backupno longer usesTx.CopyFiledirectly.CopyFileopens the destination withO_CREATE|O_TRUNC, so its mode argument is ignored when the file already exists — a chmod afterwards comes too late, since the database bytes would already have landed in whatever permissions a stale backup carried. The copy is now staged in an owner-only temp file next to the destination and renamed into place.Why
Scoped honestly:
~/.mcpproxyis created0700(internal/config/loader.go), so in a default install another local user cannot traverse to the0644database. This is defense-in-depth, and the 0700 directory is not an invariant — theMkdirAllis skipped whenDataDirstill contains an unresolved${...}, andMkdirAllnever tightens an already-existing directory.Backupcurrently has no production callers — it is reachable only as an exported method declared onappctx.StorageInterface. The0644copy was therefore a latent hazard on a public API, not a live leak.Out of scope, deliberately:
cmd/mcpproxy/db_cmd.gocompact/repair propagate the on-disk mode on purpose (info.Mode().Perm(), with a comment explaining bbolt will not chmod an existing file). They become correct by propagation after this change and are untouched.~/.mcpproxy/index.bleve/and the log files (documented as0644) are not covered here.How verified
TDD: five new tests in
internal/storage/bbolt_file_mode_test.go(fresh create, migration of an existing0644database, owner-bit preservation, backup to a new destination, backup over a pre-existing0644destination), each confirmed failing before the fix. They are skipped on Windows, whereos.Chmodonly toggles the read-only bit andos.Statreports0666.Also verified against a real
mcpproxy serveinstance on a scratch data dir: a freshconfig.dblands-rw-------; loosening it to0644and restarting migrates it back withTightened permissions on ... from 0644 to 0600at debug level; a third start on an already-0600database logs nothing.Cross-reviewed with
codex gpt-5.6-solover three rounds; two rounds returned blocking findings on the backup path (both verified againstgo.etcd.io/bbolt@v1.5.0/tx.gobefore fixing), the third returned APPROVE.🤖 Generated with Claude Code