"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(redaction): cover Telegram id lengths and webhook host variants
Haozhe Wu2c00cd207cfc
diff --git a/agent/src/tools/redaction.py b/agent/src/tools/redaction.pyindex 46936dbd9..92bffe0fd 100644--- a/agent/src/tools/redaction.py+++ b/agent/src/tools/redaction.py@@ -571,18 +571,18 @@ _TEXT_TOKEN_PATTERN = re.compile(#: Channel credentials that embed the secret in a URL path or a bare token, so#: neither the key-based nor the issuer-prefix patterns see them. The Telegram-#: bot token (``<8-10 digit id>:<35 chars>``) appears in the request URL+#: bot token (``<numeric id>:<35 chars>``) appears in the request URL#: ``https://api.telegram.org/bot<token>/sendMessage``, which HTTP client error#: messages echo verbatim; Slack and Discord incoming-webhook URLs are bearer#: credentials whose last path segment is the secret. The Telegram body is a#: fixed-length class and the webhook secrets are bounded runs, so matching#: stays linear._TEXT_TELEGRAM_BOT_TOKEN_PATTERN = re.compile(- r"(?<![A-Za-z0-9_-])(?:bot)?\d{8,10}:[A-Za-z0-9_-]{35}(?![A-Za-z0-9_-])"+ r"(?<![A-Za-z0-9_-])(?:bot)?\d+:[A-Za-z0-9_-]{35}(?![A-Za-z0-9_-])")_TEXT_WEBHOOK_URL_PATTERN = re.compile(- r"(?P<head>https://hooks\.slack\.com/(?:services|triggers)/[A-Za-z0-9]+/[A-Za-z0-9]+/"- r"|https://(?:[a-z]+\.)?discord(?:app)?\.com/api/(?:v\d+/)?webhooks/\d+/)"+ r"(?P<head>(?i:https://hooks\.slack(?:-gov)?\.com)/(?:services|triggers)/[A-Za-z0-9]+/[A-Za-z0-9]+/"+ r"|(?i:https://(?:[a-z]+\.)?discord(?:app)?\.com)/api/(?:v\d+/)?webhooks/\d+/)"r"[A-Za-z0-9_-]{20,}")diff --git a/agent/tests/test_redaction_channel_and_provider_tokens.py b/agent/tests/test_redaction_channel_and_provider_tokens.pyindex 66f8ffcf3..23500eb64 100644--- a/agent/tests/test_redaction_channel_and_provider_tokens.py+++ b/agent/tests/test_redaction_channel_and_provider_tokens.py@@ -4,7 +4,7 @@ from __future__ import annotationsimport pytest-from src.tools.redaction import redact_text+from src.tools.redaction import redact_text, redact_tool_result_TELEGRAM = "123456789:" + "AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw1"@@ -40,3 +40,27 @@ def test_discord_webhook_secret_is_redacted() -> None:def test_lookalikes_are_left_alone() -> None:text = "12:30:45 ratio 1234567890:short gsk_short nvapi-x https://hooks.slack.com/" + "services/T0/B0/short"assert redact_text(text) == text++[email protected]("bot_id", ["123456", "1234567", "12345678901"])[email protected]("in_url", [False, True])+def test_telegram_token_does_not_assume_an_eight_to_ten_digit_id(bot_id, in_url):+ # Telegram's own Bot API documentation uses a six-digit bot id.+ token = bot_id + ":" + "A" * 35+ text = f"https://api.telegram.org/bot{token}/getMe" if in_url else token+ out = redact_tool_result(text)+ assert token not in out+ assert "[redacted]" in out+ assert redact_text(out) == out++[email protected]("host", ["hooks.slack-gov.com", "HOOKS.SLACK.COM"])+def test_webhook_host_variants_are_redacted_inside_results(host):+ import json++ secret = "X" * 24+ url = f"https://{host}/services/T00000000/B00000000/{secret}"+ out = json.loads(redact_tool_result(json.dumps({"error": f"request failed: {url}"})))+ assert secret not in out["error"]+ assert host in out["error"]+ assert "[redacted]" in out["error"]