security(gateway): set explicit client_max_size on 3 uncapped aiohttp servers (#59180)

Sibling sweep from the #58902 raft review found aiohttp servers still
running on the implicit 1 MiB default with no explicit body cap:

- bluebubbles webhook (127.0.0.1): 1 MiB explicit cap — events are small
  JSON/form payloads; attachments arrive via the REST API
- teams Bot Framework listener (0.0.0.0 bind — most exposed): 1 MiB cap;
  activities are JSON well under that
- hermes proxy server: 10 MB cap mirroring api_server's MAX_REQUEST_BYTES
  (chat-completion payloads can be large, but must stay bounded)

client_max_size bounds every read path including chunked transfer-encoding
requests that carry no Content-Length (#58536/#58902 pattern).

Deliberately excluded: feishu, whatsapp_cloud, sms, line, wecom, msgraph —
open contributor PRs (#54938, #54944, #54620, #54931, #54934, #25296)
already cover those; reviewing them separately preserves their credit.

3 regression tests pin the wiring.
This commit is contained in:
Teknium 2026-07-05 14:48:28 -07:00 committed by GitHub
parent 0823230545
commit 8986981df4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 59 additions and 4 deletions

View file

@ -50,6 +50,10 @@ _HOP_BY_HOP_HEADERS = frozenset(
DEFAULT_PORT = 8645
DEFAULT_HOST = "127.0.0.1"
# Body cap for forwarded requests. Chat-completion payloads with long agent
# conversations can be large; mirror api_server's MAX_REQUEST_BYTES (10 MB).
# client_max_size bounds every read path, including chunked bodies.
MAX_REQUEST_BYTES = 10_000_000
def _json_error(status: int, message: str, code: str = "proxy_error") -> "web.Response":
@ -89,7 +93,7 @@ def create_app(adapter: UpstreamAdapter) -> "web.Application":
"pip install 'hermes-agent[messaging]' or `pip install aiohttp`."
)
app = web.Application()
app = web.Application(client_max_size=MAX_REQUEST_BYTES)
# AppKey ensures forward-compat with future aiohttp versions that strip
# bare-string keys.
_adapter_key = web.AppKey("adapter", UpstreamAdapter)