Skip to content

fix: don't parse request bodies before auth #798

Closed

Description

@uniqueg

Connexion 2 builds its request object (connexion.apis.flask_api.FlaskApi.get_request)
at the start of every operation's decorator chain, before the security
decorator, and reads flask.request.form, files and get_data() there.
So the body of every request is parsed before its token is checked.

For application/x-www-form-urlencoded, Werkzeug reads the whole body at
once and applies neither MAX_FORM_MEMORY_SIZE nor MAX_FORM_PARTS
(werkzeug.formparser.FormDataParser._parse_urlencoded). An anonymous
client can therefore make each request parse up to server.max_content_length
of fields: in proWES (10 MiB limit), a body of a& repeated took about
2.2 s and about 400 MB per request before the 401 (found in the review of
elixir-cloud-aai/prowes#185). This affects every operation, not only those
with form bodies.

Options:

  • Refuse URL-encoded bodies larger than a configurable limit (default, e.g.,
    MAX_FORM_MEMORY_SIZE) in a before_request hook of FOCA, with 413,
    for all operations; or refuse bodies on operations that declare none.

  • Validate the token before Connexion builds its request (e.g., a FOCA
    before_request hook for operations with bearer security), so that
    unauthenticated requests get 401 unread.

  • Regression test: an anonymous large URL-encoded request is answered
    without parsing the form (patched Request.form).

  • Docs: security notes and the configuration of the limit.

Related: FOCA sets no default for Flask's MAX_CONTENT_LENGTH either, so apps without their own limit parse and validate bodies of any size before they look at them (in DRS-Filer, about 5 s of CPU per worker for an anonymous 6 MB OPTIONS /objects, found in the review of elixir-cloud-aai/drs-filer#98). A configurable default limit, with Werkzeug's RequestEntityTooLarge mapped to problem details (413), belongs in the same fix.

Activity

  1. added
    priority: medium
    status: triage
    type: bug
    workload: hours
    on Nov 19, 2026
  2. added
    status: in progress
    and removed
    status: triage
    on Nov 21, 2026
  3. self-assigned this
    on Nov 21, 2026
  4. removed
    status: in progress
    on Nov 23, 2026
  5. added this to the v0.23.0 milestone on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: mediumtype: bugworkload: hours

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions