Skip to content

The agent that grows with you

fix(debug): keep RFC 6750 Bearer challenges out of the free-text token scrub

kshitijk4poora3351e7d433d
diff --git a/hermes_cli/debug_redaction.py b/hermes_cli/debug_redaction.py
index f73dbfc3d2b..2fed29253b6 100644
--- a/hermes_cli/debug_redaction.py
+++ b/hermes_cli/debug_redaction.py
@@ -114,7 +114,11 @@ _PLAIN_HEADER_ARG_RE = re.compile(
_SUPPORT_BEARER_RE = re.compile(
# Free text has no header boundary to stop at: consume the whole value,
# inner ``=`` padding included (``abcd1234==x``), not just a key-shaped prefix.
- rf"(?P<prefix>\bBearer\s+|\bBasic\s+{_NOT_WORD})(?=[^\s]{{8}})"
+ # An RFC 6750/7235 challenge (``Bearer realm="api"``, ``Bearer error=...``)
+ # is auth-params, not a token: a quoted param or a known param name stays.
+ rf"(?P<prefix>\bBearer\s+|\bBasic\s+{_NOT_WORD})"
+ r'(?![A-Za-z_]+="|(?:realm|scope|error|error_description|error_uri)=)'
+ rf"(?=[^\s]{{8}})"
rf"[{_KEY_CHARS}=]+(?::[{_KEY_CHARS}=]+)*",
re.IGNORECASE,
)
diff --git a/tests/tui_gateway/test_diagnostics_share_nous.py b/tests/tui_gateway/test_diagnostics_share_nous.py
index 29db6ff2644..52d183dd8b5 100644
--- a/tests/tui_gateway/test_diagnostics_share_nous.py
+++ b/tests/tui_gateway/test_diagnostics_share_nous.py
@@ -196,6 +196,8 @@ def test_redacted_support_egress_scrubs_structured_values_and_errors(
for prose in ("see: documentation", "time: 12:30:45", "configured via env", "undefined"):
kept = real_redact(f"x-api-key: *** {prose}")
assert kept.endswith(f" {prose}") and real_redact(kept) == kept
+ # An RFC 6750 challenge is auth-params, not a token.
+ assert real_redact('Bearer realm="api"') == 'Bearer realm="api"'
# Short, colon-bearing and double-encoded keys are keys, not prose.
for leaky, key in (
("x-api-key: Bearer abc1234", "abc1234"),