You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Collapse scheme-relative leading slashes in Rewrite middleware redirect/rewrite targets
`AddRedirect`, IIS URL Rewrite, and Apache mod_rewrite rules let an attacker-controlled or
misconfigured back-reference produce a target starting with `//`, `///`, or `/\` (and longer
runs). When `PathBase` is empty, the resulting `Location` header is scheme-relative and
resolves off-origin — an open redirect.
This change adds a small internal helper `UrlNormalizer.CollapseLeadingSlashes` that mirrors
the rejection predicate in `SharedUrlHelper.IsLocalUrl` but coerces instead of returning a
boolean: any leading run of `/` and `\` is collapsed to a single `/`. The helper is applied
at the three sinks that emit `Location` or mutate `Request.Path`:
* `RedirectRule.ApplyRule` (`AddRedirect` surface)
* `UrlActions.RedirectAction.ApplyAction` (IIS / Apache redirect import)
* `UrlActions.RewriteAction.ApplyAction` (defense in depth for `Request.Path`)
Adds regression theories on all three surfaces covering `//`, `///`, `//////`, `/\`
shapes, both as literal replacements and as back-reference-synthesized captures.
No public API surface change; `PublicAPI.Shipped.txt` / `PublicAPI.Unshipped.txt` unchanged.
// Licensed to the .NET Foundation under one or more agreements.
2
+
// The .NET Foundation licenses this file to you under the MIT license.
3
+
4
+
namespaceMicrosoft.AspNetCore.Rewrite;
5
+
6
+
internalstaticclassUrlNormalizer
7
+
{
8
+
// Collapses a leading run of '/' and '\' to a single '/' so a redirect/rewrite target cannot resolve as a scheme-relative authority. Mirrors the rejection predicate in SharedUrlHelper.IsLocalUrl.
0 commit comments