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 20c01b6..203d81d 100644 Binary files a/tests/Tests/UltraHardenedParser.Response.cs and b/tests/Tests/UltraHardenedParser.Response.cs differ 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 // ================================================================