The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: derive suggest globs from the raw command, class-key when redaction hits them
teknium11f08821bd0e4
diff --git a/hermes_cli/approvals_suggest.py b/hermes_cli/approvals_suggest.pyindex b3978cbcc3e..cb3f1bd217e 100644--- a/hermes_cli/approvals_suggest.py+++ b/hermes_cli/approvals_suggest.py@@ -231,11 +231,17 @@ def build_proposals(if is_unsafe_class(description):continue# Commands mined from past tool calls can embed credentials (URL userinfo,- # env assignments, bearer tokens). Patterns and examples are echoed to the- # operator and can be persisted to config.yaml, so mask them like every- # other display boundary — classification above still sees the raw command.- normalized = redact_sensitive_text(normalize_command(command), force=True)- glob = derive_glob(normalized)+ # env assignments, bearer tokens). Examples are echoed to the operator, so+ # mask them like every other display boundary — classification above+ # still sees the raw command. The glob is derived from the raw command:+ # a redacted `***` inside a persisted pattern would be three fnmatch+ # wildcards, so when redaction touches the tokens the glob embeds, the+ # command is proposed under its class key instead.+ raw = normalize_command(command)+ normalized = redact_sensitive_text(raw, force=True)+ glob = derive_glob(raw)+ if glob is not None and derive_glob(normalized) != glob:+ glob = Nonepattern, kind = (glob, "glob") if glob is not None else (description, "class")if pattern in existing:continuediff --git a/tests/hermes_cli/test_approvals_suggest.py b/tests/hermes_cli/test_approvals_suggest.pyindex 7cb2300ce13..13c6a909b21 100644--- a/tests/hermes_cli/test_approvals_suggest.py+++ b/tests/hermes_cli/test_approvals_suggest.py@@ -237,6 +237,20 @@ class TestProposalRedaction:assert pat not in p["pattern"]assert all(pat not in ex for ex in p["examples"])+ def test_credential_in_glob_tokens_falls_back_to_class_key(self, isolated_allowlist):+ """Redaction must never reach a persisted glob: `KEY=*** git *` would be three+ fnmatch wildcards pre-approving any `KEY=… git …` command."""+ from tools.approval_floors import _command_matches_permanent_allowlist++ cmd = "GITHUB_TOKEN=ghp_16C7e42F292c6912E7710c838347Ae178B4a git push --force origin main"+ proposals = build_proposals([(cmd, "git push --force")] * 3, min_count=1)+ assert [(p.pattern, p.kind) for p in proposals] == [("git push --force", "class")]+ assert "ghp_" not in proposals[0].examples[0]+ added = apply_proposals(proposals, [0])+ assert "*" not in "".join(added)+ approval_module.load_permanent(set(approval_module.load_permanent_allowlist()))+ assert not _command_matches_permanent_allowlist("GITHUB_TOKEN=x sudo git push --force origin main")+# ---------------------------------------------------------------------------# --apply / dry-rundiff --git a/website/docs/user-guide/security.md b/website/docs/user-guide/security.mdindex 38f767d7249..fea2eb5e2f1 100644--- a/website/docs/user-guide/security.md+++ b/website/docs/user-guide/security.md@@ -320,8 +320,10 @@ Safety rules:- **Credentials inside mined commands are masked** (`ghp_…`, `bot<id>:<token>`URLs, `KEY=value` assignments, bearer tokens) in both the printed `e.g.`examples and the `--json` payload, using the same redactor as terminal- output. Note this masks the *display* only — the session database itself- still holds the command as it was executed.+ output. Masked text is never used as an allowlist pattern: a command whose+ glob would embed a credential (`TOKEN=… git …`) is proposed under its+ dangerous-class key instead. The session database itself still holds the+ command as it was executed.Useful flags: `--days N` (history window, default 90), `--min-count N`(minimum approvals to qualify, default 2), `--limit N`, and `--db PATH`.