Skip to content

fix(redact): treat Hermes-home credential stores as secret-file reads - #158145

Open
hr1juldey wants to merge 1 commit into
NousResearch:mainfrom
hr1juldey:fix/redact-credential-file-basenames
Open

hr1juldey wants to merge 1 commit into
NousResearch:mainfrom
hr1juldey:fix/redact-credential-file-basenames

Conversation

@hr1juldey

Copy link
Copy Markdown

TL;DR for the reviewer

cat ~/.hermes/auth.json reached the model context in cleartext while cat ~/.hermes/config.yaml was redacted: _is_secret_file_arg knew .env/rc files, .netrc-class stores, and config.yaml-under-.hermes — but Hermes' own credential stores (auth.json, .anthropic_oauth.json, auth/google_oauth.json, webhook_subscriptions.json, secret-cache stores) were on no list. This is the issue's part 1 (allowlisted-reader name matching); parts 2 (non-allowlisted readers) and 3 (egress heuristic) are deliberately left out to keep the blast radius minimal.

One-line diff summary: one anchored arm in _is_secret_file_arg, driven by the same inventory the file tools hard-deny — imported, not copied.

Related issue & credit

Fixes #157915 (part 1) — reported by @kauansb (whose follow-up comment independently confirmed the content-shape gap).

Root cause

agent/redact.py:1678-1684: _FILE_READ_COMMANDS readers gate redact_terminal_output's secret-file pass via _command_reads_secret_file → _is_secret_file_arg. That matcher (before) matched:

  • .env/.envrc/shell rcs — any path
  • HOME_CREDENTIAL_FILES (.netrc, .pgpass, …) — any path
  • config.yaml — only under .hermes / $HERMES_HOME / resolved Hermes home

…while agent/file_safety.py:468-470 (_CREDENTIAL_FILE_NAMES) maintains the authoritative list of Hermes-home credential stores for the file tools — a list redact.py never consulted. Net effect: the most credential-dense file in ~/.hermes was the one file the terminal redactor didn't classify.

The change (agent/redact.py, +16/−3)

Risks & mitigations

Risk Mitigation
Over-redaction of legitimate output Anchored matching (.hermes/$HERMES_HOME/resolved home only); negative test asserts /home/user/myapp/auth.json stays untouched.
List drift between redact and file tools The list is imported, not duplicated.
Write-back corruption (the #35519 hazard) Unchanged: secret_file masking already uses non-reusable sentinels.
Scope creep Parts 2/3 of the issue (python -c/jq readers, egress heuristic) explicitly not attempted here — each deserves its own measured false-positive review.

How to cross-review

  1. Read the diff — one arm + one import + docstring.
  2. Run the tests: uv run pytest tests/agent/test_redact.py tests/agent/test_redact_credential_stores.py tests/hermes_cli/test_credential_store_lists.py -q → 315 + 53 passed. The last file pins SECRET_CACHE_STORES/HOME_ENV_FILES contents, so inventory drift would fail there too.
  3. Attack it: python -c "from agent.redact import redact_terminal_output as r; print(r('{\"api_key\": \"sk-or-v1-abc123def456ghi789jkl\"}', 'cat ~/.hermes/auth.json'))" → token masked. Same call with 'cat /home/user/myapp/auth.json' → unchanged.
  4. Cross-check the anchor logic against the existing config.yaml arm directly below the new code — same anchors by design.

Verification evidence

  • Python 3.14.9, Linux x86_64, deps via uv sync --group dev --group test --frozen; ast-grep post-check; no nested control flow; no inline regexes.

Checklist

@hr1juldey

hr1juldey commented Nov 20, 2026 •

Copy link
Copy Markdown
Author

@coderabbitai review

@kauansb (issue reporter) — this is part 1 of your #157915: the allowlisted-reader name-matching half (cat ~/.hermes/auth.json in cleartext). Parts 2 (non-allowlisted readers like python -c/jq) and 3 (egress heuristic) are intentionally not in this PR — each deserves its own false-positive review.

How the bug was detected: compared _is_secret_file_arg against agent/file_safety._CREDENTIAL_FILE_NAMES (the list the file tools hard-deny) — auth.json, .anthropic_oauth.json, auth/google_oauth.json, webhook_subscriptions.json and the secret-cache stores were on the file-tool denylist but on no redaction list, so cat ~/.hermes/auth.json passed through unredacted while cat ~/.hermes/config.yaml was masked.

How it was fixed: one anchored arm in _is_secret_file_arg, delegating to agent/redact_hermes_home.is_hermes_credential_store — the file-safety inventory imported there (no duplicated list → no drift; the helper lives in the topic module that already holds _is_under_hermes_home, keeping redact.py under its code-health cap), anchored exactly like the config.yaml arm (.hermes segment / $HERMES_HOME / resolved home — never a project's own auth.json). secret_file=True then re-enables the existing JSON assignment pass, so values are masked with non-reusable sentinels (#35519 policy).

How it was tested: 2 new tests — uv run pytest tests/agent/test_redact.py tests/agent/test_redact_credential_stores.py tests/hermes_cli/test_credential_store_lists.py -q → 315 + 53 passed (the last file pins the shared inventory, so drift would fail CI).

Verify it yourself: python -c "from agent.redact import redact_terminal_output as r; print(r('{\"api_key\": \"sk-or-v1-abc123def456ghi789jkl\"}', 'cat ~/.hermes/auth.json'))" → masked; same command against '/home/user/myapp/auth.json' → unchanged.

@alt-glitch alt-glitch added area/auth Authentication, OAuth, credential pools P3 Low — cosmetic, nice to have tool/terminal Terminal execution and process management type/security Security vulnerability or hardening labels Nov 20, 2026
_is_secret_file_arg knew .netrc/.pgpass/.env and config.yaml-under-.hermes,
but auth.json, .anthropic_oauth.json and auth/google_oauth.json were not on
any list — 'cat ~/.hermes/auth.json' reached the model context in cleartext
while the same read of config.yaml was redacted (NousResearch#157915).

The stores now match via the same inventory the file tools hard-deny
(agent/file_safety._CREDENTIAL_FILE_NAMES), anchored like config.yaml: a
.hermes segment, $HERMES_HOME or the resolved Hermes home, so a project's
own auth.json is unaffected. secret_file=True re-enables the JSON
assignment pass, so the token values are masked.

Fixes NousResearch#157915 (part 1: allowlisted-reader name matching)
@hr1juldey
hr1juldey force-pushed the fix/redact-credential-file-basenames branch from 2904649 to 57785eb Compare November 20, 2026 07:37
@alt-glitch alt-glitch added the comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint label Nov 20, 2026
@hr1juldey

Copy link
Copy Markdown
Author

@teknium1 — cordial ping on this one too, whenever bandwidth allows. It closes the cleartext half of #157915: cat ~/.hermes/auth.json reached model context unredacted while cat ~/.hermes/config.yaml was masked — the fix reuses the exact inventory your file tools already hard-deny (imported, not copied, so the lists can't drift), anchored to the Hermes home so a project's own auth.json is untouched.

Same note as its siblings: the first-time-contributor CI runs across today's five PRs are queued in action_required awaiting a maintainer approval click, after which your normal CI gate takes over. Happy to rework anything — the PR body carries the root cause, risk table, and cross-review steps so it should be a quick read.

Thanks for the incredible merge pace on this repo — it's what makes contributing here worth the care. 🙏

This branch has not been deployed

No deployments
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/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have 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.

[Bug]: Secret redaction bypass: auth.json via non-allowlisted readers, and exfiltration by literal value

2 participants