fix(install): restrict ~/.hermes/.env to owner-only permissions (0600) (#25477)#25533
Closed
Bartok9 wants to merge 1 commit into
Closed
fix(install): restrict ~/.hermes/.env to owner-only permissions (0600) (#25477)#25533Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
The installer left ~/.hermes/.env at mode 0664 — group- and world-readable — exposing secrets (ANTHROPIC_API_KEY, Slack tokens, Plane API tokens, etc.) to every user on multi-user systems. Root cause: cp and touch both inherit the process umask (typically 0022 on Ubuntu, yielding 0644; or 0002 in some server environments, yielding 0664). No explicit chmod was applied after file creation. Fix: add chmod 0600 immediately after the file is created OR found to already exist. The fallback (|| true) is intentional: on NixOS managed installs or containers the activation script owns permissions and a chmod may fail or be a no-op — that is already handled by the is_managed() guard in the Python layer. The || true keeps the installer from exiting on those platforms. The tighten-on-existing-file branch also fixes users who installed an earlier version and already have 0664 on disk — their permissions are hardened on the next upgrade. The Python layer (_secure_file in hermes_cli/config.py) already applies 0o600 on every write through save_env_value() and sanitize_env_file(), but the install script's initial creation was never covered. Fixes NousResearch#25477
Collaborator
This was referenced May 14, 2026
9 tasks
Contributor
|
Closing as superseded by #25779. Triage notes (high confidence): Thanks for the contribution — the underlying problem this PR addresses has been resolved by the linked PR on current main. If you believe this was closed in error, please comment and we'll reopen. (Bulk-closed during a CLI PR triage sweep.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #25477 — installer leaves
~/.hermes/.envworld/group-readable, exposing API keys.Root Cause
The installer uses
cpandtouchto create~/.hermes/.env, both of which inherit the process umask. On Ubuntu (umask 0022) the result is 0644; on some server environments with umask 0002 the result is 0664. No explicitchmodwas applied after file creation, leaving platform tokens, API keys, and Slack tokens visible to other users on the system.The Python layer (
_secure_file()inhermes_cli/config.py) already applies 0o600 on every subsequent write viasave_env_value()andsanitize_env_file()— but the install script's initial file creation was never covered.Fix
Add
chmod 0600 "/.env"immediately after the file is created incopy_config_templates(), with a|| truefallback to stay safe on NixOS managed installs and containers where the activation script owns permissions.The fix also tightens permissions when the file already exists (the
elsebranch), so users who installed a previous version and have 0664 on disk are hardened on their next upgrade — without any user action required.Before / After
Testing