Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions forks/hermes-agent/agent/redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# drift: a blocked file_tools read that falls back to ``cat`` is still caught.
from agent.file_safety import _BLOCKED_PROJECT_ENV_BASENAMES as _ENV_FILE_BASENAMES
from agent.redact_connstr import _KV_CONNSTR_GATE_RE, _redact_kv_connection_strings
from agent.redact_kubernetes import redact_kubernetes
from agent.redact_headers import (
_COOKIE_HEADER_JSON_RE, _COOKIE_HEADER_JSON_UNTERMINATED_RE, _SECRET_HEADER_JSON_RE,
_SECRET_HEADER_JSON_UNTERMINATED_RE, json_header_value_is_credential, redact_cookie_assignments,
Expand Down Expand Up @@ -1420,7 +1421,9 @@ def _redact_yaml(m):
if quote and (not inner or _DSN_PW_PLACEHOLDER_RE.fullmatch(inner)
or (inner.startswith("{{") and inner.endswith("}}"))): # Helm/Jinja template
return m.group(0)
if not _should_redact_assignment(key, inner, check_keyword=True):
# ``kubectl describe``'s ``<set to the key 'k' in secret 's'>`` names a reference, not a value.
if not _should_redact_assignment(key, inner, check_keyword=True) \
or (inner == "<set" and m.string.startswith(" to the key ", m.end())):
return m.group(0)
return f"{key}{sep}{quote}{mask(inner)}{quote}"
text = _YAML_ASSIGN_RE.sub(_redact_yaml, text)
Expand Down Expand Up @@ -1558,13 +1561,18 @@ def redact_sensitive_text(text: str, *, force: bool = False, code_file: bool = F
_zhipu_sub = _mask_token_nonreusable if file_read else _mask_token
text = _ZHIPU_API_KEY_RE.sub(lambda m: _zhipu_sub(m.group(1)), text)

# PEM blocks first: a multi-line key under a secret env name must be masked as a whole block.
text = _redact_private_key_blocks(text)
# Kubernetes Secret data / secret env values run in every mode: the source is a live object,
# never a code fixture, and kubectl output is how the model sees them (RIG-11725).
text = redact_kubernetes(text, _mask_token_nonreusable("") if file_read else "***")

if not code_file:
text = _redact_assignments(text, mask_nonreusable=file_read)

# Flags and connection-string keys carry a credential in command text, so they are not
# gated on code_file: the shape (``--password=`` / ``;AccountKey=``) is unambiguous, and
# the surfaces that leaked them (approval cards, chat status) run this pass anyway.
text = _redact_private_key_blocks(text)
text = _redact_cli_secrets(text, _mask_token_nonreusable if file_read else None)

if force and "=" in text:
Expand Down
Loading
Loading