Skip to content

fix(security): create terminal env snapshots owner-only (0600) - #60199

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-5e978399
Jul 7, 2026
Merged

fix(security): create terminal env snapshots owner-only (0600)#60199
teknium1 merged 2 commits into
mainfrom
hermes/hermes-5e978399

Conversation

@teknium1

@teknium1 teknium1 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Terminal session snapshot files (hermes-snap-*.sh) are now created owner-only (0600) instead of inheriting the process umask, closing a local credential-disclosure path on shared hosts.

Root cause: BaseEnvironment persists the shell environment across spawn-per-call commands via export -p > redirects, which inherit the ambient umask — with the common 0022/0002 defaults the snapshot landed world-readable in /tmp while containing every exported env var (including operator-set secrets like BWS_ACCESS_TOKEN that the provider-env blocklist never covers).

This reverses the earlier by-design call on #48441 / #41278 / #57386: /tmp is world-traversable unlike ~/.hermes, so on multi-user hosts the snapshot was the one copy of secrets another local user could actually open, and reports kept recurring. Salvages @egilewski's clean two-file commit from #57386 (co-authored by @andrewhomeyer, original fix in #20056) with authorship preserved.

Changes

  • tools/environments/base.py: umask 077 before the bootstrap snapshot dump in init_session(), and after the user's command (before the re-dump) in _wrap_command() — the user command itself keeps its own ambient umask
  • tests/tools/test_base_environment.py: 6 new permission tests (TestSnapshotPermissions)
  • scripts/release.py: AUTHOR_MAP entry for co-author

Validation

Check Result
scripts/run_tests.sh tests/tools/test_base_environment.py 32/32 pass
Live local E2E (umask 0002) snapshot 0600 after init_session AND post-command re-dump
Live local E2E env persistence export survives across calls; user command still sees umask 0002
Live Docker E2E (real ubuntu:24.04 container) snapshot 600 in-container at both write sites, persistence intact
Docker cross-user risk none — all docker exec calls use the container's single exec user (docker.py _run_bash)

Closes #48441.

Infographic

shell-snapshots-owner-only

egilewski and others added 2 commits July 7, 2026 04:31
BaseEnvironment writes shell snapshots and cwd metadata through the process
umask. With a common 022 umask, snapshot files containing exported environment
state landed at mode 0644 even though they can include env-carried credentials
from the parent process.

Set umask 077 only around Hermes metadata writes: the initial snapshot
bootstrap and the post-command snapshot/cwd refresh. User commands still run
under the caller's original umask, while Hermes-owned snapshot and cwd files
are created owner-only.

This intentionally does not copy the source PR's global orphan sweep; deleting
all matching /tmp snapshot files could interfere with concurrent Hermes
processes. The security-critical local disclosure fix is the file mode clamp.

This is salvageable because the source report still identifies a concrete
credential-disclosure path, but the safe subset is smaller than the original
proposal: clamp only the Hermes-owned snapshot writes and leave process-wide
cleanup, user command umask, and concurrent sessions alone.

Salvages source PR: #20056
Related issue: #48441

Co-authored-by: Andrew Homeyer <andrew@hndl.app>
@alt-glitch alt-glitch added type/security Security vulnerability or hardening P1 High — major feature broken, no workaround tool/terminal Terminal execution and process management area/auth Authentication, OAuth, credential pools sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data labels Jul 7, 2026
@teknium1
teknium1 merged commit 685f527 into main Jul 7, 2026
31 checks passed
@teknium1
teknium1 deleted the hermes/hermes-5e978399 branch July 7, 2026 12:22
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 P1 High — major feature broken, no workaround sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data tool/terminal Terminal execution and process management type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Terminal session snapshots leak .env secrets to disk in plaintext (cache/terminal/hermes-snap-*.sh)

3 participants