Skip to content

security(discord): bound image/animation/attachment HTTP response reads - #60222

Closed
isheng-eqi wants to merge 5 commits into
NousResearch:mainfrom
isheng-eqi:fix/discord-image-download-bounds
Closed

security(discord): bound image/animation/attachment HTTP response reads#60222
isheng-eqi wants to merge 5 commits into
NousResearch:mainfrom
isheng-eqi:fix/discord-image-download-bounds

Conversation

@isheng-eqi

@isheng-eqi isheng-eqi commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Extends the Discord resource-bounding pass (#60122, #60112, #60113) to four HTTP response reads for image/animation/attachment downloads that were left unbounded.

An attacker or misconfigured CDN serving a multi-GB response to an await resp.read() call in the Discord adapter could exhaust memory and crash the bot.

Related Issue

Fixes sibling paths of the Discord bounding pass (#60122, #60112).

Type of Change

  • Bug fix
  • Security fix

Changes Made

  • plugins/platforms/discord/adapter.py: Add _read_response_bytes_bounded() helper, constants (50MB/100MB). Replace 4 unbounded await resp.read() calls.
  • tests/gateway/test_discord_image_download_bounds.py: Unit tests

The gateway already strips stale dangerous-confirmation text from
replayed history (NousResearch#60110, NousResearch#60117 — fix for NousResearch#59607). The TUI gateway
has two session resume paths that sanitize replay history but do not
strip stale dangerous confirmations, leaving the same vulnerability
unaddressed in TUI sessions.

Add strip_stale_dangerous_confirmations() after sanitize_replay_history()
in both TUI resume paths (resume_session and the WebUI resume path).

Refs: NousResearch#59607, NousResearch#60110, NousResearch#60117
The recent Discord resource-bounding pass (NousResearch#60122, NousResearch#60112, NousResearch#60113)
added limits for REST JSON/error response bodies and component label
UTF-16 lengths. Four HTTP response reads for image/animation/attachment
downloads were left unbounded — an oversized response from a CDN or
external URL could OOM the bot.

Add _DISCORD_IMAGE_DOWNLOAD_MAX_BYTES (50 MB) and
_DISCORD_ATTACHMENT_DOWNLOAD_MAX_BYTES (100 MB) constants, a shared
_read_response_bytes_bounded() helper, and apply bounds to:
- Batch image download (adapter.py ~2467)
- Single image download (adapter.py ~3555)
- Animation/GIF download (adapter.py ~3634)
- Attachment download (adapter.py ~5799)

Refs: NousResearch#60122, NousResearch#60112
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/discord Discord bot adapter P3 Low — cosmetic, nice to have labels Jul 7, 2026
@isheng-eqi isheng-eqi changed the title fix(discord): bound image/animation/attachment HTTP response reads security(discord): bound image/animation/attachment HTTP response reads Jul 7, 2026
@isheng-eqi

Copy link
Copy Markdown
Contributor Author

Branch contaminated — rebuilding with clean base from upstream/main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/discord Discord bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants