Skip to content

fix(state): restrict sensitive store file permissions (salvage #30917) - #31469

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-f9dd4507
May 24, 2026
Merged

fix(state): restrict sensitive store file permissions (salvage #30917)#31469
teknium1 merged 1 commit into
mainfrom
hermes/hermes-f9dd4507

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #30917 by @Hinotoi-agent onto current main, with the api_server.py rework.

Summary

response_store.db (api server conversation history with tool payloads, prompts, results) and webhook_subscriptions.json (per-route HMAC secrets) were created mode 0o644 under typical umask 022 — readable by other local users on shared boxes. Both now end up 0o600 owner-only.

Changes

  • gateway/platforms/api_server.py: ResponseStore tightens the DB and WAL/SHM sidecars to 0o600 once at __init__ (after the initial commit creates the sidecars), then trusts the inode.
  • hermes_cli/webhook.py: _save_subscriptions writes via tempfile.mkstemp (creates with 0o600), chmods the temp before the atomic rename, then re-asserts 0o600 on the destination so an existing permissive file gets narrowed on next save.
  • Tests for both stores covering (a) creation under permissive umask and (b) narrowing an existing 0o644 file. skipif os.name=='nt' since POSIX mode bits are platform-specific.

Salvage scope

Original PR added a _commit() wrapper that called _secure_file_mode() after every put/get/delete — chmod syscall per request on a hot api_server path. Reworked to chmod-once at __init__ since SQLite preserves mode bits across writes (the inode is what matters, not the open fd). All the original PR's test intent is preserved.

Test plan

pytest tests/gateway/test_api_server.py tests/hermes_cli/test_webhook_cli.py  # 170 passed

Co-authored-by: Hinotoi-agent paperlantern.agent@gmail.com

Closes #30917

response_store.db (api server) holds conversation history including tool
payloads, prompts, and results. webhook_subscriptions.json holds per-route
HMAC secrets. Under a permissive umask (e.g. 0o022, default on most
distros) both files were created mode 0o644 — readable by other local
users on shared boxes.

- gateway/platforms/api_server.py: ResponseStore tightens itself + WAL/SHM
  sidecars to 0o600 after __init__, then trusts the inode. (Original
  contributor patch chmod'd after every _commit() — wasteful on a hot
  api_server path; chmod-on-create is sufficient since SQLite preserves
  mode bits across writes.)

- hermes_cli/webhook.py: _save_subscriptions writes via tempfile.mkstemp
  (which itself creates the file with 0o600), chmods the temp before the
  atomic rename, and re-asserts 0o600 on the destination so an existing
  permissive file from before this fix gets narrowed.

Tests cover (a) creation under permissive umask leaves 0o600 and (b) an
existing 0o644 webhook_subscriptions.json gets narrowed on next save.
Tests guarded with skipif os.name=='nt' since POSIX mode bits don't apply
on Windows.

Salvaged from PR #30917 by @Hinotoi-agent. Reworked the api_server.py
side from chmod-on-every-commit to chmod-on-create.

Co-authored-by: teknium1 <127238744+teknium1@users.noreply.github.com>
@teknium1
teknium1 merged commit 3bace07 into main May 24, 2026
19 of 22 checks passed
@teknium1
teknium1 deleted the hermes/hermes-f9dd4507 branch May 24, 2026 11:55
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-f9dd4507 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9077 on HEAD, 9077 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4834 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery comp/cli CLI entry point, hermes_cli/, setup wizard labels May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery 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