fix(telegram): redact bot tokens from transport error logs - #58594
fix(telegram): redact bot tokens from transport error logs#58594AlexFucuson9 wants to merge 1 commit into
Conversation
Telegram Bot API URLs carry credentials in the path as /bot<TOKEN>/<method>. Three error-handling paths logged raw exception text that could include these URLs: - sendRichMessage fallback (line 1603) - editMessageText fallback (line 1709) - polling reconnect warning (line 1902) Replace raw / with which uses the existing redact_sensitive_text(force=True) pipeline. This matches the pattern already used by transient send failures, retry errors, and legacy edit paths. Fixes NousResearch#58376
Related: this closes three residual leak sites in Related: #58376 (the issue), #58377 (earlier closed twin), #58501 (the merged salvage this completes). Note: the |
|
suggesting changes The patch still leaves a Telegram transport error path logging raw bot-token URLs. In Security evidence: Telegram Bot API credentials are carried in the request path and must not reach gateway logs; Signed: GPT-5.5-xhigh in Codex |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing three confirmed raw-error sites. The hunks still apply cleanly to current main, but the patch needs broader coverage before it closes this transport-error leak class.
Problems
plugins/platforms/telegram/adapter.py:2155-2159still logs rawerrorwhen a polling recovery task is already pending. This is the same method and error object as the warning changed by this PR, so repeated recovery calls can still expose a token URL.plugins/platforms/telegram/adapter.py:1879-1892catchessendRichMessageDrafttransport errors and logs rawexcin both branches.- The PR adds no regression test.
tests/gateway/test_telegram_rich_messages.py:480-498covers the transient rich-send result path, not these fallback/recovery log branches.
Suggested changes
- Apply
_redact_telegram_error_text()to those sibling logging paths. - Add
caplogtests withagent.redact._REDACT_ENABLEDdisabled, following the force-redaction pattern attests/gateway/test_telegram_rich_messages.py:480-498.
Automated hermes-sweeper review.
| @@ -1899,7 +1899,7 @@ def _schedule_polling_recovery(self, error: Exception, *, reason: str) -> None: | |||
| self._send_path_degraded = True | |||
There was a problem hiding this comment.
This redacts the degraded warning, but the immediately preceding pending-recovery branch still logs the same error object raw. Please redact that branch too and add a force-redaction regression test for repeated recovery calls.
…xception sites Extends @AlexFucuson9's 3-site fix (#58594) across the full adapter: every logger call and SendResult.error that interpolates a raw PTB exception now routes through _redact_telegram_error_text(). Covers polling conflict/retry/network ladders, overflow-split edits, draft sends, prompt/approval/clarify/picker sends, media send fallbacks, media cache failures, reactions, and chat-info lookups (48 additional sites). Telegram Bot API exceptions embed the token in the request URL (/bot<TOKEN>/<method>), so any raw str(exc) is a leak surface. Adds regression tests for SendResult.error redaction (update prompt, clarify) and delete_message debug-log redaction.
|
Merged via PR #65508 — your commit was cherry-picked onto current main with your authorship preserved in git log (rebase merge, commit on main). We widened the same fix to the remaining 48 raw-exception sites in the adapter on top of your 3, so the whole class is closed. Thanks for the fix! |
…xception sites Extends @AlexFucuson9's 3-site fix (NousResearch#58594) across the full adapter: every logger call and SendResult.error that interpolates a raw PTB exception now routes through _redact_telegram_error_text(). Covers polling conflict/retry/network ladders, overflow-split edits, draft sends, prompt/approval/clarify/picker sends, media send fallbacks, media cache failures, reactions, and chat-info lookups (48 additional sites). Telegram Bot API exceptions embed the token in the request URL (/bot<TOKEN>/<method>), so any raw str(exc) is a leak surface. Adds regression tests for SendResult.error redaction (update prompt, clarify) and delete_message debug-log redaction.
…xception sites Extends @AlexFucuson9's 3-site fix (NousResearch#58594) across the full adapter: every logger call and SendResult.error that interpolates a raw PTB exception now routes through _redact_telegram_error_text(). Covers polling conflict/retry/network ladders, overflow-split edits, draft sends, prompt/approval/clarify/picker sends, media send fallbacks, media cache failures, reactions, and chat-info lookups (48 additional sites). Telegram Bot API exceptions embed the token in the request URL (/bot<TOKEN>/<method>), so any raw str(exc) is a leak surface. Adds regression tests for SendResult.error redaction (update prompt, clarify) and delete_message debug-log redaction.
…xception sites Extends @AlexFucuson9's 3-site fix (NousResearch#58594) across the full adapter: every logger call and SendResult.error that interpolates a raw PTB exception now routes through _redact_telegram_error_text(). Covers polling conflict/retry/network ladders, overflow-split edits, draft sends, prompt/approval/clarify/picker sends, media send fallbacks, media cache failures, reactions, and chat-info lookups (48 additional sites). Telegram Bot API exceptions embed the token in the request URL (/bot<TOKEN>/<method>), so any raw str(exc) is a leak surface. Adds regression tests for SendResult.error redaction (update prompt, clarify) and delete_message debug-log redaction.
Summary
Telegram Bot API URLs carry credentials in the path as
/bot<TOKEN>/<method>. Three error-handling paths logged raw exception text that could include these URLs, leaking bot tokens to gateway logs.Affected Paths
logger.debug(... exc)logger.debug(... exc)logger.warning(... error)Fix
Replace raw
exc/errorwith_redact_telegram_error_text()in all three locations. This function already exists and usesredact_sensitive_text(force=True)from the shared redaction pipeline.This matches the pattern already used by:
Testing
The redaction function is already tested via
agent.redacttest suite. The fix ensures transport-level errors are treated consistently with all other Telegram error paths.Fixes #58376