Skip to content

reject invalid and conflicting Content-Length in httpGetLength - #219

Closed
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:http-content-length-strict
Closed

tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:http-content-length-strict

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor
  1. httpGetLength parsed Content-Length with strtoll(value, NULL, 10), so 5abc, +5 and 5, 50 all framed a 5-byte body, and http_add_field let a second Content-Length field replace the first, so Content-Length: 5 followed by Content-Length: 50 framed 50 bytes.
  2. A front end that frames by the first value, or treats the malformed value differently, disagrees with a libcups server (ippeveprinter, PAPPL) about where the body ends, and the leftover bytes are parsed as the next request on the keep-alive connection (CL.CL request smuggling). RFC 9112 section 6.3 makes an invalid or conflicting Content-Length an unrecoverable framing error.
  3. Each Content-Length value must now be 1*DIGIT, and repeated fields are combined and accepted only when every value matches (RFC 9110 section 8.6). Anything else makes httpGetLength return -1, which _httpUpdate already reports as a bad Content-Length, the same path now used for unknown Transfer-Encoding values.

The new loopback cases in testhttp fail 4 of 7 on master (got 50, 5, 5, 5 where -1 is expected) and all pass with this change; single, repeated identical and 5, 5 values still return 5.

@michaelrsweet michaelrsweet self-assigned this Nov 19, 2026
@michaelrsweet michaelrsweet added the enhancement New feature or request label Nov 19, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Nov 19, 2026

@michaelrsweet michaelrsweet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I want to refactor this change, and limit any changes to the library and not the unit test program (for now at least).

Also, for future PRs:

  • Currently testhttp does not try to simulate requests/responses, and any such changes should be contributed as a separate PR as it will be a huge amount of maintenance.
  • Please just put your suggested changelog test in the description of the PR; at the very least I'll be adding the issue/PR number and I almost always reword things.

@michaelrsweet

Copy link
Copy Markdown
Member

FWIW, RFC 9110 has a fair amount to say about Content-Length, and allows an implementation to reject multi-value lengths.

So I will be marking Content-Length as potentially multi-valued and reject any header containing anything other than "1*DIGIT".

michaelrsweet added a commit that referenced this pull request Nov 19, 2026
@michaelrsweet

Copy link
Copy Markdown
Member

[master 7e09183] Validate Content-Type header (Issue #219)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants