Skip to content

Scan the Quart query as the app reads it - #784

Open
iacobdaniel wants to merge 1 commit into
mainfrom
fix/quart-query-from-request-args
Open

iacobdaniel wants to merge 1 commit into
mainfrom
fix/quart-query-from-request-args

Conversation

@iacobdaniel

Copy link
Copy Markdown
Contributor

Werkzeug keeps an invalid escape such as %ff as is, while parse_qs turns it into U+FFFD, so attacks in request.args were missed. Keep the parse_qs reading too, for apps that parse the query themselves.

values = query.setdefault(key, [])
if values != raw_values:
seen = set(values)
values.extend(value for value in raw_values if value not in seen)

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.

🟡 Medium - Repeated invalid escapes can amplify Quart request memory

A client can send a large query containing repeated escapes such as a=%ff; the ASGI context first stores the parse_qs values and the Quart hook then retains a second framework-decoded list, with set_framework_query appending both readings to context.query. Because this happens before every handler and the repository defines no query-size bound, concurrent requests can use roughly twice the parsed value storage (and the extra parse/copy) to exhaust a worker's memory and availability.

Show fix

Avoid retaining both full value lists for unbounded query input, or enforce a strict query/field budget before parsing and merging. If both representations must be scanned, cap the combined values and discard temporary parser structures as soon as the bounded representation is built.

More info - Reply on this comment to give feedback or ignore the issue.

This branch has not been deployed

No deployments
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.

1 participant