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

RC2, seems like CookieAuthenticationOptions.CookieSecure does not work #831

Closed
sadjadbp opened this issue May 20, 2016 · 19 comments
Closed

Comments

@sadjadbp
Copy link

In RC2, seems like setting
CookieAuthenticationOptions.CookieSecure = CookieSecureOption.Always;

Does not work anymore. We cannot afford the default value SameAsRequest since we are behind a LoadBalancer that opens the SSL packets and sends us via HTTP. In RC1, the same code in our Startup.cs use to take care of it.

@Tratcher
Copy link
Member

Please share the response headers.

@Tratcher
Copy link
Member

Note that some load balancers will give you an x-forwarded-proto header to let you know the original scheme. Or if you know it will always be https you can hardcode it:

app.Use((context, next) =>
{
  context.Request.Scheme = "https";
  return next();
});

@sadjadbp
Copy link
Author

sadjadbp commented May 20, 2016

@Tratcher our response header:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: -1
Server: Kestrel
Set-Cookie: .AspNetCore.Antiforgery.fU83vCg1Q3E=CfDJ8NPOhTB6To9Ll_bBm2FKytkgxg9VUwfHWRziRp9DWvXl8bTHLNvx_C8HbZm0jvnncV4Vis145gkZHuog6XvDac8_NgPITPv9ikBeGkLbg_5FG6maSHKGZzC9Bfm5O9FRIqQ9YFgUJDvZdUiC7T3bI24; path=/; httponly
Set-Cookie: .AspNetCore.Session=80b0f95b-49a4-9a09-ccf3-f6bbc8b6c8c6; domain=.eimmigration.com; path=/; httponly
X-Frame-Options: SAMEORIGIN
Date: Fri, 20 May 2016 22:10:46 GMT
Content-Length: 17290

@Tratcher
Copy link
Member

That's session and anti-forgery, not CookieAuthentication. Were you intending to use Microsoft.AspNetCore.CookiePolicy?

@sadjadbp
Copy link
Author

Oh sure, you are right! I've checked and that other cookie is set to secure. So what I'm looking for is

app.UseSession(new SessionOptions() { });

But there is no option for CookieSecure on that SessionOptions. Am I asking the right question under right Repro? Since my other question #832 is about how to make .AspNetCore.Antiforgery always secure.

@Tratcher
Copy link
Member

aspnet/Session#106
For now use the CookiePolicy middleware, it can sit in front of the others and override their settings.

@Tratcher
Copy link
Member

That said, you should really fix your request scheme rather than focusing on the cookie settings. For example aren't your links automatically generated using http instead of https?

@sadjadbp
Copy link
Author

@Tratcher Thanks. Cookie middleware worked. But as I tested, using that Cookie middleware, works for .AspNetCore,Antiforgery and .AspNetCore.Session but won't work on AuthenticationCookie so I have to set that separately. Don't know if it is a bug or as intended.

@Tratcher
Copy link
Member

A bug: #814

@sadjadbp
Copy link
Author

Wow, you guys are super fast, super helpful. I'm getting my life's best tech support ever. Thanks again.

Q#2, as for the issue of load balancer you think that small middleware
app.Use((context, next) => { context.Request.Scheme = "https"; return next(); });

Would fix all these types of issues? I'm going to test it. Does it matter were I put in Startup::Configure

@Tratcher
Copy link
Member

Yes it should help with these issues because many middleware inspect the scheme. Put it at the start so all it affects all requests.

Does your load balancer specify x-forwarded-for headers? In that case us the ForwardedHeaders middleware instead. https://github.com/aspnet/BasicMiddleware/blob/dev/samples/HttpOverridesSample/Startup.cs#L13

@Tratcher
Copy link
Member

woops, x-forwarded-proto headers...

@sadjadbp
Copy link
Author

@Tratcher good.

Not sure they said to use 'X-SSL-SessionId'. I'm going to check that X-Forwarded-Proto

Thanks again.

@sadjadbp sadjadbp reopened this May 21, 2016
@sadjadbp
Copy link
Author

One last question, any plans to add "same-site" setting on CookiePolicy middleware. I think I can do it now with OnAppendCookie event.

@Eilon
Copy link
Member

Eilon commented May 26, 2016

Cookies by default only get sent back to the same domain. Can you clarify what you're asking about?

@sadjadbp
Copy link
Author

@Eilon I'm asking about "same-site cookie attribute" something like
Set-Cookie: key=value; HttpOnly; SameSite=strict

@Eilon
Copy link
Member

Eilon commented May 26, 2016

@blowdart @Tratcher ?

@Tratcher
Copy link
Member

Ah, this draft? https://tools.ietf.org/html/draft-west-first-party-cookies-07? Maybe when the spec is finished.

@sadjadbp
Copy link
Author

Thanks

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

No branches or pull requests

3 participants