Skip to content

The agent that grows with you

fix(delegate): strip URL userinfo from tool history

embwl0xa8c9ad0bccc7
diff --git a/tests/agent/test_subagent_stop_hook.py b/tests/agent/test_subagent_stop_hook.py
index 84c0bbe4127..7bb21d9a60e 100644
--- a/tests/agent/test_subagent_stop_hook.py
+++ b/tests/agent/test_subagent_stop_hook.py
@@ -213,6 +213,7 @@ class TestPayloadShape:
"argument_keys": ["content", "path", "token"],
"targets": {
"path": "/private/report.json",
+ "url": "https://user:[email protected]:8443/upload?token=secret",
"token": "must-not-leak",
},
},
@@ -226,7 +227,10 @@ class TestPayloadShape:
"tool_name": "write_file",
"tool_input": {
"argument_keys": ["content", "path", "token"],
- "targets": {"path": "/private/report.json"},
+ "targets": {
+ "path": "/private/report.json",
+ "url": "https://example.test:8443/upload",
+ },
},
"input_bytes": 128,
"output_bytes": 32,
@@ -237,7 +241,7 @@ class TestPayloadShape:
summary = _summarize_tool_arguments(json.dumps({
"path": "/workspace/report.json",
"content": "private report contents",
- "url": "https://example.test/upload?token=secret#fragment",
+ "url": "https://user:[email protected]:8443/upload?token=secret#fragment",
"command": "curl -H 'Authorization: secret' example.test",
}))
@@ -245,7 +249,7 @@ class TestPayloadShape:
"argument_keys": ["command", "content", "path", "url"],
"targets": {
"path": "/workspace/report.json",
- "url": "https://example.test/upload",
+ "url": "https://example.test:8443/upload",
},
}
diff --git a/tools/delegate_tool.py b/tools/delegate_tool.py
index c7dba38ea82..b1dcd80127b 100644
--- a/tools/delegate_tool.py
+++ b/tools/delegate_tool.py
@@ -333,7 +333,17 @@ def _sanitize_tool_target(key: str, value: Any) -> Any:
try:
parsed = urlsplit(bounded)
if parsed.scheme and parsed.netloc:
- return urlunsplit((parsed.scheme, parsed.netloc, parsed.path, "", ""))
+ hostname = parsed.hostname
+ if not hostname:
+ return None
+ # ``SplitResult.netloc`` includes ``user:password@``. Rebuild
+ # the authority from parsed host/port so hook-visible history
+ # cannot carry URL credentials. Bracket IPv6 literals before
+ # appending a validated port.
+ host = f"[{hostname}]" if ":" in hostname else hostname
+ port = parsed.port
+ netloc = f"{host}:{port}" if port is not None else host
+ return urlunsplit((parsed.scheme, netloc, parsed.path, "", ""))
except ValueError:
return None
return bounded