Skip to content

Commit 11e3dd6

Browse files
Fix incorrect HTTP/2 method header decoding (#40412) (#40460)
Co-authored-by: Aditya Mandaleeka <[email protected]> Co-authored-by: James Newton-King <[email protected]>
1 parent b7c95f3 commit 11e3dd6

18 files changed

+129
-19
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ private void OnHeaderCore(HeaderType headerType, int? staticTableIndex, ReadOnly
14431443
{
14441444
UpdateHeaderParsingState(value, GetPseudoHeaderField(staticTableIndex.GetValueOrDefault()));
14451445

1446-
_currentHeadersStream.OnHeader(staticTableIndex.GetValueOrDefault(), indexOnly: true, name, value);
1446+
_currentHeadersStream.OnHeader(staticTableIndex.GetValueOrDefault(), indexOnly: false, name, value);
14471447
}
14481448
else
14491449
{

src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private void OnHeaderCore(HeaderType headerType, int? staticTableIndex, ReadOnly
314314
{
315315
UpdateHeaderParsingState(value, GetPseudoHeaderField(staticTableIndex.GetValueOrDefault()));
316316

317-
OnHeader(staticTableIndex.GetValueOrDefault(), indexOnly: true, name, value);
317+
OnHeader(staticTableIndex.GetValueOrDefault(), indexOnly: false, name, value);
318318
}
319319
else
320320
{

src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
<ItemGroup>
1616
<Compile Include="$(KestrelSharedSourceRoot)\PooledStreamStack.cs" Link="Internal\PooledStreamStack.cs" />
17+
<Compile Include="$(KestrelSharedSourceRoot)\HPackHeaderWriter.cs" Link="Internal\Http2\HPackHeaderWriter.cs" />
18+
<Compile Include="$(KestrelSharedSourceRoot)\Http2HeadersEnumerator.cs" Link="Internal\Http2\Http2HeadersEnumerator.cs" />
1719
<Compile Include="$(SharedSourceRoot)CertificateGeneration\**\*.cs" />
1820
<Compile Include="$(SharedSourceRoot)ValueTaskExtensions\**\*.cs" />
1921
<Compile Include="$(SharedSourceRoot)UrlDecoder\**\*.cs" />

src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
66
<TestGroupName>Kestrel.Core.Tests</TestGroupName>
7-
<DefineConstants>$(DefineConstants);KESTREL</DefineConstants>
7+
<DefineConstants>$(DefineConstants);KESTREL;IS_TESTS</DefineConstants>
88
</PropertyGroup>
99

1010
<ItemGroup>
@@ -15,6 +15,8 @@
1515
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.pfx" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
1616
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.crt" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
1717
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.key" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
18+
<Compile Include="$(KestrelSharedSourceRoot)\HPackHeaderWriter.cs" Link="Http2\HPackHeaderWriter.cs" />
19+
<Compile Include="$(KestrelSharedSourceRoot)\Http2HeadersEnumerator.cs" Link="Http2\Http2HeadersEnumerator.cs" />
1820
<Compile Include="$(RepoRoot)src\Shared\Buffers.MemoryPool\*.cs" LinkBase="MemoryPool" />
1921
<Compile Include="$(KestrelSharedSourceRoot)\CorrelationIdGenerator.cs" Link="Internal\CorrelationIdGenerator.cs" />
2022
<Compile Include="$(SharedSourceRoot)test\Shared.Tests\runtime\Http2\*.cs" LinkBase="Shared\runtime\Http2" />

src/Servers/Kestrel/Kestrel/test/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<ItemGroup>
88
<Compile Include="$(SharedSourceRoot)NullScope.cs" />
9-
<Compile Include="$(KestrelSharedSourceRoot)test\*.cs" LinkBase="shared" />
9+
<Compile Include="$(KestrelSharedSourceRoot)test\TestResources.cs" Link="shared\TestResources.cs" />
1010
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.pfx" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
1111
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.crt" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
1212
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.key" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />

src/Servers/Kestrel/Transport.Quic/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
<ItemGroup>
1010
<Compile Include="$(SharedSourceRoot)NullScope.cs" />
11-
<Compile Include="$(KestrelSharedSourceRoot)test\*.cs" LinkBase="shared" />
11+
<Compile Include="$(KestrelSharedSourceRoot)test\HttpEventSourceListener.cs" Link="shared\HttpEventSourceListener.cs" />
12+
<Compile Include="$(KestrelSharedSourceRoot)test\TestResources.cs" Link="shared\TestResources.cs" />
13+
<Compile Include="$(KestrelSharedSourceRoot)test\StreamExtensions.cs" Link="shared\StreamExtensions.cs" />
14+
<Compile Include="$(KestrelSharedSourceRoot)test\KestrelTestLoggerProvider.cs" Link="shared\KestrelTestLoggerProvider.cs" />
15+
<Compile Include="$(KestrelSharedSourceRoot)test\TestApplicationErrorLoggerLoggedTest.cs" Link="shared\TestApplicationErrorLoggerLoggedTest.cs" />
16+
<Compile Include="$(KestrelSharedSourceRoot)test\TestApplicationErrorLogger.cs" Link="shared\TestApplicationErrorLogger.cs" />
1217
<Compile Include="$(KestrelSharedSourceRoot)test\TransportTestHelpers\IHostPortExtensions.cs" Link="shared\TransportTestHelpers\IHostPortExtensions.cs" />
1318
<Compile Include="$(KestrelSharedSourceRoot)test\TransportTestHelpers\MsQuicSupportedAttribute.cs" Link="shared\TransportTestHelpers\MsQuicSupportedAttribute.cs" />
1419
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.pfx" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />

src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2ConnectionBenchmarkBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Microsoft.Extensions.Logging.Abstractions;
2323
using Microsoft.Extensions.Primitives;
2424
using Microsoft.Net.Http.Headers;
25+
using Http2HeadersEnumerator = Microsoft.AspNetCore.Server.Kestrel.Core.Tests.Http2HeadersEnumerator;
2526

2627
namespace Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks;
2728

src/Servers/Kestrel/perf/Microbenchmarks/Http2/Http2HeadersEnumeratorBenchmark.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
77
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
88
using Microsoft.Extensions.Primitives;
9+
using Http2HeadersEnumerator = Microsoft.AspNetCore.Server.Kestrel.Core.Tests.Http2HeadersEnumerator;
910

1011
namespace Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks;
1112

src/Servers/Kestrel/perf/Microbenchmarks/Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<ServerGarbageCollection>true</ServerGarbageCollection>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<TieredCompilation>false</TieredCompilation>
9+
<DefineConstants>$(DefineConstants);IS_BENCHMARKS</DefineConstants>
910
</PropertyGroup>
1011

1112
<ItemGroup>
@@ -15,6 +16,8 @@
1516
<Compile Include="$(KestrelSharedSourceRoot)\CompletionPipeReader.cs" />
1617
<Compile Include="$(KestrelSharedSourceRoot)\CompletionPipeWriter.cs" />
1718
<Compile Include="$(KestrelSharedSourceRoot)test\PipeWriterHttp2FrameExtensions.cs" Link="Internal\PipeWriterHttp2FrameExtensions.cs" />
19+
<Compile Include="$(KestrelSharedSourceRoot)\HPackHeaderWriter.cs" Link="Http2\HPackHeaderWriter.cs" />
20+
<Compile Include="$(KestrelSharedSourceRoot)\Http2HeadersEnumerator.cs" Link="Http2\Http2HeadersEnumerator.cs" />
1821
<Compile Include="$(RepoRoot)src\Shared\Buffers.MemoryPool\*.cs" LinkBase="MemoryPool" />
1922
<Compile Include="$(KestrelSharedSourceRoot)test\KestrelTestLoggerProvider.cs" />
2023
<Compile Include="$(KestrelSharedSourceRoot)test\TestApplicationErrorLogger.cs" />

src/Servers/Kestrel/Core/src/Internal/Http2/HPackHeaderWriter.cs renamed to src/Servers/Kestrel/shared/HPackHeaderWriter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
using System.Net.Http;
55
using System.Net.Http.HPack;
66

7+
#if !(IS_TESTS || IS_BENCHMARKS)
78
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
9+
#else
10+
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests;
11+
#endif
812

13+
// This file is used by Kestrel to write response headers and tests to write request headers.
14+
// To avoid adding test code to Kestrel this file is shared. Test specifc code is excluded from Kestrel by ifdefs.
915
internal static class HPackHeaderWriter
1016
{
1117
/// <summary>

0 commit comments

Comments
 (0)