Skip to content

The agent that grows with you

fix(debug): treat a 20+ letter single-case run after a masked scheme as a key

kshitijk4pooreb828ac3f443
diff --git a/hermes_cli/debug_redaction.py b/hermes_cli/debug_redaction.py
index 44559848bfa..a860183a8f0 100644
--- a/hermes_cli/debug_redaction.py
+++ b/hermes_cli/debug_redaction.py
@@ -57,10 +57,11 @@ _QUOTED_HEADER_RE = re.compile(
# A key may carry inner colons (``sk-abc:xyz``, ``user:pass``); a trailing colon
# is prose punctuation (``see: docs``). A letters-only word (``docs``, ``Note``,
# ``HTTP``) is prose rather than a key: keys mix case, digits or symbols. The
-# word test is case-sensitive even inside the IGNORECASE regexes below.
+# word test is case-sensitive even inside the IGNORECASE regexes below. A
+# single-case run of 20+ letters is no English word, so it is a key.
_KEY_CHARS = r"A-Za-z0-9._~+/\-"
_KEY = rf"[{_KEY_CHARS}]+(?::[{_KEY_CHARS}]+)*=*(?![{_KEY_CHARS}=]|:[{_KEY_CHARS}])"
-_NOT_WORD = rf"(?!(?-i:[A-Z]?[a-z]+|[A-Z]+)(?![{_KEY_CHARS}=]|:[{_KEY_CHARS}]))"
+_NOT_WORD = rf"(?!(?-i:[A-Z]?[a-z]{{1,19}}|[A-Z]{{1,19}})(?![{_KEY_CHARS}=]|:[{_KEY_CHARS}]))"
# agent.redact masks the scheme of ``x-api-key: Basic <key>`` to ``***`` and
# keeps the key, so ``***`` is a scheme too and the key is the value when it
# is key-shaped (not a word; 4+ chars before any colon, or 6+ mixing letters
diff --git a/tests/tui_gateway/test_diagnostics_share_nous.py b/tests/tui_gateway/test_diagnostics_share_nous.py
index 3bf5fd0537d..517e25cd317 100644
--- a/tests/tui_gateway/test_diagnostics_share_nous.py
+++ b/tests/tui_gateway/test_diagnostics_share_nous.py
@@ -201,6 +201,8 @@ def test_redacted_support_egress_scrubs_structured_values_and_errors(
("x-api-key: Bearer abc1234", "abc1234"),
("-H 'x-auth-token: *** s3cr3t'", "s3cr3t"),
("--header x-api-key *** abc1234", "abc1234"),
+ ("x-api-key: *** " + "q" * 32, "q" * 32),
+ ("--header x-api-key *** " + "Q" * 32, "Q" * 32),
("x-api-key: *** sk-abc:xyz123456", "xyz123456"),
("Basic user:passw0rd", "passw0rd"),
("?r=x%2526access_token%253Dtok123456789", "tok123456789"),