Skip to content

fix(webhook): enforce chunked body limits - #3955

Closed
Gutslabs wants to merge 1 commit into
NousResearch:mainfrom
Gutslabs:fix/webhook-chunked-body-limit
Closed

fix(webhook): enforce chunked body limits#3955
Gutslabs wants to merge 1 commit into
NousResearch:mainfrom
Gutslabs:fix/webhook-chunked-body-limit

Conversation

@Gutslabs

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes webhook payload size enforcement for chunked requests.

Previously, the webhook adapter only rejected oversized payloads when Content-Length was present and over the configured max_body_bytes. Chunked requests omit Content-Length, so an oversized webhook body could still be fully read and accepted.

This change enforces the same limit for chunked bodies by configuring aiohttp's client_max_size, mapping HTTPRequestEntityTooLarge to a clean 413 response, and keeping a post-read size check as a defensive fallback.

Type of Change

  • Bug fix
  • Security fix
  • Tests

Changes Made

  • Set client_max_size on the webhook aiohttp app from max_body_bytes
  • Return 413 Payload too large when request.read() exceeds the limit
  • Keep an explicit post-read size check as a fallback
  • Added a regression test for oversized chunked request bodies

How to Test

  1. Run source .venv/bin/activate
  2. Run python -m pytest tests/gateway/test_webhook_adapter.py -q
  3. Send a chunked webhook request larger than max_body_bytes
  4. Confirm the adapter returns 413 instead of accepting the webhook

Notes

  • Manual repro before the fix: an oversized chunked request returned 202 Accepted
  • Manual repro after the fix: the same request returns 413 Payload too large
  • Full suite on current main still has unrelated failures in Slack, delegate credential resolution, transcription, website policy, and CLI tools reset tests

@alt-glitch alt-glitch added P2 Medium — degraded but workaround exists type/security Security vulnerability or hardening comp/gateway Gateway runner, session dispatch, delivery platform/webhook Webhook / API server labels May 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #12543 (issue) and #13336 (existing fix PR for same problem). May be duplicate of #13336.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #12543 (issue) and #13336 (existing fix PR for same problem). May be duplicate of #13336.

teknium1 added a commit that referenced this pull request Jul 5, 2026
…ked-limit

fix(gateway): enforce body-size limits on chunked requests (salvage #3955 + #3949)
liuhao1024 pushed a commit to liuhao1024/hermes-agent that referenced this pull request Jul 5, 2026
The webhook adapter enforced max_body_bytes only via the Content-Length
header; a Transfer-Encoding: chunked request (content_length=None) or a
spoofed small Content-Length bypassed the cap entirely and read the full
body (bounded only by aiohttp's implicit 1 MiB default, above any
operator-configured smaller limit).

- web.Application(client_max_size=max_body_bytes): aiohttp enforces the
  cap on every read path, chunked included
- catch HTTPRequestEntityTooLarge -> 413 (was swallowed into generic 400)
- post-read length re-check as defense in depth
- chunked-upload regression test

Manual port of PR NousResearch#3955 by @Gutslabs onto current main (handler had
been restructured since); authorship preserved.
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
The webhook adapter enforced max_body_bytes only via the Content-Length
header; a Transfer-Encoding: chunked request (content_length=None) or a
spoofed small Content-Length bypassed the cap entirely and read the full
body (bounded only by aiohttp's implicit 1 MiB default, above any
operator-configured smaller limit).

- web.Application(client_max_size=max_body_bytes): aiohttp enforces the
  cap on every read path, chunked included
- catch HTTPRequestEntityTooLarge -> 413 (was swallowed into generic 400)
- post-read length re-check as defense in depth
- chunked-upload regression test

Manual port of PR NousResearch#3955 by @Gutslabs onto current main (handler had
been restructured since); authorship preserved.
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…webhook-chunked-limit

fix(gateway): enforce body-size limits on chunked requests (salvage NousResearch#3955 + NousResearch#3949)
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the security fix. This is already implemented on current main via a manual port that preserved the contribution's authorship.

  • Automated hermes-sweeper review verified gateway/platforms/webhook.py:216 sets client_max_size=self._max_body_bytes.
  • gateway/platforms/webhook.py:504-518 maps aiohttp's oversized-body exception to 413 and retains the defensive post-read size check.
  • tests/gateway/test_webhook_adapter.py:1164-1184 covers an oversized chunked request and confirms it is not dispatched.
  • Commit ec29590a0f193590e24012ff6c165de5ba2930d6 is explicitly recorded as a manual port of fix(webhook): enforce chunked body limits #3955 and is included in v2026.7.7.

@teknium1 teknium1 closed this Jul 12, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 12, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
The webhook adapter enforced max_body_bytes only via the Content-Length
header; a Transfer-Encoding: chunked request (content_length=None) or a
spoofed small Content-Length bypassed the cap entirely and read the full
body (bounded only by aiohttp's implicit 1 MiB default, above any
operator-configured smaller limit).

- web.Application(client_max_size=max_body_bytes): aiohttp enforces the
  cap on every read path, chunked included
- catch HTTPRequestEntityTooLarge -> 413 (was swallowed into generic 400)
- post-read length re-check as defense in depth
- chunked-upload regression test

Manual port of PR NousResearch#3955 by @Gutslabs onto current main (handler had
been restructured since); authorship preserved.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…webhook-chunked-limit

fix(gateway): enforce body-size limits on chunked requests (salvage NousResearch#3955 + NousResearch#3949)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
The webhook adapter enforced max_body_bytes only via the Content-Length
header; a Transfer-Encoding: chunked request (content_length=None) or a
spoofed small Content-Length bypassed the cap entirely and read the full
body (bounded only by aiohttp's implicit 1 MiB default, above any
operator-configured smaller limit).

- web.Application(client_max_size=max_body_bytes): aiohttp enforces the
  cap on every read path, chunked included
- catch HTTPRequestEntityTooLarge -> 413 (was swallowed into generic 400)
- post-read length re-check as defense in depth
- chunked-upload regression test

Manual port of PR NousResearch#3955 by @Gutslabs onto current main (handler had
been restructured since); authorship preserved.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…webhook-chunked-limit

fix(gateway): enforce body-size limits on chunked requests (salvage NousResearch#3955 + NousResearch#3949)
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
The webhook adapter enforced max_body_bytes only via the Content-Length
header; a Transfer-Encoding: chunked request (content_length=None) or a
spoofed small Content-Length bypassed the cap entirely and read the full
body (bounded only by aiohttp's implicit 1 MiB default, above any
operator-configured smaller limit).

- web.Application(client_max_size=max_body_bytes): aiohttp enforces the
  cap on every read path, chunked included
- catch HTTPRequestEntityTooLarge -> 413 (was swallowed into generic 400)
- post-read length re-check as defense in depth
- chunked-upload regression test

Manual port of PR NousResearch#3955 by @Gutslabs onto current main (handler had
been restructured since); authorship preserved.
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…webhook-chunked-limit

fix(gateway): enforce body-size limits on chunked requests (salvage NousResearch#3955 + NousResearch#3949)
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 P2 Medium — degraded but workaround exists platform/webhook Webhook / API server sweeper:implemented-on-main Sweeper: behavior already present on current main type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants