Skip to content

[Bug]: Telegram file download lacks timeout, can hang gateway indefinitely #6849

Closed

Description

@coygeek

CVSS Assessment

Metric Value
Score 7.5 / 10.0
Severity High
Vector CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

CVSS v3.1 Calculator

Summary

The Telegram file download functions in download.ts make HTTP fetch calls without any timeout or AbortController. If Telegram's API becomes slow or unresponsive, these calls block indefinitely, potentially hanging the entire message processing pipeline.

Affected Code

File: src/telegram/download.ts:12-13,34

export async function getTelegramFile(token: string, fileId: string): Promise<TelegramFileInfo> {
  const res = await fetch(  // NO TIMEOUT - can hang forever
    `https://api.telegram.org/bot${token}/getFile?file_id=${encodeURIComponent(fileId)}`,
  );
  // ...
}

export async function downloadTelegramFile(
  token: string,
  fileInfo: TelegramFileInfo,
): Promise<SavedMedia> {
  // ...
  const res = await fetch(url);  // Line 34 - NO TIMEOUT
  // ...
}

Attack Surface

How is this reached?

  • Network (HTTP/WebSocket endpoint, API call)
  • Adjacent Network (same LAN, requires network proximity)
  • Local (local file, CLI argument, environment variable)
  • Physical (requires physical access to machine)

Authentication required?

  • None (unauthenticated/public access)
  • Low (any authenticated user)
  • High (admin/privileged user only)

Entry point: Any Telegram message with an attachment (photo, document, video, etc.) triggers file download via these functions.

Exploit Conditions

Complexity:

  • Low (no special conditions, works reliably)
  • High (requires race condition, specific config, or timing)

User interaction:

  • None (automatic, no victim action needed)
  • Required (victim must click, visit, or perform action)

Prerequisites: Telegram API must experience slowdown or become unresponsive. This can occur due to:

  • Telegram infrastructure issues
  • Network connectivity problems
  • Rate limiting or API degradation
  • Malicious network interception (MITM causing TCP slowloris)

Impact Assessment

Scope:

  • Unchanged (impact limited to vulnerable component)
  • Changed (can affect other components, escape sandbox)

What can an attacker do?

Impact Type Level Description
Confidentiality None No data exposure
Integrity None No data modification
Availability High Message processing hangs, connection pools exhaust, cascade failures in async workflows

Steps to Reproduce

  1. Configure OpenClaw with Telegram integration
  2. Simulate slow Telegram API responses (e.g., using a proxy that delays responses)
  3. Send a message with an attachment to the bot
  4. Observe that the gateway hangs waiting for the fetch to complete
  5. Additional messages queue up, eventually exhausting resources

Recommended Fix

Add AbortController with timeout, consistent with patterns used elsewhere in the codebase (e.g., chrome.ts):

import { withTimeout } from "../web/web-shared.js";

const TELEGRAM_FETCH_TIMEOUT_MS = 30_000; // 30 seconds

export async function getTelegramFile(token: string, fileId: string): Promise<TelegramFileInfo> {
  const controller = new AbortController();
  const timeoutId = setTimeout(() => controller.abort(), TELEGRAM_FETCH_TIMEOUT_MS);

  try {
    const res = await fetch(
      `https://api.telegram.org/bot${token}/getFile?file_id=${encodeURIComponent(fileId)}`,
      { signal: controller.signal }
    );
    // ...
  } finally {
    clearTimeout(timeoutId);
  }
}

References

  • CWE: CWE-400 - Uncontrolled Resource Consumption

Activity

  1. added a commit that references this issue on Feb 2, 2026
    c8fa1b6
  2. added a commit that references this issue on Feb 2, 2026
    d46b489
  3. added a commit that references this issue on Feb 3, 2026
    e27eb49
  4. added a commit that references this issue on Feb 3, 2026
    c2fd178
  5. added a commit that references this issue on Feb 3, 2026
    3b77615
  6. added a commit that references this issue on Feb 4, 2026
    a4d87ff
  7. added a commit that references this issue on Feb 5, 2026
    5969ef8
  8. added a commit that references this issue on Feb 5, 2026
    8b1527c
  9. added a commit that references this issue on Feb 10, 2026
    ec0b43d
  10. added 2 commits that reference this issue on Feb 12, 2026
    8ea07f9
    1da8b0d
  11. locked as resolved and limited conversation to collaborators on Mar 7, 2026
  12. added a commit that references this issue on Apr 28, 2026
    7c50ef1
  13. added a commit that references this issue on May 2, 2026
    2a8438a
  14. added a commit that references this issue on May 9, 2026
    ee91228
  15. added a commit that references this issue on Oct 11, 2026
    134b6e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions