Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

CookiePolicy middleware can't affect CookieAuthentication middleware #814

Closed
analogrelay opened this issue May 6, 2016 · 4 comments
Closed
Assignees
Milestone

Comments

@analogrelay
Copy link

Because the CookieAuthentication middleware does it's own cookie-writing manually (see https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNetCore.Authentication.Cookies/ChunkingCookieManager.cs), the CookiePolicy middleware can't affect it. This is easily seen by doing something like this in your Startup.cs

app.UseCookiePolicy(new CookiePolicyOptions()
{
    HttpOnly = HttpOnlyPolicy.Always
});

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationScheme = "MagicSignin",
    CookieHttpOnly = false,
    LoginPath = new PathString("/Account/Login"),
    AccessDeniedPath = new PathString("/Account/AccessDenied"),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});

CookiePolicy works by replacing the IResponseCookiesFeature, but CookieAuth sets the header manually so it ignores the policy.

@brockallen
Copy link

Does this mean there are 2 different ways to emit cookies in ASP.NET Core then?

@Tratcher
Copy link
Member

Tratcher commented May 7, 2016

Sortof. HttpContext.Response.Cookies.Append and HttpContext.Response.Headers.Append can both be used to set a set-cookie header. Note you could also do this in Asp.Net 4. The difference between 4 and Core is that in Core the headers are the source of truth, where in 4 there was a cookies collection that would overwrite the headers just before sending the response.

@davidfowl
Copy link
Member

This feels like something we should fix post RC2.

@analogrelay
Copy link
Author

@davidfowl Agree entirely. It's a functional change, yes, but a fairly edge-case scenario and I agree it need not be a priority for RC2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants