Skip to content

security: limit request body size to 1MB in FastAPI and Nginx#147

Merged
YaronZaki merged 2 commits into
Quantarq:mainfrom
dominiccreates:feature/body-size-limit
Jun 19, 2026
Merged

security: limit request body size to 1MB in FastAPI and Nginx#147
YaronZaki merged 2 commits into
Quantarq:mainfrom
dominiccreates:feature/body-size-limit

Conversation

@dominiccreates

Copy link
Copy Markdown
Contributor

this pr closes #46 Title: security: limit request body size to 1MB in FastAPI and Nginx

Summary No request body size limits were configured in FastAPI or Nginx. Large payloads could cause DoS via memory exhaustion before application-level validation runs. This PR introduces size limits at both layers to mitigate this vulnerability.

Changes

Nginx Configs: Added client_max_body_size 1M; to both
quantara.conf
and
quantara_dev.conf
to reject oversized requests at the edge.
FastAPI Middleware: Implemented a custom ASGI
MaxBodySizeMiddleware
to enforce a 1MB limit on request bodies and return a 413 Request Entity Too Large response.
App Integration: Registered the middleware in
main.py
before the rate limiter middleware.
Integration Tests: Added
test_body_size_limit.py
to verify request body size limitation for normal, chunked/streamed, and oversized requests.

@YaronZaki YaronZaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@YaronZaki YaronZaki merged commit 317a5d5 into Quantarq:main Jun 19, 2026
4 checks passed
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.

security: Add request body size limits to FastAPI

2 participants