Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to set a session cookie without a domain attribute when SERVER_NAME is set #1784

Closed
wrr opened this issue Apr 18, 2016 · 6 comments

Comments

@wrr
Copy link

wrr commented Apr 18, 2016

If cookie has no domain attribute, it is valid only for the exact domain to which the request that sets the cookie is addressed, this is often a desirable behavior. A domain attribute makes the cookie also valid for all sub-domains of the specified domain.

Looking at

def get_cookie_domain(self, app):
if SERVER_NAME is set, a cookie will always have a domain attribute (either explicitly set via SESSION_COOKIE_DOMAIN or inferred from the SERVER_NAME).

Would it be possible to allow setting cookies without a domain when SERVER_NAME is set?

@Fajkowsky
Copy link

But why? What would be purpose of this?

@wrr
Copy link
Author

wrr commented Apr 28, 2016

@Fajkowsky say example.org site uses admin.example.org subdomain for administration purposes and would like to set authentication cookies that are restricted to admin.example.org only.

@untitaker
Copy link
Contributor

I don't understand how a decent API would look like. Note that you can already subclass Flask (which is generally encouraged).

@wrr
Copy link
Author

wrr commented May 4, 2016

@untitaker ideally SESSION_COOKIE_DOMAIN would be the only setting that controls the domain attribute (the domain would be never set if SESSION_COOKIE_DOMAIN is None). But such change is not backward compatible.

A backward compatible approach would be to introduce for example SESSION_COOKIE_DOMAIN_FROM_SERVER_NAME setting that defaults to True. With the setting set to True, the current behavior is preserved. With the setting set to False, the domain attribute is set based on the SESSION_COOKIE_DOMAIN only.

@davidism
Copy link
Member

You can now set SESSION_COOKIE_DOMAIN = False to explicitly prevent any domain being set on the cookie. #2282

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
@davidism
Copy link
Member

See #5051, going to refactor this to remove the SERVER_NAME fallback.

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

4 participants