Skip to content

A Content-Length of 2^63 or more is accepted, then framed as no body #61

Open

Description

@MDA2AV

What happens

The validator accepts Content-Length values up to ulong.MaxValue: SemIsValidContentLengthValue (UltraHardenedParser.FullHeader.ROM.cs:371) compares 20-digit values against "18446744073709551615" (:410). The framing parse, though, accumulates in a signed long and gives up on overflow:

// BodyFramingDetector.cs, ParseContentLengthDigits
result = result * 10 + (b - '0');
if (result < 0) return -1; // overflow   (:160)

DetectBodyFraming then turns that -1 into NoBody (:52, :56):

Content-Length: accepted DetectBodyFraming
9223372036854775807 yes ContentLength 9223372036854775807
9223372036854775808 yes None
18446744073709551615 yes None

Why it matters

As in #60, the body is read as the next request. A front end that takes the header at its word, waiting for the body or refusing it, disagrees with the back end about where the request ends. A header the parser accepted should never be framed as no body.

Responses share the parse: DetectResponseBodyFraming returns UntilClose for Content-Length: 9223372036854775808 (:131).

Fix

Either refuse these values (413), or frame them as long.MaxValue, which a server then refuses as too large instead of reading past it. Ktron's Kotlin port does the latter, in MDA2AV/Ktron@c6504d6.

main (f5d2cc1) and the NuGet package 0.3.7 both give the table above.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions