The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(redact): dotted sk- body cannot span "..", so display masks survive a second pass; Zhipu matcher is 32-hex.16+alnum
teknium1aebc71d78c70
diff --git a/agent/redact.py b/agent/redact.pyindex e1fee91dd9d..6e955012589 100644--- a/agent/redact.py+++ b/agent/redact.py@@ -134,11 +134,13 @@ def _redact_enabled() -> bool:# pre-screen gate) is derived from these literals and must stay false-negative-free._PREFIX_PATTERNS = [# Some provider-issued ``sk-`` keys carry dot-delimited body segments (Alibaba- # ``sk-sp-…``/``sk-ws-…``). The lookahead sets the 10-char floor over the whole- # dotted body; the body then runs to its last non-dot char so sentence- # punctuation after a key is never consumed. Kept free of nested unbounded- # repeats so the pattern passes the same structural gate plugins must.- r"sk-(?=[A-Za-z0-9_.-]{10,}(?![A-Za-z0-9_.-]))[A-Za-z0-9_.-]*[A-Za-z0-9_-]",+ # ``sk-sp-…``/``sk-ws-…``). Each unit is one body char optionally preceded by+ # a single dot, so the body ends on its last non-dot char (sentence punctuation+ # is never consumed) and can never span ``..``: the ``sk-pro...EFGH`` display+ # mask is left alone by a second redaction pass instead of collapsing to+ # ``***``. Kept free of nested unbounded repeats so the pattern passes the+ # same structural gate plugins must.+ r"sk-[A-Za-z0-9_-](?:\.?[A-Za-z0-9_-]){9,}",r"ghp_[A-Za-z0-9]{10,}", # GitHub PAT (classic)r"github_pat_[A-Za-z0-9_]{10,}", # GitHub PAT (fine-grained)r"gho_[A-Za-z0-9]{10,}", # GitHub OAuth access token@@ -571,10 +573,11 @@ _PREFIX_RE = _compile_prefix_matcher(_PREFIX_PATTERNS)# Zhipu API keys use an unprefixed ``id.secret`` form. Keep this deliberately# provider-shaped instead of applying a generic high-entropy dotted-token rule:-# both opaque segments are alphanumeric, the ID is 32--40 characters, and the-# credential suffix is at least six characters.+# the ID is exactly 32 lowercase hex chars and the credential suffix is a run of+# at least 16 alphanumerics, so content-hash filenames (``<sha>.bundle``,+# ``<md5>.sqlite3``) never match._ZHIPU_API_KEY_RE = re.compile(- r"(?<![A-Za-z0-9_.-])([A-Za-z0-9]{32,40}\.[A-Za-z0-9]{6,})(?![A-Za-z0-9_.-])"+ r"(?<![A-Za-z0-9_.-])([0-9a-f]{32}\.[A-Za-z0-9]{16,})(?![A-Za-z0-9_.-])")diff --git a/tests/agent/test_redact.py b/tests/agent/test_redact.pyindex 062b3dc68e8..9427994d1b4 100644--- a/tests/agent/test_redact.py+++ b/tests/agent/test_redact.py@@ -28,12 +28,17 @@ class TestKnownPrefixes:dotted_sk = "sk-sp-" + "ABCDEFGH1234567890" + "." + "abcdefgh1234567890_XYZ-0987654321"multi_dot_sk = "sk-ws-" + "H.EEPXREE.pFau.MEUCIQC6UnD-jj2a" + "ABCDEFGHIJKLMNOP"- zhipu = "50aaedFAKE1234567890abcdef1234567890abc" + "." + "ZpSh99"+ zhipu = "50aaed1234567890abcdef1234567890" + "." + "ZpSh99AbCdEfGh12"yaml = f"a:\n api_key: {dotted_sk}\nb:\n api_key: {zhipu}\nc:\n api_key: {multi_dot_sk}\n"term = redact_terminal_output(yaml, "cat /tmp/keys.yaml")for secret_tail in ("abcdefgh1234567890_XYZ", "ZpSh99", "MEUCIQC6UnD", "EEPXREE"):assert secret_tail not in term, term+ # Display masks (``sk-pro...EFGH``) contain ``..``, which no real key does:+ # a second pass over an already-masked token must be a no-op, not ``***``+ # (tool_executor redacts browser_type args, then build_tool_preview+ # redacts them again).+ assert redact_sensitive_text("sk-pro...EFGH", force=True) == "sk-pro...EFGH"read = redact_sensitive_text(yaml, file_read=True)assert "«redacted:sk-…»" in read and "«redacted-secret»" in read, read@@ -42,15 +47,18 @@ class TestKnownPrefixes:def test_dotted_and_prefixless_matchers_leave_benign_tokens_alone(self):"""The Zhipu matcher is provider-shaped, not a generic dotted-token sweep:- content-hash filenames, bare git shas, short ``sk-`` fragments and a- 31-char id must stay byte-identical."""+ content-hash filenames (incl. ``<sha>.bundle`` / ``<md5>.sqlite3``), bare+ git shas, short ``sk-`` fragments and a 31-char id must stay byte-identical."""from agent.redact import redact_terminal_outputbenign = ("blob 0123456789abcdef0123456789abcdef.png\n"+ "git bundle create 0123456789abcdef0123456789abcdef01234567.bundle\n"+ "/cache/0123456789abcdef0123456789abcdef.sqlite3\n"+ "cp " + "a1" * 18 + ".example\n""commit 0123456789abcdef0123456789abcdef01234567\n""sk-short sk-abc.def\n"- "release=" + "a" * 31 + ".ZpSh99\n"+ "release=" + "a" * 31 + ".ZpSh99AbCdEfGh12\n")assert redact_terminal_output(benign, "git log --stat") == benignassert redact_sensitive_text(benign, file_read=True) == benign