Skip to content

feat(api): add request size protection middleware (#688) - #746

Open
ravendevhub wants to merge 1 commit into
Core-Foundry:mainfrom
ravendevhub:feat/request-size-protection-688
Open

feat(api): add request size protection middleware (#688)#746
ravendevhub wants to merge 1 commit into
Core-Foundry:mainfrom
ravendevhub:feat/request-size-protection-688

Conversation

@ravendevhub

Copy link
Copy Markdown

Summary

Resolves #688 by introducing an API request size protection middleware (listener/src/api/request-size-limiter.ts) that enforces configurable byte limits on incoming payloads, fast-rejects oversized Content-Length headers, and pauses/destroys streaming data to prevent memory exhaustion and DoS attacks.

Changes

  1. Request Size Limiter Middleware (listener/src/api/request-size-limiter.ts):
    • Inspects Content-Length headers and incoming stream chunks against maxSizeBytes.
    • Returns structured HTTP 413 PAYLOAD_TOO_LARGE error responses.
    • Cleans up event listeners and pauses input stream to prevent memory buffering.
  2. Automated Unit Tests (listener/src/api/request-size-limiter.test.ts):
    • Tests within-limit requests, oversized header rejections, and streaming chunk overflows.
  3. Documentation (docs/REQUEST_SIZE_PROTECTION.md):
    • Documents threat model, configuration options, and error schemas.

Acceptance Criteria

  • A configurable request-size limit exists.
  • Oversized requests receive an appropriate error.
  • The server does not attempt to process rejected payloads.
  • Tests cover boundary conditions.

- Enforce configurable request body size limits with HTTP 413 Payload Too Large
- Inspect Content-Length header for fast rejection
- Monitor and abort streaming chunked transfers to prevent memory exhaustion
- Add test suite in request-size-limiter.test.ts and docs in docs/REQUEST_SIZE_PROTECTION.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add API Request Size Protection

1 participant