Skip to content

The agent that grows with you

refactor(agent): simplify strict URL userinfo substitution

kshitijk4poorc900b1df58ee
diff --git a/agent/redact.py b/agent/redact.py
index e5f91cdb805..4c72f3ea72a 100644
--- a/agent/redact.py
+++ b/agent/redact.py
@@ -560,7 +560,7 @@ _STRICT_URL_PARAM_RE = re.compile(r"([?#&;])([A-Za-z0-9_.~+%\-]+)=([^#&;\s\"'<>]
# authority stops at path/query/fragment delimiters. Anchored on the mandatory
# ``//`` — an optional-scheme prefix backtracked O(n²) on long alphanumeric runs
# (~55s per sub() on a 320KB compaction payload).
-_STRICT_URL_USERINFO_RE = re.compile(r"(//)([^/\s?#@]+)@")
+_STRICT_URL_USERINFO_RE = re.compile(r"//[^/\s?#@]+@")
# Form-urlencoded body: only when the ENTIRE text is a k=v&k=v string.
_FORM_BODY_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_.-]*=[^&\s]*(?:&[A-Za-z_][A-Za-z0-9_.-]*=[^&\s]*)+$")
@@ -759,9 +759,7 @@ def _redact_strict_url_credentials(text: str) -> str:
text = _STRICT_URL_PARAM_RE.sub(
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)}***:***@",
- text)
+ return _STRICT_URL_USERINFO_RE.sub("//***:***@", text)
def redact_cdp_url(value: object) -> str:
@@ -888,7 +886,7 @@ def redact_sensitive_text(text: str, *, force: bool = False, code_file: bool = F
raw secrets regardless.
``redact_url_credentials=True``: also redact credential-named query params
- and ``user:pass@`` userinfo — off by default because OAuth-callback /
+ and the entire URL userinfo (``***:***@``) — off by default because OAuth-callback /
magic-link / pre-signed URLs must survive ordinary tool flows unchanged.
``code_file=True``: skip the ENV/JSON assignment passes for known source
code (``MAX_TOKENS=***``, ``"apiKey": "test"`` fixtures). ``file_read=True``
diff --git a/tests/agent/test_redact.py b/tests/agent/test_redact.py
index e4e123f29b9..beccb8146d1 100644
--- a/tests/agent/test_redact.py
+++ b/tests/agent/test_redact.py
@@ -749,6 +749,11 @@ class TestStrictUrlCredentialRedaction:
"NET_SECRET",
"//***:***@x.test/path",
),
+ (
+ "https://Zq8vT3kP9wLm2xR7nB4cY6fH1dJ5sA0e:@llm-proxy.example/v1",
+ "Zq8vT3kP9wLm2xR7nB4cY6fH1dJ5sA0e",
+ "https://***:***@llm-proxy.example/v1",
+ ),
],
)
def test_masks_all_url_reference_forms_only_when_opted_in(
@@ -761,13 +766,6 @@ 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