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
2 changes: 1 addition & 1 deletion Benchmarks/Infrastructure/BenchmarkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public BenchmarkContext(string request, IHandler handler)

public async ValueTask Execute()
{
if (!UltraHardenedParser.TryExtractFullHeaderROM(ref _request, _context.Request.Source, Limits, out _))
if (!UltraHardenedParser.TryParseRequestHeader(ref _request, _context.Request.Source, Limits, out _))
{
throw new ArgumentException("Given request could not be parsed.");
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/Internal/GenHTTP.Engine.Internal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="10.0.14" />

<PackageReference Include="Glyph11" Version="0.3.7" />
<PackageReference Include="Glyph11" Version="0.4.0" />

</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions Engine/Internal/Protocol/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ private async ValueTask HandlePipeAsync(PipeReader reader)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryParseRequest(ref ReadOnlySequence<byte> buffer, BinaryRequest into)
{
if (!UltraHardenedParser.TryExtractFullHeaderValidated(ref buffer, into, Limits, out var bytesRead))
if (!UltraHardenedParser.TryParseRequestHeader(ref buffer, into, Limits, out var consumed))
{
return false;
}

buffer = buffer.Slice(bytesRead + 1);
buffer = buffer.Slice(consumed);
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions Engine/Ioxide/GenHTTP.Engine.Ioxide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<PackageReference Include="ioxide.ngtcp2" Version="0.15.251" />
<PackageReference Include="ioxide.nghttp3" Version="0.15.251" />

<PackageReference Include="Glyph11" Version="0.3.7" />
<PackageReference Include="Glyph11.Pico" Version="0.0.1" />
<PackageReference Include="Glyph11" Version="0.4.0" />

</ItemGroup>

Expand Down
28 changes: 3 additions & 25 deletions Engine/Ioxide/Protocol/Drivers/Tcp/Http1Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Glyph11;
using Glyph11.Parser;
using Glyph11.Parser.UltraHardened;
using Glyph11.Pico;
using Glyph11.Protocol;

using Microsoft.Extensions.Logging;
Expand All @@ -28,11 +27,6 @@ internal static class Http1Driver
{
private static readonly ParserLimits Limits = ParserLimits.Default;

// GENHTTP_IOXIDE_PARSER=pico swaps the hardened managed parser for picohttpparser, which
// does no path/token/smuggling hardening. For benchmarking, not for untrusted traffic.
private static readonly bool UsePico =
string.Equals(Environment.GetEnvironmentVariable("GENHTTP_IOXIDE_PARSER"), "pico", StringComparison.OrdinalIgnoreCase);

private static readonly ByteString KeepAliveValue = new("Keep-Alive");

[ThreadStatic]
Expand Down Expand Up @@ -147,31 +141,15 @@ private static async ValueTask SendErrorAsync(IServer server, PipeWriter writer,
}
}

// Parses one request head, through whichever parser this process was started with.
// Parses one request head: full RFC validation plus smuggling hardening.
private static bool TryParseRequest(ref ReadOnlySequence<byte> buffer, BinaryRequest into)
=> UsePico ? TryParseRequestPico(ref buffer, into) : TryParseRequestGlyph11(ref buffer, into);

// The default path: full RFC validation plus smuggling hardening.
private static bool TryParseRequestGlyph11(ref ReadOnlySequence<byte> buffer, BinaryRequest into)
{
if (!UltraHardenedParser.TryExtractFullHeaderValidated(ref buffer, into, Limits, out var bytesRead))
{
return false;
}

buffer = buffer.Slice(bytesRead + 1);
return true;
}

// The benchmark path: picohttpparser, which validates only as far as picohttpparser does.
private static bool TryParseRequestPico(ref ReadOnlySequence<byte> buffer, BinaryRequest into)
{
if (!PicoParser.TryParse(buffer, into, out var consumed))
if (!UltraHardenedParser.TryParseRequestHeader(ref buffer, into, Limits, out var consumed))
{
return false;
}

buffer = buffer.Slice(consumed + 1);
buffer = buffer.Slice(consumed);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion Engine/Shared/GenHTTP.Engine.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ProjectReference Include="..\..\Modules\ErrorHandling\GenHTTP.Modules.ErrorHandling.csproj" />

<PackageReference Include="Glyph11" Version="0.3.7" />
<PackageReference Include="Glyph11" Version="0.4.0" />

<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.14" />

Expand Down
7 changes: 6 additions & 1 deletion Testing/Acceptance/Engine/Body/ChunkedFramingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ public async Task TestTruncatedBodyFails()
{
var (_, framing) = await CreateAsync("5\r\nHel");

var e = await Assert.ThrowsExactlyAsync<ProviderException>(async () => await framing.ReadAsync(new byte[16], CancellationToken.None));
var buffer = new byte[16];

Assert.AreEqual(3, await framing.ReadAsync(buffer, CancellationToken.None));
Assert.AreEqual("Hel", Encoding.ASCII.GetString(buffer, 0, 3));

var e = await Assert.ThrowsExactlyAsync<ProviderException>(async () => await framing.ReadAsync(buffer, CancellationToken.None));

Assert.AreEqual(ResponseStatus.BadRequest, e.Status);
}
Expand Down
16 changes: 8 additions & 8 deletions Testing/Acceptance/Engine/Body/RequestBodyLifecycleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using GenHTTP.Engine.Shared.Types;

using Glyph11.Parser;
using Glyph11.Parser.FlexibleParser;
using Glyph11.Parser.UltraHardened;
using Glyph11.Pico;

using NSubstitute;

Expand Down Expand Up @@ -453,9 +453,9 @@ public async Task TestContinueNotCarriedOver()

var buffer = (await pipe.Reader.ReadAsync()).Buffer;

Assert.IsTrue(UltraHardenedParser.TryExtractFullHeaderValidated(ref buffer, request.Source, ParserLimits.Default, out var bytesRead));
Assert.IsTrue(UltraHardenedParser.TryParseRequestHeader(ref buffer, request.Source, ParserLimits.Default, out var consumed));

request.Apply(Substitute.For<IServer>(), Substitute.For<IEndPoint>(), pipe.Reader, buffer.Slice(bytesRead + 1).Start, null, null, output.Writer);
request.Apply(Substitute.For<IServer>(), Substitute.For<IEndPoint>(), pipe.Reader, buffer.Slice(consumed).Start, null, null, output.Writer);

await request.GetBody()!.AsMemoryAsync();

Expand Down Expand Up @@ -520,14 +520,14 @@ public async Task TestWithoutConnection()

if (validate)
{
Assert.IsTrue(UltraHardenedParser.TryExtractFullHeaderValidated(ref buffer, request.Source, ParserLimits.Default, out var bytesRead));
buffer = buffer.Slice(bytesRead + 1);
Assert.IsTrue(UltraHardenedParser.TryParseRequestHeader(ref buffer, request.Source, ParserLimits.Default, out var consumed));
buffer = buffer.Slice(consumed);
}
else
{
// picohttpparser does not validate the framing headers, so they reach the request as sent
Assert.IsTrue(PicoParser.TryParse(buffer, request.Source, out var consumed));
buffer = buffer.Slice(consumed + 1);
// FlexibleParser does not validate the framing headers, so they reach the request as sent
Assert.IsTrue(FlexibleParser.TryParseRequestHeader(ref buffer, request.Source, out var consumed));
buffer = buffer.Slice(consumed);
}

var endPoint = Substitute.For<IEndPoint>();
Expand Down
2 changes: 1 addition & 1 deletion Testing/Acceptance/Engine/Compliance/ComplianceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ComplianceTests : WireTest
[MultiEngineTest]
public async Task TestNoMinorHttpVersion(ServerEngine engine)
{
await TestAsync(["GET / HTTP/1", "Host: localhost"], "505", Layout.Create(), engine);
await TestAsync(["GET / HTTP/1", "Host: localhost"], "400", Layout.Create(), engine);
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion Testing/Acceptance/Engine/WireTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task TestNoHost()
[TestMethod]
public async Task TestUnsupportedProtocolVersion()
{
await TestAsync("GET / HTTP/2.0\r\n", "Invalid HTTP version");
await TestAsync("GET / HTTP/2.0\r\n", "Unsupported HTTP version");
}

[TestMethod]
Expand Down
Loading