-
Notifications
You must be signed in to change notification settings - Fork 27
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
Use secure and httponly csrf cookie #284
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
I've left some comments about why the values are currently set as they - happy to discuss further.
piccolo_api/csrf/middleware.py
Outdated
@@ -120,6 +120,8 @@ async def dispatch( | |||
self.cookie_name, | |||
token, | |||
max_age=self.max_age, | |||
httponly=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With CSRF cookies, when the front end code makes AJAX requests, it has to read the value from the CSRF cookie and submit it as a HTTP header. So we can't use httponly
unfortunately.
https://piccolo-api.readthedocs.io/en/latest/csrf/usage.html#reading-from-the-cookie
piccolo_api/csrf/middleware.py
Outdated
@@ -120,6 +120,8 @@ async def dispatch( | |||
self.cookie_name, | |||
token, | |||
max_age=self.max_age, | |||
httponly=True, | |||
secure=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason this was currently set to False
is because when using Piccolo Admin locally, most people wouldn't run it under HTTPS so it would stop working. I think a good compromise would be to have this configurable. For example, we have a production
argument with Session auth:
production: bool = False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this needs to be updated in piccolo admin as well, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's right. We would pass production
in here: https://github.com/piccolo-orm/piccolo_admin/blob/5e8e96d56656cbf7283b63f8729d0748eb895867/piccolo_admin/endpoints.py#L439
@dantownsend Is this alright now? |
No description provided.