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

Incompatible with CSRF_USE_SESSIONS = True #14

Closed
nijel opened this issue Jul 31, 2024 · 2 comments · Fixed by #15
Closed

Incompatible with CSRF_USE_SESSIONS = True #14

nijel opened this issue Jul 31, 2024 · 2 comments · Fixed by #15

Comments

@nijel
Copy link
Contributor

nijel commented Jul 31, 2024

The client code fetches CSRF token from the cookie, but this is not available with CSRF_USE_SESSIONS = True. We ended up using that as the outcome of some security audits. I don't think it's more secure and Django documentation agrees, but storing CSRF token in a cookie is a red flag for some audits.

Would it be possible to let it extract it from the HTML page in this case?

We make sure that the input is always present (<input type="hidden" name="csrfmiddlewaretoken" value="...">).

@Stormheg
Copy link
Member

Stormheg commented Jul 31, 2024

Thanks for the report!

Originally, my proof of concept retrieved the CSRF token from a hidden input. If I recall my reasoning correctly, I changed that to retrieve from a cookie instead under the assumption that is always available and a hidden input might not be. Turns out that is a wrong assumption.

Would you be up to opening a pull request? The JS that goes looking for the CSRF token lives here:

export async function getCSRFToken(config: Config): Promise<string> {

Falling back to looking for an input on the page sounds like it would do the job.

@nijel
Copy link
Contributor Author

nijel commented Jul 31, 2024

Sorry, if it would be in Python, I'd do it, but typescript is out of my abilities.

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