Skip to content

Restrict permissions on stored credentials file - #65

Merged
mattiasgeniar merged 1 commit into
mainfrom
fix/credential-file-permissions
Oct 22, 2026
Merged

mattiasgeniar merged 1 commit into
mainfrom
fix/credential-file-permissions

Conversation

@Nelwhix

@Nelwhix Nelwhix commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CredentialStore wrote ~/.ohdear/config.json (which holds the API token in plain JSON) without setting a file mode, so it ended up 0644 inside a 0755 directory. On systems where the home directory isn't private, other local users could read the token.

  • Create the config directory with 0700 instead of 0755
  • Set config.json to 0600 before writing the contents, so the token is never in a world-readable file, and write with LOCK_EX
  • Existing 0644 files from earlier versions get tightened the next time the CLI writes them (login / logout)

Existing ~/.ohdear directories aren't re-chmodded. The file itself is protected, and the path can be overridden with OHDEAR_CONFIG_FILE_PATH, so changing the permissions of a directory we didn't create seemed wrong.

Tests

  • New file is 0600 and the new directory is 0700
  • Existing 0644 file is tightened to 0600 on setToken
  • flush() leaves the file at 0600

Permission tests are skipped on Windows. composer test, composer analyse and Pint all pass.

The config file holding the API token was written with the default
mode (0644 under a typical umask) inside a 0755 directory, so other
local users could read the token when the home directory is not
private.

Create ~/.ohdear with 0700 and set config.json to 0600 before writing,
which also tightens files written by earlier versions on next write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Nelwhix
Nelwhix marked this pull request as ready for review October 21, 2026 21:05
@mattiasgeniar

Copy link
Copy Markdown
Contributor

Thanks!

@mattiasgeniar
mattiasgeniar merged commit 46b4488 into main Oct 22, 2026
11 checks passed
@mattiasgeniar
mattiasgeniar deleted the fix/credential-file-permissions branch October 22, 2026 09:16
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.

2 participants