From 8a43b44b60e48dc01cfa2f4859eae25c87164476 Mon Sep 17 00:00:00 2001 From: Diogo Martins Date: Fri, 13 Nov 2026 16:05:46 +0000 Subject: [PATCH] Refuse Transfer-Encoding in HTTP/1.0 messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RFC 9112 §6.1: a recipient of an HTTP/1.0 message with Transfer-Encoding MUST treat its framing as faulty, even with a Content-Length, and close the connection after it. Both hardened parsers checked Transfer-Encoding against Content-Length and against any value but chunked, never against the version, so an HTTP/1.0 request or response with Transfer-Encoding: chunked parsed and was framed as chunked. HTTP/1.0 has no transfer codings, so a hop that speaks only 1.0 frames such a body another way. Both now refuse it beside the TE + CL check, as 400 for a request. Fixes #90 --- SECURITY.md | 6 ++++ .../UltraHardenedParser.FullHeader.ROM.cs | 4 +++ .../UltraHardenedParser.FullResponse.ROM.cs | 4 +++ tests/Tests/UltraHardenedParser.Response.cs | Bin 9847 -> 10615 bytes tests/Tests/UltraHardenedParser.Semantics.cs | 28 ++++++++++++++++++ 5 files changed, 42 insertions(+) diff --git a/SECURITY.md b/SECURITY.md index 65ddd45..f625bc9 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -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. diff --git a/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullHeader.ROM.cs b/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullHeader.ROM.cs index ac470d2..9d908d5 100644 --- a/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullHeader.ROM.cs +++ b/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullHeader.ROM.cs @@ -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."); diff --git a/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullResponse.ROM.cs b/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullResponse.ROM.cs index f2b4fee..54a5933 100644 --- a/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullResponse.ROM.cs +++ b/src/Glyph11/Parser/UltraHardened/UltraHardenedParser.FullResponse.ROM.cs @@ -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; } diff --git a/tests/Tests/UltraHardenedParser.Response.cs b/tests/Tests/UltraHardenedParser.Response.cs index 20c01b6482da74c99c71f423b3008038ce593f5e..203d81d6ac26623d44d7d07ee02b927a8da66566 100644 GIT binary patch delta 286 zcmY+9u}Z^G6ov^#TkT?!t1VQ^QE(8oBr1YVNNCd7Sh;!8! zVUxZp8#J0*G}h^9`eOMg2*eQebt_d^s2!nt82@D*vO0BFO}aE|#ebtwr#Hu@nFaN_ H#(et+q+MKF delta 16 Ycmew!^xbE}H{r>Dne{iTiU$b+08ESrTL1t6 diff --git a/tests/Tests/UltraHardenedParser.Semantics.cs b/tests/Tests/UltraHardenedParser.Semantics.cs index c14ff48..f23d953 100644 --- a/tests/Tests/UltraHardenedParser.Semantics.cs +++ b/tests/Tests/UltraHardenedParser.Semantics.cs @@ -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(() => 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 // ================================================================