RedirectRule not respecting configured scheme #41707
Labels
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
investigate
Milestone
Is there an existing issue for this?
Describe the bug
When using
Microsoft.AspNetCore.Rewrite
to configure a Redirect, the scheme configured in the redirect is ignored and replaced with the scheme that was used for the original request. For example, a redirect rule tohttp://www.example.com
will actually redirect tohttps://www.example.com
if your endpoint was served over HTTPS, while a redirect rule tohttps://www.example.com
will actually redirect tohttp://www.example.com
if your endpoint was served over HTTP.This was a breaking change for us on moving from .NET Core 3.1 to .NET 6.
The behaviour occurs at line 100 of RedirectRule, and appears to have been introduced in this commit of 21st April 2021.
Expected Behavior
The scheme configured in the redirect should be respected, as in .NET Core 3.1, to continue to allow redirects to URLs with a different scheme to the receiving endpoint.
Steps To Reproduce
In ASP.NET Core middleware configuration/start-up (e.g. on the vanilla ASP.NET Core Web API template in Visual Studio):
Now, when running locally over HTTPS, send a request to
https://localhost:[port]/test
. An HTTP 302 is returned with the headerlocation: https://www.example.com
, despite the configuration.Equivalently, replace
http://www.example.com
in the configuration withhttps://www.example.com
and access over HTTP athttp://localhost:[port]/test
. An HTTP 302 is returned with the headerlocation: http://www.example.com
, despite the configuration.Exceptions (if any)
No response
.NET Version
6.0.203
Anything else?
ASP.NET Core runtime version 6.0.5.
The text was updated successfully, but these errors were encountered: