Skip to content

Cookie authentication redirects with the base domain #26369

@SirMrDexter

Description

@SirMrDexter

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

  1. 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/");
                });
  1. Add authentication middleware
applicationBuilder.UseAuthentication();
  1. Setup a controller action with AuthorizeAttribute
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Status: No Recent Activityarea-authIncludes: Authn, Authz, OAuth, OIDC, Bearer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions