"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(redaction): scrub Telegram bot tokens, Slack/Discord webhook secrets, Groq and NVIDIA keys
Rudy Celeklife04c2226ba1
diff --git a/agent/src/tools/redaction.py b/agent/src/tools/redaction.pyindex d804199cb..46936dbd9 100644--- a/agent/src/tools/redaction.py+++ b/agent/src/tools/redaction.py@@ -563,10 +563,29 @@ _TEXT_TOKEN_PATTERN = re.compile(r"|glpat-[A-Za-z0-9_-]{20,}" # GitLab PATr"|npm_[A-Za-z0-9]{36}" # npm access tokenr"|hf_[A-Za-z0-9]{30,}" # Hugging Face token+ r"|gsk_[A-Za-z0-9]{20,}" # Groq API key+ r"|nvapi-[A-Za-z0-9_-]{20,}" # NVIDIA API keyr"|eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}" # JWTr")(?![A-Za-z0-9_-])")+#: 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+#: ``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_-])"+)+_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"[A-Za-z0-9_-]{20,}"+)+def redact_text(text: object) -> str:"""Scrub credential-shaped values from a free-form string.@@ -602,6 +621,8 @@ def redact_text(text: object) -> str:s = _TEXT_AUTH_SCHEME_PATTERN.sub(r"\g<head>\g<scheme> " + _REDACTED, s)s = _TEXT_URL_USERINFO_PATTERN.sub(_REDACTED + "@", s)s = _TEXT_KV_PATTERN.sub(_sub_credential_pair, s)+ s = _TEXT_WEBHOOK_URL_PATTERN.sub(r"\g<head>" + _REDACTED, s)+ s = _TEXT_TELEGRAM_BOT_TOKEN_PATTERN.sub(_REDACTED, s)# Bare tokens with no key label in front of them.return _TEXT_TOKEN_PATTERN.sub(_REDACTED, s)diff --git a/agent/tests/test_redaction_channel_and_provider_tokens.py b/agent/tests/test_redaction_channel_and_provider_tokens.pynew file mode 100644index 000000000..66f8ffcf3--- /dev/null+++ b/agent/tests/test_redaction_channel_and_provider_tokens.py@@ -0,0 +1,42 @@+"""Channel and provider credentials with no key label are scrubbed from text."""++from __future__ import annotations++import pytest++from src.tools.redaction import redact_text++_TELEGRAM = "123456789:" + "AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw1"++def test_telegram_bot_token_in_request_url_is_redacted() -> None:+ out = redact_text(f"401 for url: https://api.telegram.org/bot{_TELEGRAM}/sendMessage")+ assert _TELEGRAM not in out+ assert out == "401 for url: https://api.telegram.org/[redacted]/sendMessage"+ assert redact_text(out) == out++[email protected]("token", ["gsk_" + "a1B2c3D4e5F6g7H8i9J0k1L2m3N4", "nvapi-" + "a1B2c3D4e5F6g7H8i9J0k1L2", _TELEGRAM])+def test_bare_token_is_redacted(token: str) -> None:+ out = redact_text(f"provider rejected {token} today")+ assert out == "provider rejected [redacted] today"+ assert redact_text(out) == out+++def test_slack_webhook_secret_is_redacted() -> None:+ url = "https://hooks.slack.com/" + "services/T00000000/B00000000/" + "X" * 24+ out = redact_text(f"post to {url} failed")+ assert "X" * 24 not in out+ assert out == "post to https://hooks.slack.com/" + "services/T00000000/B00000000/[redacted] failed"+ assert redact_text(out) == out+++def test_discord_webhook_secret_is_redacted() -> None:+ secret = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV"+ out = redact_text(f"https://discord.com/api/webhooks/123456789012345678/{secret}")+ assert secret not in out+ assert out == "https://discord.com/api/webhooks/123456789012345678/[redacted]"+++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