Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(redaction): redact bare userinfo only when it looks like a token

t148dfd7f20fd
diff --git a/agent/src/tools/redaction.py b/agent/src/tools/redaction.py
index fb2213a91..01d025ebb 100644
--- a/agent/src/tools/redaction.py
+++ b/agent/src/tools/redaction.py
@@ -452,13 +452,17 @@ _TEXT_BEARER_PATTERN = re.compile(
)
#: URL userinfo (``scheme://user:password@host``). It is a credential with no
-#: key label, so the key-based pattern never reaches it. The class may contain
-#: ``@`` (a password can), but stops at whitespace, path/query/fragment markers,
-#: quotes, brackets and commas. So the match ends at the last ``@`` of the
-#: authority, and JSON fields after a URL are left alone. A bare username
-#: (``git@host``) is redacted too, since a token used as a username is a
-#: credential.
-_TEXT_URL_USERINFO_PATTERN = re.compile(r"(?<=://)[^\s/?#\"'<>(){}\[\],]+@")
+#: key label, so the key-based pattern never reaches it. A password may contain
+#: ``@``, so the match runs to the last ``@`` before a delimiter (whitespace,
+#: path/query/fragment markers, quotes, brackets, commas), and JSON fields after
+#: a URL are left alone. A bare username is redacted only when it is 20+ token
+#: characters (a pasted access token), so ``git@host`` stays readable.
+_TEXT_URL_USERINFO_PATTERN = re.compile(
+ r"(?<=://)"
+ r"(?:[^\s/?#\"'<>(){}\[\],:@]*:[^\s/?#\"'<>(){}\[\],]*" # user:password
+ r"|[A-Za-z0-9_-]{20,})" # bare token
+ r"@"
+)
def _sub_credential_pair(match: re.Match[str]) -> str:
diff --git a/agent/tests/test_redaction.py b/agent/tests/test_redaction.py
index 9f3ba3cac..60634942e 100644
--- a/agent/tests/test_redaction.py
+++ b/agent/tests/test_redaction.py
@@ -176,9 +176,9 @@ _URL_USERINFO_SHAPES = (
"see https://[redacted]@host/x",
),
(
- # A token used as the username (no colon) is still a credential.
- "fetch http://[email protected]/repo",
- "fetch http://[redacted]@git.example.com/repo",
+ # A long token used as the username (no colon) is still a credential.
+ "fetch https://ghp_" + "a" * 36 + "@github.com/org/repo",
+ "fetch https://[redacted]@github.com/org/repo",
),
)
@@ -220,6 +220,8 @@ def test_redact_text_is_idempotent(raw: str) -> None:
"pad_token=0 eos_token=2 max_token=4096",
# JSON fields after a URL must survive; only real userinfo is scrubbed.
'{"url":"https://api.x.com","email":"[email protected]"}',
+ # A short SSH username is not a credential; keep it readable.
+ "git+ssh://[email protected]/org/repo.git",
],
)
def test_redact_text_leaves_benign_output_readable(raw: str) -> None: