Skip to content

The agent that grows with you

fix(debug): scrub a key-shaped free-text Bearer value before `="..."`

kshitijk4poor48975fcaa2c8
diff --git a/hermes_cli/debug_redaction.py b/hermes_cli/debug_redaction.py
index 96790b7b82b..910e215a17c 100644
--- a/hermes_cli/debug_redaction.py
+++ b/hermes_cli/debug_redaction.py
@@ -118,9 +118,10 @@ _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.
# 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.
+ # is auth-params, not a token: only a known param name stays, so a key-shaped
+ # ``<letters>="..."`` is still scrubbed (fail closed).
rf"(?P<prefix>\bBearer\s+|\bBasic\s+{_NOT_WORD})"
- r'(?![A-Za-z_]+="|(?:realm|scope|error|error_description|error_uri)=)'
+ r"(?!(?: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 2cd4d7435b5..8dbf1ad73c4 100644
--- a/tests/tui_gateway/test_diagnostics_share_nous.py
+++ b/tests/tui_gateway/test_diagnostics_share_nous.py
@@ -202,6 +202,7 @@ def test_redacted_support_egress_scrubs_structured_values_and_errors(
for leaky, key in (
("x-api-key: Bearer abc1234", "abc1234"),
("-H 'x-auth-token: *** s3cr3t'", "s3cr3t"),
+ ('Bearer qwertyuiopas="v"', "qwertyuiopas"),
("x-api-key: *** qwertyuiopas", "qwertyuiopas"),
("--header x-api-key *** abc1234", "abc1234"),
("x-api-key: *** " + "q" * 32, "q" * 32),