Skip to content

fix(security): write secret-bearing files 0600 over a pre-existing 0644 file (Closes #2105) - #2203

Merged
bc037 merged 2 commits into
mainfrom
fix/2105-secret-write-0600
Dec 3, 2026
Merged

bc037 merged 2 commits into
mainfrom
fix/2105-secret-write-0600

Conversation

@bc037

@bc037 bc037 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Related Issue

Closes #2105

Description

Four writers of secret-bearing files used an in-place writeFileSync. Its mode option applies only when the file is created. A pre-existing 0644 file therefore stayed 0644 (readable by other users).

File Writer
~/.amico/slack-app.json (Slack client_secret) amicode_service/connections.ts and the overlay copy of connections.ts
~/.amico/ops/server/standalone.json (server password) writeHandshake in server_handshake.ts (its comment said atomic; it was not)
opencode auth.json and account.json (provider API keys) disconnectProviders in credential_scanner.ts

All now use the existing atomicWriteFileSync (0600 tmp file + rename). Rename swaps the inode, so the result is 0600 even over a 0644 file. No new helper.

Changes: the four writers above, test/secret_write_modes.test.ts (new, written first), and app-bundle/manifest.json (one file hash refreshed with refresh_manifest.mjs, because the overlay connections.ts changed).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Config / infrastructure (CI, tooling, build, docs)
  • Breaking change (fix or feature that changes existing behavior)

Verification

  • pnpm -r run build exits 0
  • pnpm -r run test exits 0 (or pnpm -r run typecheck if tests aren't relevant)
  • Manual testing described below

pnpm -r run typecheck passes. The new test pre-creates each file at 0644 in a temp HOME and asserts 0600 after the write. In WSL (Linux) it failed first (mode 420 instead of 384) and passes with the fix. The related server, handshake, scanner and service tests also pass in WSL (904 tests).

Manual Testing Notes

  • The mode tests skip on Windows, which has no 0644/0600 distinction. CI (Linux and macOS) runs them. On Windows, three older tests (two handshake mode checks, one XDG path) fail on unchanged main too.
  • The overlay copy of connections.ts runs inside the engine and cannot be imported from the extension tests. It has a source-level check only, not a behavior test. The extension copy has the behavior test.
  • Not covered: other secret writers that the fix(cloud): cloud.json is written 0644 (ADR-0001 requires 0600 for secrets) #2096 audit did not list. I did not search for more.

🤖 Generated with Claude Code

…44 file

Four writers used an in-place writeFileSync. Its `mode` option applies only
when the file is created, so a pre-existing 0644 file stayed 0644:

- slack-app.json (client_secret), in the extension service and the overlay copy
- standalone.json (server password handshake); its comment said atomic, it was not
- auth.json and account.json (provider API keys) in disconnectProviders

All now go through atomicWriteFileSync (0600 tmp file + rename). The new test
pre-creates each file at 0644 in a temp HOME and asserts 0600 after the write.
It failed first (420 instead of 384) and passes after. The overlay copy cannot
be imported from the extension tests, so it gets a source-level check.

Closes #2105

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b1440ce5-0e35-4a58-b13a-2e276e24cd94
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

The slack-app.json fix edits the overlay copy of connections.ts, so its hash in
manifest.json was stale. drift_gate (app-bundle-gate) and the notturno drift
step (fast) failed on it. Ran materialize.mjs and refresh_manifest.mjs; the
manifest changes one file hash and extracted_at.

Refs #2105

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bc037
bc037 marked this pull request as ready for review December 3, 2026 00:54
@bc037
bc037 merged commit a1942d0 into main Dec 3, 2026
12 checks passed
@bc037
bc037 deleted the fix/2105-secret-write-0600 branch December 3, 2026 00:55
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.

fix(security): three secret-bearing writes do not guarantee 0600 (slack-app.json, standalone.json, auth.json/account.json)

2 participants