bug(a2a): ASGI HTTP server lacks DoS protection — no body size limit, header count limit, or rate limiting #3637

Open
opened 2026-04-05 21:01:45 +00:00 by freemo · 1 comment
Owner

Background and Context

The specification (lines 9229–9230) explicitly defines DoS protection requirements for the server layer:

  • Max Content-Length: 10 MB — messages exceeding this are rejected with a warning log (DoS guard)
  • Max header lines: 32 — headers with more lines are rejected with a warning log (DoS guard)

These limits are correctly implemented in the LSP server (src/cleveragents/lsp/server.py: MAX_CONTENT_LENGTH = 10 * 1024 * 1024, MAX_HEADER_LINES = 32).

However, the ASGI HTTP server (src/cleveragents/a2a/asgi.py) has no equivalent protections:

  1. No Content-Length validation on incoming HTTP requests
  2. No request body size limit (the receive callable is deleted: del receive)
  3. No rate limiting (requests per second/minute per client)
  4. No header count limit
  5. No 413 / 429 / 431 responses for limit violations

Additionally, the spec mentions rate_limit: "10/min" as a configuration option for actors (specification.md line 22057), but no HTTP-level rate limiting middleware exists anywhere in the server stack.

Current Behavior

src/cleveragents/a2a/asgi.py has no body size limits, no rate limiting, and no header count enforcement. A malicious client could send arbitrarily large requests or flood the server with requests, causing resource exhaustion.

Expected Behavior (from spec)

Server-mode HTTP endpoints must enforce:

  • Max request body size: 10 MB → reject with HTTP 413 + warning log
  • Max header count: 32 → reject with HTTP 431 + warning log
  • Rate limiting per client IP or API key → reject with HTTP 429
  • Warning logs emitted when limits are exceeded (matching LSP server pattern)

Code Location

src/cleveragents/a2a/asgi.py — entire file lacks DoS protections

The LSP server (src/cleveragents/lsp/server.py) correctly implements the equivalent limits and serves as the reference implementation.


Backlog note: This issue was discovered during autonomous operation
on milestone v3.3.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.

Metadata

  • Branch: fix/asgi-dos-protection
  • Commit Message: fix(a2a): add DoS protection middleware to ASGI HTTP server
  • Milestone: (none — backlog)
  • Parent Epic: #400

Subtasks

  • Implement ASGI middleware that validates Content-Length header ≤ 10 MB; reject with HTTP 413 and emit warning log if exceeded
  • Implement ASGI middleware that counts request headers and rejects with HTTP 431 + warning log if count exceeds 32
  • Implement rate-limiting middleware (token bucket or sliding window) per client IP; reject with HTTP 429 when limit exceeded
  • Emit warning log entries for all limit violations, matching the pattern used in lsp/server.py
  • Wire all middleware into the ASGI app in src/cleveragents/a2a/asgi.py
  • Unit tests: verify oversized request body (> 10 MB) returns 413
  • Unit tests: verify excess headers (> 32) returns 431
  • Unit tests: verify rate-limited client receives 429
  • Verify coverage ≥ 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

  • All subtasks above are completed and checked off
  • ASGI middleware enforces Content-Length ≤ 10 MB (reject with HTTP 413)
  • ASGI middleware enforces max header count ≤ 32 (reject with HTTP 431)
  • Rate limiting middleware configured (e.g., slowapi or custom token bucket); clients exceeding the limit receive HTTP 429
  • Warning logs emitted when limits are exceeded (matching LSP server pattern in lsp/server.py)
  • Unit tests verify that oversized requests are rejected with 413
  • Unit tests verify that header-flooding requests are rejected with 431
  • Unit tests verify that rate-limited clients receive 429
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done
  • All nox stages pass
  • Coverage ≥ 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Background and Context The specification (lines 9229–9230) explicitly defines DoS protection requirements for the server layer: - **Max Content-Length: 10 MB** — messages exceeding this are rejected with a warning log (DoS guard) - **Max header lines: 32** — headers with more lines are rejected with a warning log (DoS guard) These limits are correctly implemented in the **LSP server** (`src/cleveragents/lsp/server.py`: `MAX_CONTENT_LENGTH = 10 * 1024 * 1024`, `MAX_HEADER_LINES = 32`). However, the **ASGI HTTP server** (`src/cleveragents/a2a/asgi.py`) has **no equivalent protections**: 1. No `Content-Length` validation on incoming HTTP requests 2. No request body size limit (the `receive` callable is deleted: `del receive`) 3. No rate limiting (requests per second/minute per client) 4. No header count limit 5. No 413 / 429 / 431 responses for limit violations Additionally, the spec mentions `rate_limit: "10/min"` as a configuration option for actors (specification.md line 22057), but no HTTP-level rate limiting middleware exists anywhere in the server stack. ## Current Behavior `src/cleveragents/a2a/asgi.py` has no body size limits, no rate limiting, and no header count enforcement. A malicious client could send arbitrarily large requests or flood the server with requests, causing resource exhaustion. ## Expected Behavior (from spec) Server-mode HTTP endpoints must enforce: - Max request body size: 10 MB → reject with HTTP 413 + warning log - Max header count: 32 → reject with HTTP 431 + warning log - Rate limiting per client IP or API key → reject with HTTP 429 - Warning logs emitted when limits are exceeded (matching LSP server pattern) ## Code Location `src/cleveragents/a2a/asgi.py` — entire file lacks DoS protections The LSP server (`src/cleveragents/lsp/server.py`) correctly implements the equivalent limits and serves as the reference implementation. --- > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.3.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. ## Metadata - **Branch**: `fix/asgi-dos-protection` - **Commit Message**: `fix(a2a): add DoS protection middleware to ASGI HTTP server` - **Milestone**: *(none — backlog)* - **Parent Epic**: #400 ## Subtasks - [ ] Implement ASGI middleware that validates `Content-Length` header ≤ 10 MB; reject with HTTP 413 and emit warning log if exceeded - [ ] Implement ASGI middleware that counts request headers and rejects with HTTP 431 + warning log if count exceeds 32 - [ ] Implement rate-limiting middleware (token bucket or sliding window) per client IP; reject with HTTP 429 when limit exceeded - [ ] Emit warning log entries for all limit violations, matching the pattern used in `lsp/server.py` - [ ] Wire all middleware into the ASGI app in `src/cleveragents/a2a/asgi.py` - [ ] Unit tests: verify oversized request body (> 10 MB) returns 413 - [ ] Unit tests: verify excess headers (> 32) returns 431 - [ ] Unit tests: verify rate-limited client receives 429 - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done - [ ] All subtasks above are completed and checked off - [ ] ASGI middleware enforces `Content-Length` ≤ 10 MB (reject with HTTP 413) - [ ] ASGI middleware enforces max header count ≤ 32 (reject with HTTP 431) - [ ] Rate limiting middleware configured (e.g., `slowapi` or custom token bucket); clients exceeding the limit receive HTTP 429 - [ ] Warning logs emitted when limits are exceeded (matching LSP server pattern in `lsp/server.py`) - [ ] Unit tests verify that oversized requests are rejected with 413 - [ ] Unit tests verify that header-flooding requests are rejected with 431 - [ ] Unit tests verify that rate-limited clients receive 429 - [ ] A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation - [ ] The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly - [ ] The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done - All nox stages pass - Coverage ≥ 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Backlog — Security hardening for the ASGI HTTP server. The LSP server has these protections; the ASGI server does not.
  • Story Points: 5 — L — Requires implementing 3 middleware components (body size, header count, rate limiting), wiring them into the ASGI app, and comprehensive unit tests for each limit type.
  • MoSCoW: Should Have — The spec explicitly defines DoS protection requirements (10 MB body limit, 32 header limit). These are security requirements that should be implemented for server mode, even though server mode is not yet fully operational. The LSP server already implements them correctly.
  • Parent Epic: #400

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Backlog — Security hardening for the ASGI HTTP server. The LSP server has these protections; the ASGI server does not. - **Story Points**: 5 — L — Requires implementing 3 middleware components (body size, header count, rate limiting), wiring them into the ASGI app, and comprehensive unit tests for each limit type. - **MoSCoW**: Should Have — The spec explicitly defines DoS protection requirements (10 MB body limit, 32 header limit). These are security requirements that should be implemented for server mode, even though server mode is not yet fully operational. The LSP server already implements them correctly. - **Parent Epic**: #400 --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#400 Epic: Post-MVP Security
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3637
No description provided.