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

Use secure and httponly csrf cookie #284

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Astra-X
Copy link

@Astra-X Astra-X commented May 16, 2024

No description provided.

Copy link
Member

@dantownsend dantownsend left a 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.

@@ -120,6 +120,8 @@ async def dispatch(
self.cookie_name,
token,
max_age=self.max_age,
httponly=True,
Copy link
Member

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

@@ -120,6 +120,8 @@ async def dispatch(
self.cookie_name,
token,
max_age=self.max_age,
httponly=True,
secure=True,
Copy link
Member

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,

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmazingAkai
Copy link

@dantownsend Is this alright now?

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

Successfully merging this pull request may close these issues.

3 participants