Exposing a Django secret key is an easy mistake to make. Good walkthrough of the cleanup process.
My Django Secret Key Was Public on GitHub - How I Fixed It
3 Comments
Worth swapping the emphasis in your parenthetical, because GitHub's own guidance runs the other way round. Purging history is not the "completely secure" step and rotation is not the lesser one. GitHub documents that after a rewrite the old commits may still be reachable in clones and forks of your repository, and directly via their SHA-1 hashes in cached views on GitHub. Their removal page puts revoking or rotating the secret first, and says Support will only help remove data where the risk cannot be mitigated by rotating the credential. So generating the new key was the actual fix. git-filter-repo is tidying up behind it.
The part worth knowing before you do this on a project with real users: rotating SECRET_KEY invalidates sessions, cookie-backed messages, and every outstanding PasswordResetView token. On a learning project that costs nothing. On a live one it signs everyone out and breaks reset links already sitting in people's inboxes. Django gives you a way through that, SECRET_KEY_FALLBACKS. Set the new key, move the old value to the front of the fallback list, then drop it once you are ready for those tokens to expire.
Small one on the settings change. os.getenv returns None when the variable is missing, so a deploy with no SECRET_KEY set fails later and further from the cause than it needs to. Reading it in a way that raises at startup saves you that hunt.
Please log in to add a comment.
Please log in to comment on this post.
More Posts
- © 2026 Coder Legion
- Feedback / Bug
- Privacy
- About Us
- Contacts
- You Tube
- Tiktok
- Premium Subscription
- Terms of Service
- Early Builders
Always learning, always creating.
Related Jobs
- IOS Developer (Swift, GitHub, CI/CD) | Hybrid Sunnyvale, CAE-Solutions · Full time · Sunnyvale, CA
- Retail Sales Associate Spanish BilingualVerizon · Full time · Germany
- Spanish Bilingual Appointment Setter Work From HomeInsurance Protection Specialists · Full time · Puerto Rico
Commenters (This Week)
Contribute meaningful comments to climb the leaderboard and earn badges!