Repository navigation
fix(telegram): bound Bot API response reads to prevent OOM - #97271
vincentkoc merged 2 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 27, 2026, 1:07 PM ET / 17:07 UTC. Summary PR surface: Source +23, Tests +14, Other +142. Total +179 across 5 files. Reproducibility: Do we have a high-confidence way to reproduce the issue? Yes from source and PR proof: current main still calls unbounded Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the focused bounded-read hardening after maintainers accept the 4 MiB fail-closed policy, with the getChat companion coverage reviewed as separate but related work. Do we have a high-confidence way to reproduce the issue? Do we have a high-confidence way to reproduce the issue? Yes from source and PR proof: current main still calls unbounded Is this the best way to solve the issue? Is this the best way to solve the issue? Yes for the targeted paths: using the existing plugin SDK response-limit helper is the narrow owner-boundary fix, while the cap value and getChat sequencing remain maintainer decisions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1bdde6695030. Label changesLabel justifications:
Evidence reviewedPR surface: Source +23, Tests +14, Other +142. Total +179 across 5 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
…97271) * fix(telegram): bound Bot API response reads to prevent OOM * fix(scripts): make proof-telegram-bound.mjs lint-clean --------- Co-authored-by: NIO <[email protected]>
…97271) * fix(telegram): bound Bot API response reads to prevent OOM * fix(scripts): make proof-telegram-bound.mjs lint-clean --------- Co-authored-by: NIO <[email protected]>
…97271) * fix(telegram): bound Bot API response reads to prevent OOM * fix(scripts): make proof-telegram-bound.mjs lint-clean --------- Co-authored-by: NIO <[email protected]> (cherry picked from commit a07d59e)
…97271) * fix(telegram): bound Bot API response reads to prevent OOM * fix(scripts): make proof-telegram-bound.mjs lint-clean --------- Co-authored-by: NIO <[email protected]> (cherry picked from commit a07d59e)
…97271) * fix(telegram): bound Bot API response reads to prevent OOM * fix(scripts): make proof-telegram-bound.mjs lint-clean --------- Co-authored-by: NIO <[email protected]> (cherry picked from commit a07d59e)
…97271) * fix(telegram): bound Bot API response reads to prevent OOM * fix(scripts): make proof-telegram-bound.mjs lint-clean --------- Co-authored-by: NIO <[email protected]> (cherry picked from commit a07d59e)
What Problem This Solves
Three Telegram Bot API response paths use unbounded
await response.json()on the success path, leaving the gateway exposed to OOM if a misbehaving or hostile endpoint streams an oversized response body:extensions/telegram/src/probe.tsgetMe,getWebhookInfoextensions/telegram/src/audit-membership-runtime.tsgetChatMemberextensions/telegram/src/telegram-ingress-worker.runtime.tsgetUpdatesLegitimate Telegram Bot API responses for these endpoints are tiny (< 1 KiB for
getMe/getChatMember, < 500 KiB for 100getUpdates). An unbounded read allows any interceptor or rogue endpoint to force the gateway to buffer an arbitrarily large body before returning control.This continues the response-limit campaign already merged for Discord, xAI, fal, MiniMax, OpenRouter, embeddings, speech, and other surfaces.
Changes
extensions/telegram/src/probe.tsreadResponseWithLimitfromopenclaw/plugin-sdk/response-limit-runtimeTELEGRAM_BOT_API_MAX_RESPONSE_BYTES = 4 MiBconstantawait meRes.json()(getMe) withreadResponseWithLimit+JSON.parseawait webhookRes.json()(getWebhookInfo) withreadResponseWithLimit+JSON.parseextensions/telegram/src/audit-membership-runtime.tsreadResponseWithLimitfromopenclaw/plugin-sdk/response-limit-runtimeTELEGRAM_BOT_API_MAX_RESPONSE_BYTES = 4 MiBconstantawait res.json()(getChatMember) withreadResponseWithLimit+JSON.parseextensions/telegram/src/telegram-ingress-worker.runtime.tsreadResponseWithLimitfromopenclaw/plugin-sdk/response-limit-runtimeTELEGRAM_GET_UPDATES_MAX_RESPONSE_BYTES = 4 MiBconstantawait response.json()(getUpdates) withreadResponseWithLimit+JSON.parseextensions/telegram/src/probe.test.tsvi.mockpass-through foropenclaw/plugin-sdk/response-limit-runtimeso existingplain-object fetch mocks continue to work without requiring real
Responsebody streamsscripts/proof-telegram-bound.mjs— local proof script (see Evidence below)Real behavior proof
response.json()on Telegram Bot API success paths — a misbehaving endpoint can stream an arbitrarily large body, exhausting gateway heap before the read returnsnode:httpcreateServeron127.0.0.1:0, Node v22+, macOSreadResponseWithLimitcancelled the stream after reading ~1.1 MiB (server wrote ~1.4 MiB total including HTTP framing); the unbounded.json()negative-control read the full 25 MiB; a normal 99-byte happy-path response parsed correctlyapi-fetch.tsgetChatpath (already guarded by.catch(() => null), lower risk)shen@192 openclaw % node --import tsx/esm scripts/proof-telegram-bound.mjs
[proof] Telegram Bot API response-limit
cap=1048576 bytes (1 MiB), would-stream≈25165824 bytes (24 MiB)
ok: oversized body rejected (threw=true)
ok: error message contains limit info: "Content too large: 1072391 bytes (limit: 1048576 bytes)"
ok: server wrote ≈1572885 bytes, well below 24 MiB (stream was cancelled early)
ok: negative control: unbounded .json() caused server to write ≈25165847 bytes (>> 1048576)
ok: small response parsed correctly (ok=true id=123456789)
ok: result bytes within cap (99 < 1048576)
ALL PROOF ASSERTIONS PASSED
shen@192 openclaw % pnpm test extensions/telegram/src/probe.test.ts
$ node scripts/test-projects.mjs extensions/telegram/src/probe.test.ts
[test] starting test/vitest/vitest.extension-telegram.config.ts
RUN v4.1.8 /Users/shen/Documents/GitHub/openclaw
✓ extension-telegram extensions/telegram/src/probe.test.ts (12 tests) 19ms
Test Files 1 passed (1)
Tests 12 passed (12)
Start at 21:56:43
Duration 2.09s (transform 1.17s, setup 253ms, import 1.74s, tests 19ms, environment 0ms)
[test] passed 1 Vitest shard in 5.36s
Evidence
Tests and validation
pnpm test extensions/telegram/src/probe.test.ts— 12/12 passpnpm test extensions/telegram— 2214/2218 pass (4 pre-existing failures inbot.create-telegram-bot.channel-post-media.test.ts, confirmed onmainbefore this change)scripts/proof-telegram-bound.mjs— ALL PROOF ASSERTIONS PASSEDRisk checklist
telegram-ingress-worker.runtime.ts(getUpdateshot path); new import fromopenclaw/plugin-sdk/response-limit-runtimein the worker threadreadResponseWithLimituses only standard Web Streams +BufferAPIs available in Node.js worker threads; the 4 MiB cap is far above the largest realistic Bot API responseCurrent review state