Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enforce FormParser limits in parser callbacks#3331

Merged
Kludex merged 1 commit into
mainfrom
enforce-form-limits-in-callbacks
Jun 12, 2026
Merged

Enforce FormParser limits in parser callbacks#3331
Kludex merged 1 commit into
mainfrom
enforce-form-limits-in-callbacks

Conversation

@Kludex

@Kludex Kludex commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Follow-up to #3329. The max_fields and max_part_size checks ran while draining buffered messages, after QuerystringParser.write() had already tokenized the whole chunk. When a application/x-www-form-urlencoded body arrives as a single chunk (e.g. via the test client, or after request.body() has cached it), the parser tokenizes and buffers every field before the drain loop reaches the limit check.

This moves the count and size checks into the on_field_* callbacks, which run during write(), so parsing stops as soon as a limit is crossed regardless of how the body is chunked. Behaviour and error messages are unchanged; only the point at which parsing aborts moves earlier.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

Review in cubic

The limit checks ran while draining buffered messages, after `QuerystringParser.write()` had already tokenized the whole chunk. For a body delivered as a single chunk (e.g. via the test client or after `request.body()` cached it), every field was buffered before the limit was reached. Move the count and size checks into the callbacks so parsing stops as soon as a limit is crossed.
@github-actions

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@Kludex Kludex merged commit 25b8e17 into main Jun 12, 2026
13 checks passed
@Kludex Kludex deleted the enforce-form-limits-in-callbacks branch June 12, 2026 09:16
Kludex added a commit that referenced this pull request Jun 12, 2026
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