[Security] Fix hardcoded Django SECRET_KEY with environment variable (CWE-798) - #176
Open
saaa99999999 wants to merge 1 commit into
Open
[Security] Fix hardcoded Django SECRET_KEY with environment variable (CWE-798)#176saaa99999999 wants to merge 1 commit into
saaa99999999 wants to merge 1 commit into
Conversation
Replace the hardcoded SECRET_KEY ("django-insecure-...") with
DJANGO_SECRET_KEY environment variable. Add startup validation that
rejects empty keys and any key prefixed with "django-insecure-".
Add .env.example with generation instructions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
CVE Request — Action Needed from MaintainerThis PR fixes security vulnerabilities. To assign a CVE number: GitHub only issues CVEs from the official upstream repository, not from forks. Please:
If you prefer, I can submit the CVE via MITRE (cveform.mitre.org) instead — just let me know. Thank you for reviewing this PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security Audit Report ??Lithium (wsvincent/lithium)
Manual code audit discovered 1 critical security vulnerability ??CWE-798: Hardcoded Django SECRET_KEY.
CRITICAL: CWE-798 ??Hardcoded Django SECRET_KEY Published in Public Repository (CVSS 9.1)
Location:
django_project/settings.py:12Data Flow:
Description:
The Django SECRET_KEY is the root of trust for all cryptographic operations in Django. The settings.py file contained a hardcoded key with the
django-insecure-prefix ??this is the exact format Django'sstartprojectcommand generates with the explicit warning "This key is insecure and should not be used in production."The key was published in the public GitHub repository at
wsvincent/lithium(previouslydjangox). Anyone who views the repository can:The key has the
django-insecure-prefix which Django 5.2+ specifically identifies and warns about. Django will emit system check warnings (security.W009) for keys with this prefix.Proof of Concept (session forgery):
Proof of Concept (password reset token):
Fix:
django_project/settings.py:12-17: Replaced hardcoded SECRET_KEY withos.environ.get("DJANGO_SECRET_KEY", "")and added startup validation that throwsValueErrorif the key is empty or uses thedjango-insecure-prefix..env.example: Added with documentation and key generation instructions (python -c "import secrets; print(secrets.token_urlsafe(50))").Before ??After:
django_project/settings.py:12:django_project/settings.py:19:Changes in this PR (2 files)
CVSS 3.1 Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N??9.1 (Critical)Manual security audit of Django settings and key management