Repository navigation
Description
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 abefore_requesthook of FOCA, with413,
for all operations; or refuse bodies on operations that declare none. -
Validate the token before Connexion builds its request (e.g., a FOCA
before_requesthook for operations with bearer security), so that
unauthenticated requests get401unread. -
Regression test: an anonymous large URL-encoded request is answered
without parsing the form (patchedRequest.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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
docs: name explicit null limits in the migration