Skip to content

fix(security): restore .env/auth.json/state.db with 0600 perms - #19699

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-8c54fd4a
May 4, 2026
Merged

fix(security): restore .env/auth.json/state.db with 0600 perms#19699
teknium1 merged 1 commit into
mainfrom
hermes/hermes-8c54fd4a

Conversation

@teknium1

@teknium1 teknium1 commented May 4, 2026

Copy link
Copy Markdown
Contributor

Salvage of #16199 onto current main.

Summary

hermes import was creating .env, auth.json, and state.db with the process umask (typically 0644) instead of 0600. zipfile.open() doesn't honor Unix mode bits stored in the archive, so imported secret files land world-readable on restore. Add an explicit chmod 0o600 for the known secret filenames after extract.

Validation

scripts/run_tests.sh tests/hermes_cli/test_backup.py -> passed

Original PR: #16199

`hermes import` was creating secret files with the process umask
(typically 0644) instead of 0600. zipfile.open() does not honor the
Unix mode bits stored in zip member external_attr; the restore loop
used open(target, "wb") which always falls back to umask.

Threat: silent privilege downgrade after a routine restore on
multi-user systems (shared dev boxes, CI runners, jump hosts) — any
local user could read API keys and OAuth tokens from ~/.hermes/.

Fix mirrors the convention already used at file creation
(hermes_cli/auth.py: stat.S_IRUSR | stat.S_IWUSR for auth.json).
The quick-snapshot restore path (restore_quick_snapshot) is
unaffected — it uses shutil.copy2 which preserves perms via
copystat().

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@teknium1
teknium1 merged commit 60c4bc9 into main May 4, 2026
7 of 10 checks passed
@teknium1
teknium1 deleted the hermes/hermes-8c54fd4a branch May 4, 2026 11:43
@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard area/auth Authentication, OAuth, credential pools labels May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/cli CLI entry point, hermes_cli/, setup wizard 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.

3 participants