-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Describe the bug
When using cookie authentication, the redirect URLs use the full URL instead of relative URLs. This causes issues with services which are managed behind load balancers. Although it can fixed with URL rewrite rules, it may not be ideal solution.
To Reproduce
- Create a new web app and setup authentication services as below
services.AddAuthentication("MyAppAuth")
.AddCookie("MyAppAuth", cookieAuthenticationOptions =>
{
cookieAuthenticationOptions.AccessDeniedPath = new PathString("/Error/NoAccess/");
cookieAuthenticationOptions.LoginPath = new PathString("/Home/Login/");
});
- Add authentication middleware
applicationBuilder.UseAuthentication();
- Setup a controller action with
AuthorizeAttribute
- Debug the project and go to the URL with
AuthorizeAttribute
Expected Result:
Application returns a 302 response with the location header set to '/Home/Login/?returnUrl=....'
Actual Result:
Application returns a 302 response with the location header set to 'https://myapplicationdomain.com/Home/Login/?returnUrl=....'
Further technical details
Traced the changes back to this commit.
78cf7f9#diff-4e1d744cdbfdc6fa13724d45717a666bL72
Looks like it was done that way so it works for OAuth, which do need the full URL to make it work. But this causes issue with apps that do internal redirection and sit behind WAF and Load balancer services like Azure Application Gateway. Should be able to make the method virtual and override the behavior in CookieAuthenticationHandler, so it can use relative paths instead of full URL.