Skip to content

Enforce 0600 permissions on secret files#4

Open
wydrox wants to merge 1 commit intomainfrom
chore/secrets-file-permissions
Open

Enforce 0600 permissions on secret files#4
wydrox wants to merge 1 commit intomainfrom
chore/secrets-file-permissions

Conversation

@wydrox
Copy link
Copy Markdown
Owner

@wydrox wydrox commented Apr 20, 2026

Summary

  • Files under ~/.martmart-cli/ (session tokens + config.json) hold secrets; ensure they are written with 0600 mode on every save.
  • os.WriteFile honours the mode argument only when it creates a new file, so a follow-up os.Chmod(path, 0o600) is added in config.Save and session.SaveProvider to narrow permissions on pre-existing files that may have been left world-readable by older builds.
  • Adds permission round-trip tests (fresh write + overwrite-with-wider-mode) for both the Frisco and Delio session files and the shared config file, and mentions the guarantee in SECURITY.md.

Test plan

  • go vet ./...
  • go test ./... -race
  • go build -o bin/martmart ./cmd/martmart then ./bin/martmart --help and ./bin/martmart config show
  • Manual: HOME=$(mktemp -d) ./bin/martmart config set --rate-limit-rps 2, then stat confirms -rw-------; repeating with a chmod 0644 between saves confirms permissions are narrowed back to -rw-------.

Session files and config.json stored under ~/.martmart-cli/ contain bearer
tokens, refresh tokens, and cookies that effectively grant API access. Ensure
they are never world- or group-readable:

- Call os.Chmod(path, 0600) after os.WriteFile in config.Save and
  session.SaveProvider, since os.WriteFile only honours the mode argument
  when it creates a new file — pre-existing files keep their old mode and
  need an explicit chmod to be narrowed.
- Add TestSave_EnforcesFileMode0600 and TestSaveProvider_EnforcesFileMode0600
  covering the fresh-write and overwrite paths for both Frisco and Delio
  session files plus the shared config file.
- Document the 0600 guarantee in SECURITY.md.
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