Files
hermes-agent/tests/monitoring/test_export_redaction.py
Maciej Lisiewski d6815cb03c fix(redact): keep provider tool-arg URLs intact; URL query mask follows the JSON-field names
Provider tool arguments now skip the URL query mask: a memory tool may fetch the URL it
is given (openviking's viking_add_resource indexing a pre-signed S3 or SAS link), so
masking ?X-Amz-Signature=/?key=/?sig= broke it. Storage-only hand-offs keep urls=True.

The URL query pass also masks every name the JSON-field rule treats as a secret
(accessToken, x-api-key, auth_token, private_token, secret_key, passwd, ...), via the
same closed list and affixed-key policy, so the two passes agree.

Refs #119852
2026-11-14 21:01:00 +01:00

55 lines
1.5 KiB
Python

"""Export redaction tests — the security-critical layer.
Invariants:
* One unconditional scrub: secrets AND PII, no modes, no knobs.
* Fails CLOSED: if the redactor can't run, the raw string is never emitted.
* Structure (subsystem names, error codes) survives; free-text PII does not.
"""
from __future__ import annotations
from unittest import mock
import agent.monitoring.redaction as R
def test_secret_key_always_stripped():
fake_key = "sk-ant-api03-" + "A" * 24 # constructed to dodge literal-scrubbers
out = R.redact_for_export(f"calling with key {fake_key} and moving on")
assert out is not None
assert fake_key not in out
def test_bearer_header_stripped():
out = R.redact_for_export("Authorization: Bearer abc.def-ghi_jkl")
assert out is not None
assert "abc.def-ghi_jkl" not in out
def test_structure_preserved():
out = R.redact_for_export("platform.slack entered fatal after auth_failed")
assert out is not None
assert "platform.slack" in out
assert "auth_failed" in out
def test_fails_closed_when_redactor_unavailable():
with mock.patch("agent.redact.redact_sensitive_text", side_effect=RuntimeError):
out = R.redact_for_export("secret sauce sk-live-key")
assert out == "[redaction-unavailable]"
def test_prefix_less_url_query_credential_stripped():
key = "Zo4" + "Ab8RN6Jx2kq9Zs0VwT4yLm3PbQe7HcUfGdA1nX5oIr"
out = R.redact_for_export(f"GET https://x.example/y?api_key={key}&page=2 failed")
assert out is not None
assert key not in out and "page=2" in out