Skip to content

Events: stop reading oversized request bodies, and document the size limits #404

Closed

Description

@JuroOravec

Citry's Events endpoints already limit a request in two ways: the body is capped at 1 MiB (an undocumented _max_envelope_bytes setting), and one envelope carries at most 16 calls (payload_too_large). This issue covers what those limits miss.

What is missing

  1. The ASGI adapter reads the whole body into memory before the cap is checked. It should stop reading once the body passes the cap.
  2. The WSGI adapter trusts Content-Length. It should read at most cap + 1 bytes whatever the header says, including a chunked body without one.
  3. The Django adapter reads request.body, which holds up to Django's own 2.5 MB limit in memory, and an upload that middleware parses first has no total limit at all.
  4. The cap is a private, undocumented setting. It should be a documented setting, with bad values rejected.
  5. Form fields are not counted. A small urlencoded body can still hold many short fields.

Uploaded files need no separate limit: Citry's built-in payload codecs do not parse multipart bodies, so a custom codec that builds files reads them from the body, and the body cap bounds the body once every adapter enforces it. On Django, an upload that middleware parsed first is checked against its declared size.

Plan

Setting (in extensions_defaults["events"]) What it limits Default
_max_body_bytes (renamed from _max_envelope_bytes) the request body 1 MiB
_max_form_fields fields in one urlencoded form post 1,000
  • Both are engine-wide only; a value that is not a positive int raises ValueError when Citry(...) is created.
  • A request over either limit gets HTTP 413 with the existing code payload_too_large, before parsing (the batch route answers HTTP 200 with the 413 error inside the result envelope, as the protocol requires). On Django, these limits govern event requests in place of DATA_UPLOAD_MAX_MEMORY_SIZE.
  • Routes tell the host adapters their limit through an optional URLRoute.max_body_bytes callable; the ASGI, WSGI, and Django adapters read at most one byte past it.

Done when

Each adapter has a test that counts the bytes it reads from an oversized body (with a lying Content-Length and with a chunked body without one), the form field limit has a test, both settings are documented in the security guide, and the CHANGELOG has an entry.

Activity

  1. changed the title [-]Events: add request size, upload, field and batch-count limits[/-] [+]Events: stop reading oversized request bodies, and document the size limits[/+] on Oct 27, 2026
  2. added a commit that references this issue on Oct 28, 2026
    0727ccd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions