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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<Compile Include="$(SharedSourceRoot)TaskToApm.cs" />
<Compile Include="$(SharedSourceRoot)Debugger\DictionaryItemDebugView.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)Debugger\StringValuesDictionaryDebugView.cs" LinkBase="Shared" />
<Compile Include="$(SharedSourceRoot)PathNormalizer\**\*.cs" LinkBase="RequestProcessing" />
</ItemGroup>

<ItemGroup Condition="'$(DotNetBuildSourceOnly)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Compile Include="$(SharedSourceRoot)TypeNameHelper\*.cs" />
<Compile Include="$(SharedSourceRoot)Buffers.MemoryPool\**\*.cs" LinkBase="Shared\" />
<Compile Include="$(SharedSourceRoot)HttpSys\**\*.cs" LinkBase="Shared\" />
<Compile Include="$(SharedSourceRoot)PathNormalizer\**\*.cs" LinkBase="Shared\RequestProcessing\" />
<Compile Include="$(SharedSourceRoot)StackTrace\**\*.cs" LinkBase="Shared\" />
<Compile Include="$(SharedSourceRoot)RazorViews\*.cs" LinkBase="Shared\" />
<Compile Include="$(SharedSourceRoot)ErrorPage\*.cs" LinkBase="Shared\" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private void ParseTarget(TargetOffsetPathLength targetPath, Span<byte> target)
else
{
var path = target[..pathLength];
Path = _parsedPath = PathNormalizer.DecodePath(path, targetPath.IsEncoded, RawTarget, queryLength);
Path = _parsedPath = PathDecoder.DecodePath(path, targetPath.IsEncoded, RawTarget, queryLength);
}
}
catch (InvalidOperationException)
Expand Down
47 changes: 47 additions & 0 deletions src/Servers/Kestrel/Core/src/Internal/Http/PathDecoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text;
using Microsoft.AspNetCore.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;

internal static class PathDecoder
{
public static string DecodePath(Span<byte> path, bool pathEncoded, string rawTarget, int queryLength)
{
int pathLength;
if (pathEncoded)
{
// URI was encoded, unescape and then parse as UTF-8
pathLength = UrlDecoder.DecodeInPlace(path, isFormEncoding: false);

// Removing dot segments must be done after unescaping. From RFC 3986:
//
// URI producing applications should percent-encode data octets that
// correspond to characters in the reserved set unless these characters
// are specifically allowed by the URI scheme to represent data in that
// component. If a reserved character is found in a URI component and
// no delimiting role is known for that character, then it must be
// interpreted as representing the data octet corresponding to that
// character's encoding in US-ASCII.
//
// https://tools.ietf.org/html/rfc3986#section-2.2
pathLength = PathNormalizer.RemoveDotSegments(path.Slice(0, pathLength));

return Encoding.UTF8.GetString(path.Slice(0, pathLength));
}

pathLength = PathNormalizer.RemoveDotSegments(path);

if (path.Length == pathLength && queryLength == 0)
{
// If no decoding was required, no dot segments were removed and
// there is no query, the request path is the same as the raw target
return rawTarget;
}

return path.Slice(0, pathLength).GetAsciiStringNonNullCharacters();
}
}
162 changes: 0 additions & 162 deletions src/Servers/Kestrel/Core/src/Internal/Http/PathNormalizer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ private bool TryValidatePath(ReadOnlySpan<char> pathSegment)
pathBuffer[i] = (byte)ch;
}

Path = PathNormalizer.DecodePath(pathBuffer, pathEncoded, RawTarget!, QueryString!.Length);
Path = PathDecoder.DecodePath(pathBuffer, pathEncoded, RawTarget!, QueryString!.Length);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ private bool TryValidatePath(ReadOnlySpan<char> pathSegment)
pathBuffer[i] = (byte)ch;
}

Path = PathNormalizer.DecodePath(pathBuffer, pathEncoded, RawTarget!, QueryString!.Length);
Path = PathDecoder.DecodePath(pathBuffer, pathEncoded, RawTarget!, QueryString!.Length);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Compile Include="$(SharedSourceRoot)CertificateGeneration\**\*.cs" />
<Compile Include="$(SharedSourceRoot)ValueTaskExtensions\**\*.cs" />
<Compile Include="$(SharedSourceRoot)UrlDecoder\**\*.cs" />
<Compile Include="$(SharedSourceRoot)PathNormalizer\**\*.cs" LinkBase="Shared\" />
<Compile Include="$(SharedSourceRoot)InternalHeaderNames.cs" Link="Shared\InternalHeaderNames.cs"/>
<Compile Include="$(SharedSourceRoot)Buffers\**\*.cs" LinkBase="Internal\Infrastructure\PipeWriterHelpers" />
<Compile Include="$(SharedSourceRoot)runtime\*.cs" Link="Shared\runtime\%(Filename)%(Extension)" />
Expand Down
87 changes: 0 additions & 87 deletions src/Servers/Kestrel/Core/test/PathNormalizerTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using Microsoft.AspNetCore.Internal;

namespace Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks;

Expand Down
1 change: 1 addition & 0 deletions src/Shared/HttpSys/RequestProcessing/RequestUriBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Text;
using Microsoft.AspNetCore.Internal;

namespace Microsoft.AspNetCore.HttpSys.Internal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Microsoft.AspNetCore.HttpSys.Internal;
namespace Microsoft.AspNetCore.Internal;

internal static class PathNormalizer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Compile Include="$(SharedSourceRoot)WebEncoders\**\*.cs" Link="Shared\WebEncoders\%(Filename)%(Extension)" />
<Compile Include="$(SharedSourceRoot)QueryStringEnumerable.cs" />
<Compile Include="$(SharedSourceRoot)UrlDecoder\**\*.cs" Link="Shared\UrlDecoder\%(Filename)%(Extension)" />
<Compile Include="$(SharedSourceRoot)PathNormalizer\**\*.cs" Link="Shared\PathNormalizer\%(Filename)%(Extension)" />
<Compile Include="$(SharedSourceRoot)ThrowHelpers\**\*.cs" Link="Shared\ThrowHelpers\%(Filename)%(Extension)" />
<Compile Include="$(SharedSourceRoot)CallerArgument\**\*.cs" Link="Shared\CallerArgument\%(Filename)%(Extension)" />
<Compile Include="$(SharedSourceRoot)TypeNameHelper\*.cs" />
Expand Down
Loading