Skip to content

The agent that grows with you

fix(agent): redact strict URL userinfo credentials

Yuan Li00227371f27d
diff --git a/agent/redact.py b/agent/redact.py
index 20bcbe984ba..e5f91cdb805 100644
--- a/agent/redact.py
+++ b/agent/redact.py
@@ -760,7 +760,7 @@ def _redact_strict_url_credentials(text: str) -> str:
lambda m: f"{m.group(1)}{m.group(2)}=***"
if _canonical_url_param_name(m.group(2)) in _SENSITIVE_QUERY_PARAMS else m.group(0), text)
return _STRICT_URL_USERINFO_RE.sub(
- lambda m: f"{m.group(1)}{m.group(2).partition(':')[0]}:***@" if ":" in m.group(2) else f"{m.group(1)}***@",
+ lambda m: f"{m.group(1)}***:***@",
text)
diff --git a/tests/agent/test_redact.py b/tests/agent/test_redact.py
index 116c800569f..e4e123f29b9 100644
--- a/tests/agent/test_redact.py
+++ b/tests/agent/test_redact.py
@@ -747,7 +747,7 @@ class TestStrictUrlCredentialRedaction:
(
"//user:[email protected]/path",
"NET_SECRET",
- "//user:***@x.test/path",
+ "//***:***@x.test/path",
),
],
)
@@ -761,6 +761,13 @@ class TestStrictUrlCredentialRedaction:
assert secret not in result
assert result == expected
+ def test_opaque_username_credentials_are_fully_redacted(self):
+ token = "Zq8vT3kP9wLm2xR7nB4cY6fH1dJ5sA0e"
+ text = f"https://{token}:@llm-proxy.example/v1"
+ result = redact_sensitive_text(text, redact_url_credentials=True)
+ assert token not in result
+ assert result == "https://***:***@llm-proxy.example/v1"
+
def test_similarly_named_public_params_remain_unchanged(self):
text = "/metrics?token_count=17&session_id=public"
assert redact_sensitive_text(text, redact_url_credentials=True) == text