Skip to content

fix(install): restrict ~/.hermes/.env to owner-only permissions (0600)#25560

Closed
alaamohanad169-ship-it wants to merge 1 commit into
NousResearch:mainfrom
alaamohanad169-ship-it:fix/install-env-permissions
Closed

fix(install): restrict ~/.hermes/.env to owner-only permissions (0600)#25560
alaamohanad169-ship-it wants to merge 1 commit into
NousResearch:mainfrom
alaamohanad169-ship-it:fix/install-env-permissions

Conversation

@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor

Summary

Fixes #25477 — installer leaves ~/.hermes/.env world/group-readable, exposing API keys.

Root Cause

The installer uses cp and touch to 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 explicit chmod was applied after file creation, leaving platform tokens, API keys, and Slack tokens visible to other users on the system.

The Python layer (_secure_file() in hermes_cli/config.py) already applies 0o600 on every subsequent write via save_env_value() and sanitize_env_file() — but the install script's initial file creation was never covered.

Fix

Add chmod 0600 "$HERMES_HOME/.env" immediately after the file is created in copy_config_templates(), with a || true fallback 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 else branch), 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

# Before — freshly installed on Ubuntu 24.04 (umask 0022)
$ ls -la ~/.hermes/.env
-rw-rw-r-- 1 plumline plumline 1234 May 14 07:00 ~/.hermes/.env

# After
$ ls -la ~/.hermes/.env
-rw------- 1 plumline plumline 1234 May 14 07:00 ~/.hermes/.env

Testing

  • bash -n scripts/install.sh → OK (shell syntax valid)
  • Functional test in tmpdir confirms 0600 permissions applied correctly

The installer creates ~/.hermes/.env via cp or touch, 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
explicit chmod was applied after file creation, leaving API keys and
tokens visible to other users on the system.

Add chmod 0600 immediately after .env creation in copy_config_templates(),
with a || true fallback for NixOS/containers where the activation script
owns permissions. Also tightens permissions when the file already exists,
so users with 0664 on disk are hardened on next upgrade.

Fixes NousResearch#25477
@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists area/config Config system, migrations, profiles labels May 14, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #25497 — which is a superset (also covers setup-hermes.sh + adds tests). Both fix #25477. See also #25533 and #25562.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks — closing in favor of #25562 (vanthinh6886) which lands the same 0600 fix for #25477 plus also patches the Python _write_env_vars write path so re-saves through hermes setup memory get the right perms too. Both PRs noticed the same issue; we're going with the broader one. Crediting both contributors.

@teknium1 teknium1 closed this May 14, 2026
@alaamohanad169-ship-it alaamohanad169-ship-it deleted the fix/install-env-permissions branch June 6, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Installer leaves ~/.hermes/.env at file mode 0664 — group/world readable, secrets exposed

3 participants