Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix(proxy): redact proxy-authorization and *_token keys in wire debug capture (#3918)
eeshsaxenab9a0d298cfd7
diff --git a/headroom/proxy/wire_debug_redaction_policy.py b/headroom/proxy/wire_debug_redaction_policy.pyindex 5b3c40813..28fe89533 100644--- a/headroom/proxy/wire_debug_redaction_policy.py+++ b/headroom/proxy/wire_debug_redaction_policy.py@@ -7,6 +7,9 @@ from typing import AnyWIRE_DEBUG_REDACTED = "[REDACTED]"WIRE_DEBUG_SECRET_KEYS = ("authorization",+ # A proxy sees Proxy-Authorization on the hop it makes itself; it carries+ # the same kind of credential as Authorization.+ "proxy-authorization","cookie","set-cookie","api-key",@@ -19,8 +22,23 @@ WIRE_DEBUG_SECRET_KEYS = ("bearer","password","secret",+ "secret_key","token","credential",+ "credentials",+)++# Suffixes that make a prefixed key a secret. ``_token`` covers the auth,+# session, api, id and security token names providers use, and does not touch+# the usage counters (``max_tokens``, ``input_tokens``, ...), which are plural.+_SECRET_KEY_SUFFIXES = (+ "_api_key",+ "_secret",+ "_secret_key",+ "_password",+ "_token",+ "_credential",+ "_credentials",)@@ -29,13 +47,7 @@ def should_redact_key(key: str) -> bool:normalized = key.lower().replace("-", "_")if normalized in {marker.replace("-", "_") for marker in WIRE_DEBUG_SECRET_KEYS}:return True- return (- normalized.endswith("_api_key")- or normalized.endswith("_secret")- or normalized.endswith("_password")- or normalized.endswith("_access_token")- or normalized.endswith("_refresh_token")- )+ return normalized.endswith(_SECRET_KEY_SUFFIXES)def redact_for_wire_debug(value: Any) -> Any:diff --git a/tests/test_wire_debug_redaction_policy.py b/tests/test_wire_debug_redaction_policy.pyindex e271a2969..4d6e4ed9c 100644--- a/tests/test_wire_debug_redaction_policy.py+++ b/tests/test_wire_debug_redaction_policy.py@@ -43,3 +43,41 @@ def test_wire_debug_key_matching_normalizes_dashes_and_case() -> None:assert should_redact_key("Anthropic-API-Key")assert should_redact_key("custom-refresh-token")assert not should_redact_key("token_count")+++def test_wire_debug_redacts_proxy_authorization() -> None:+ redacted = redact_for_wire_debug(+ {"Proxy-Authorization": "Basic dXNlcjpwYXNz", "user-agent": "codex/1.0"}+ )++ assert redacted["Proxy-Authorization"] == WIRE_DEBUG_REDACTED+ assert redacted["user-agent"] == "codex/1.0"+++def test_wire_debug_redacts_any_token_suffix() -> None:+ for key in (+ "auth_token",+ "session_token",+ "api_token",+ "github_token",+ "x-amz-security-token",+ "google_id_token",+ ):+ assert should_redact_key(key), key+++def test_wire_debug_redacts_credentials_and_secret_key() -> None:+ for key in ("credentials", "aws_credentials", "secret_key", "aws_secret_key"):+ assert should_redact_key(key), key+++def test_wire_debug_keeps_token_usage_counters_visible() -> None:+ for key in (+ "max_tokens",+ "input_tokens",+ "output_tokens",+ "total_tokens",+ "cache_read_input_tokens",+ "token_count",+ ):+ assert not should_redact_key(key), key