Skip to content

Limit the number of header lines per multipart form-data part#2497

Merged
yhirose merged 1 commit into
yhirose:masterfrom
superm1:superm1/SWSPLAT-23636
Jul 21, 2026
Merged

Limit the number of header lines per multipart form-data part#2497
yhirose merged 1 commit into
yhirose:masterfrom
superm1:superm1/SWSPLAT-23636

Conversation

@superm1

@superm1 superm1 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

The multipart/form-data parser bounded the length of each individual header line via CPPHTTPLIB_HEADER_MAX_LENGTH but did not cap how many header lines a single part could contain. Within the overall payload limit, a client could pack a large number of small header lines into one part, each of which is parsed twice, inflating CPU usage.

This adds a per-part header-line counter that resets when a new entry begins and aborts parsing once it reaches CPPHTTPLIB_HEADER_MAX_COUNT, mirroring the limit already enforced by read_headers() for request headers.

@yhirose

yhirose commented Jul 18, 2026

Copy link
Copy Markdown
Owner

@superm1 thanks for the PR. Could you please add at least one unit test?

The multipart/form-data parser bounded the length of each individual
header line via CPPHTTPLIB_HEADER_MAX_LENGTH but did not cap how many
header lines a single part could contain. Within the overall payload
limit, a client could pack a large number of small header lines into
one part, each of which is parsed twice, inflating CPU usage.

Add a per-part header-line counter that resets when a new entry begins
and abort parsing once it reaches CPPHTTPLIB_HEADER_MAX_COUNT, mirroring
the limit already enforced by read_headers() for request headers.
@superm1
superm1 force-pushed the superm1/SWSPLAT-23636 branch from 5425ce9 to 877a52f Compare July 19, 2026 00:20
@superm1

superm1 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Added!

@yhirose
yhirose merged commit bbd56a7 into yhirose:master Jul 21, 2026
@yhirose

yhirose commented Jul 21, 2026

Copy link
Copy Markdown
Owner

@superm1 thanks for this contribution!

@superm1
superm1 deleted the superm1/SWSPLAT-23636 branch July 22, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants