Skip to content

Commit c8a648a

Browse files
committed
Normalize absolute-form request paths
1 parent 48043be commit c8a648a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

GitProtect/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@
3838

3939
var app = builder.Build();
4040

41+
app.Use((context, next) =>
42+
{
43+
var path = context.Request.Path.Value;
44+
if (!string.IsNullOrEmpty(path)
45+
&& (path.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
46+
|| path.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
47+
{
48+
if (Uri.TryCreate(path, UriKind.Absolute, out var uri))
49+
{
50+
context.Request.Path = uri.AbsolutePath;
51+
context.Request.QueryString = string.IsNullOrEmpty(uri.Query)
52+
? QueryString.Empty
53+
: new QueryString(uri.Query);
54+
}
55+
}
56+
57+
return next();
58+
});
59+
4160
if (app.Environment.IsDevelopment())
4261
{
4362
app.UseWebAssemblyDebugging();

0 commit comments

Comments
 (0)