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

New Hashing Algorithm in Django 4.1 #453

Closed
iamsobanjaved opened this issue Sep 19, 2023 · 6 comments
Closed

New Hashing Algorithm in Django 4.1 #453

iamsobanjaved opened this issue Sep 19, 2023 · 6 comments
Assignees

Comments

@iamsobanjaved
Copy link
Member

iamsobanjaved commented Sep 19, 2023

Django introduced new signing algorithm sha256 as default in Django 3.1 and provided us the transitional settings to keep the algo same sha1 while upgrading to Django 3.1+. But now that transitional setting is removed in 4.0.

Now while testing on the sandbox, on upgrading the version of Django from 3.2 to 4.2 logged-in user is logged-out.

More from the release notes

The new DEFAULT_HASHING_ALGORITHM transitional setting allows specifying the default hashing algorithm to use for encoding cookies, password reset tokens in the admin site, user sessions, and signatures created by django.core.signing.Signer and django.core.signing.dumps().

Support for SHA-256 was added in Django 3.1. If you are upgrading multiple instances of the same project to Django 3.1, you should set DEFAULT_HASHING_ALGORITHM to 'sha1' during the transition, in order to allow compatibility with the older versions of Django. Note that this requires Django 3.1.1+. Once the transition to 3.1 is complete you can stop overriding DEFAULT_HASHING_ALGORITHM.

This setting is deprecated as of this release, because support for tokens, cookies, sessions, and signatures that use SHA-1 algorithm will be removed in Django 4.0.

https://docs.djangoproject.com/en/4.2/releases/3.1/#default-hashing-algorithm-settings

@iamsobanjaved iamsobanjaved converted this from a draft issue Sep 19, 2023
@awais786
Copy link

@iamsobanjaved
Copy link
Member Author

@iamsobanjaved iamsobanjaved moved this from Todo to In Progress in Arbi-BOM Oct 9, 2023
@iamsobanjaved iamsobanjaved moved this from In Progress to Owner Review in Arbi-BOM Oct 9, 2023
@iamsobanjaved
Copy link
Member Author

We updated the hashing algorithm to sha256 two weeks ago, and today only 1/3rd of the requests are going through the fallback path in LMS. This means these are the sessions that are still hashed from sha1 and if we upgrade to Django 4.2 today, these users will be logged out (don't know about the user count though, it is just based on requests).

From analyzing the code, found out that we set 4 week time of session expiry here, and as per my current knowledge we don't extend the session expiry time, hence the user will be logged out after 4 weeks even if he/she remains active in those 4 weeks.

Also currently we are blocked on MySQL upgrade for upgrading the Django version, and we are not aware of any exact timeline for when this blocker will be resolved, so we can wait for 2 more weeks so all old sessions will be logged out and replaced with new sessions. Also, the Django 4.2 upgrade PR is merged in the Quince branch, so waiting won't have any effect on the release schedule.

The question I currently have is whether my understanding of the session expiry is correct or if is there any Job/Middleware that extends the user's session expiry.

@robrap

@robrap
Copy link
Contributor

robrap commented Oct 31, 2023

@iamsobanjaved

The question I currently have is whether my understanding of the session expiry is correct or if is there any Job/Middleware that extends the user's session expiry.

I would have guessed that the graphs would show more of an increase in 'default' and drop in 'fallback' than they do. Is it possible that each time the fallback happens it gets extended as a 'fallback' session, rather than immediately replacing it a 'default' session?

Also, I added an (estimated) user count for fallbacks to the dashboard.

@iamsobanjaved
Copy link
Member Author

iamsobanjaved commented Dec 13, 2023

Missed the notification. The current update is that all users are now shifted to the new hashing algorithm in prod, but for Edge, there are still around 25-30% of users with the old hashing algorithm. We tried comparing configs of prod and edge to find out why the users are not being logged out there after 4 weeks. We found one user who logged in around 2.5 months ago and was still not logged out. @robrap Any idea what could be the reason for that?

@robrap
Copy link
Contributor

robrap commented Dec 13, 2023

Sorry @iamsobanjaved. I do not know. I didn't see any obvious config differences, but I'm not sure of session length. If you log in to prod and edge in a private browser, is there an obvious difference in the session cookie expiration?

Separately, once you've established you won't cause a storm of logins that could hurt the system, you could always decide to update and force re-logins.

@github-project-automation github-project-automation bot moved this from Owner Review to Done in Arbi-BOM Jan 11, 2024
@jristau1984 jristau1984 moved this from Done to Done - Long Term Storage in Arbi-BOM Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done - Long Term Storage
Development

No branches or pull requests

3 participants