Skip to content

Commit

Permalink
Merged PR 21913: Merge from public release/6.0
Browse files Browse the repository at this point in the history
# {PR title}

Summary of the changes (Less than 80 chars)

## Description

{Detail}

Fixes #{bug number} (in this specific format)

## Customer Impact

{Justification}

## Regression?

- [ ] Yes
- [ ] No

[If yes, specify the version the behavior has regressed from]

## Risk

- [ ] High
- [ ] Medium
- [ ] Low

[Justify the selection above]

## Verification

- [ ] Manual (required)
- [ ] Automated

## Packaging changes reviewed?

- [ ] Yes
- [ ] No
- [ ] N/A

----

## When servicing release/2.1

- [ ] Make necessary changes in eng/PatchConfig.props
  • Loading branch information
mmitche committed Mar 21, 2022
2 parents 578ba6d + 0498f89 commit cdabbaa
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The following contains a description of each sub-directory in the `Components` d
- `Server`: Contains the implementation for WASM-specific extension methods and the launch logic for the debugging proxy
- `WebAssembly`: Contains WebAssembly-specific implementations of the renderer, HostBuilder, etc.
- `WebAssembly.Authentication`: Contains the WASM-specific implementations
- `WebView`: Contains the source files to support [Blazor Hybrid](https://github.com/dotnet/maui/tree/main/src/BlazorWebView) within [`dotnet/maui`](https://github.com/dotnet/maui). Changes in this project can be tested with `dotnet/maui` following [this guide](https://github.com/dotnet/maui/wiki/Blazor-Desktop#aspnet-core).

## Development Setup

Expand Down
5 changes: 5 additions & 0 deletions src/Components/WebView/WebView/src/IpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.JSInterop;
Expand Down Expand Up @@ -62,8 +63,12 @@ public void SendByteArray(int id, byte[] data)

public void NotifyUnhandledException(Exception exception)
{
// Send the serialized exception to the WebView for display
var message = IpcCommon.Serialize(IpcCommon.OutgoingMessageType.NotifyUnhandledException, exception.Message, exception.StackTrace);
_dispatcher.InvokeAsync(() => _messageDispatcher(message));

// Also rethrow so the AppDomain's UnhandledException handler gets notified
_dispatcher.InvokeAsync(() => ExceptionDispatchInfo.Capture(exception).Throw());
}

private void DispatchMessageWithErrorHandling(string message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.ExceptionServices;
using System.Text.Json;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.AspNetCore.Components.Web;
Expand Down Expand Up @@ -38,9 +37,6 @@ protected override void HandleException(Exception exception)
{
// Notify the JS code so it can show the in-app UI
_ipcSender.NotifyUnhandledException(exception);

// Also rethrow so the AppDomain's UnhandledException handler gets notified
ExceptionDispatchInfo.Capture(exception).Throw();
}

protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="$(SharedSourceRoot)HttpSys\**\*.cs" />
<Compile Include="$(SharedSourceRoot)Buffers.MemoryPool\*.cs" LinkBase="MemoryPool" />
<Compile Include="$(SharedSourceRoot)ServerInfrastructure\StringUtilities.cs" LinkBase="ServerInfrastructure\StringUtilities.cs" />
<Compile Include="$(SharedSourceRoot)ServerInfrastructure\HttpCharacters.cs" LinkBase="ServerInfrastructure\HttpCharacters.cs" />
<Compile Include="$(SharedSourceRoot)TaskToApm.cs" />
</ItemGroup>

Expand Down
21 changes: 21 additions & 0 deletions src/Servers/HttpSys/test/FunctionalTests/ResponseHeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ public async Task ResponseHeaders_ServerSendsCustomHeaders_Success()
}
}

[ConditionalFact]
public async Task ResponseHeaders_ServerSendsNonAsciiHeaders_Success()
{
string address;
using (Utilities.CreateHttpServer(out address, httpContext =>
{
var responseInfo = httpContext.Features.Get<IHttpResponseFeature>();
var responseHeaders = responseInfo.Headers;
responseHeaders["Custom-Header1"] = new string[] { "Dašta" };
return Task.FromResult(0);
}))
{
var socketsHttpHandler = new SocketsHttpHandler() { ResponseHeaderEncodingSelector = (_, _) => Encoding.UTF8 };
var httpClient = new HttpClient(socketsHttpHandler);
var response = await httpClient.GetAsync(address);
response.EnsureSuccessStatusCode();
Assert.True(response.Headers.TryGetValues("Custom-Header1", out var header));
Assert.Equal("Dašta", header.Single());
}
}

[ConditionalFact]
public async Task ResponseHeaders_ServerSendsConnectionClose_Closed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO.Pipelines;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;

Expand Down
1 change: 0 additions & 1 deletion src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;

Expand Down
1 change: 1 addition & 0 deletions src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
Expand Down
1 change: 1 addition & 0 deletions src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using HttpCharacters = Microsoft.AspNetCore.Http.HttpCharacters;
using HttpMethods = Microsoft.AspNetCore.Http.HttpMethods;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
Expand Down
1 change: 1 addition & 0 deletions src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using HttpCharacters = Microsoft.AspNetCore.Http.HttpCharacters;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3
{
Expand Down
1 change: 1 addition & 0 deletions src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
Expand Down
12 changes: 12 additions & 0 deletions src/Servers/Kestrel/Core/test/HttpResponseHeadersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ public void AddingNonAsciiCharactersWithCustomEncoderWorks(string value)
((IDictionary<string, StringValues>)responseHeaders).Add("Unknown", value);
}

[Fact]
public void AddingTabCharactersToHeaderPropertyWorks()
{
var responseHeaders = (IHeaderDictionary)new HttpResponseHeaders();

// Known special header
responseHeaders.Allow = "Da\tta";

// Unknown header fallback
responseHeaders.Accept = "Da\tta";
}

[Fact]
public void ThrowsWhenAddingHeaderAfterReadOnlyIsSet()
{
Expand Down
8 changes: 3 additions & 5 deletions src/Shared/HttpSys/RequestProcessing/HeaderCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,10 @@ public static void ValidateHeaderCharacters(string headerCharacters)
{
if (headerCharacters != null)
{
foreach (var ch in headerCharacters)
var invalid = HttpCharacters.IndexOfInvalidFieldValueCharExtended(headerCharacters);
if (invalid >= 0)
{
if (ch < 0x20)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Invalid control character in header: 0x{0:X2}", (byte)ch));
}
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Invalid control character in header: 0x{0:X2}", headerCharacters[invalid]));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Runtime.CompilerServices;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
namespace Microsoft.AspNetCore.Http
{
internal static class HttpCharacters
{
Expand Down Expand Up @@ -107,6 +107,9 @@ private static bool[] InitializeFieldValue()
{
// field-value https://tools.ietf.org/html/rfc7230#section-3.2
var fieldValue = new bool[_tableSize];

fieldValue[0x9] = true; // HTAB

for (var c = 0x20; c <= 0x7e; c++) // VCHAR and SP
{
fieldValue[c] = true;
Expand Down Expand Up @@ -182,7 +185,8 @@ public static int IndexOfInvalidTokenChar(ReadOnlySpan<byte> span)
return -1;
}

// Disallows control characters and anything more than 0x7F
// Follows field-value rules in https://tools.ietf.org/html/rfc7230#section-3.2
// Disallows characters > 0x7E.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfInvalidFieldValueChar(string s)
{
Expand All @@ -200,7 +204,7 @@ public static int IndexOfInvalidFieldValueChar(string s)
return -1;
}

// Disallows control characters but allows extended characters > 0x7F
// Follows field-value rules for chars <= 0x7F. Allows extended characters > 0x7F.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOfInvalidFieldValueCharExtended(string s)
{
Expand Down

0 comments on commit cdabbaa

Please sign in to comment.