Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ All limits are configurable via `ParserLimits`:

**RFC:** 9110 Section 8.6

#### Transfer-Encoding in HTTP/1.0

**Attack:** An HTTP/1.0 message with `Transfer-Encoding: chunked`. HTTP/1.0 has no transfer codings, so a hop that speaks only 1.0 frames the body another way, and what it leaves on the connection is read as the next message.

**RFC:** 9112 Section 6.1: a recipient "MUST treat the message as if the framing is faulty, even if a Content-Length is present". Refused in requests and responses alike.

#### Obfuscated Transfer-Encoding

**Attack:** TE.TE smuggling via obfuscated Transfer-Encoding values (`xchunked`, `"chunked"`, `chunked-thing`). One system recognizes it as chunked, another does not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ public static bool TryParseRequestHeader(
if (hasTE && hasCL)
throw new HttpParseException("Both Transfer-Encoding and Content-Length are present.");

// RFC 9112 §6.1: HTTP/1.0 has no transfer codings, so a hop that speaks only 1.0 frames this body another way.
if (hasTE && versionSpan[7] == (byte)'0')
throw new HttpParseException("Transfer-Encoding in an HTTP/1.0 message.");

// RFC 9112 §3.2 — HTTP/1.1 requires exactly one Host header
if (hostCount != 1)
throw new HttpParseException("Request must have exactly one Host header.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ public static bool TryParseResponseHeader(
if (hasTE && hasCL)
throw new HttpParseException("Both Transfer-Encoding and Content-Length are present.");

// RFC 9112 §6.1: HTTP/1.0 has no transfer codings, so a hop that speaks only 1.0 frames this body another way.
if (hasTE && versionSpan[7] == (byte)'0')
throw new HttpParseException("Transfer-Encoding in an HTTP/1.0 message.");

consumed = totalHeaderBytes;
return true;
}
Expand Down
Binary file modified tests/Tests/UltraHardenedParser.Response.cs
Binary file not shown.
28 changes: 28 additions & 0 deletions tests/Tests/UltraHardenedParser.Semantics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,34 @@ public void Accepts_OnlyTE_NoCL(bool multi)
Assert.True(ok);
}

// ================================================================
// Transfer-Encoding in HTTP/1.0 (RFC 9112 §6.1)
// ================================================================

[Theory]
[InlineData(false)]
[InlineData(true)]
public void Throws_TEinHttp10(bool multi)
{
// HTTP/1.0 has no transfer codings: a hop that speaks only 1.0 frames this body some other way.
var raw =
"POST / HTTP/1.0\r\n" +
"Host: x\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n";
var ex = Assert.Throws<HttpParseException>(() => Parse(raw, multi));
Assert.Equal(400, ex.StatusCode);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void Accepts_CLinHttp10(bool multi)
{
var (ok, _) = Parse("POST / HTTP/1.0\r\nHost: x\r\nContent-Length: 10\r\n\r\n", multi);
Assert.True(ok);
}

// ================================================================
// Content-Length header name case insensitivity
// ================================================================
Expand Down
Loading