Description
Severity: CRITICAL
CWE: CWE-798 (Use of Hard-coded Credentials)
Affected file: core/settings.py:27
Vulnerability
Weak default SECRET_KEY
In core/settings.py:27, SECRET_KEY falls back to a hardcoded value when the environment variable is not set:
SECRET_KEY = os.environ.get('SECRET_KEY', 'django-insecure-dev-key-for-local-testing')
This key is publicly known (visible in source code). If any production deployment fails to set SECRET_KEY, Django silently uses this weak key. An attacker can then:
- Forge session cookies — impersonate any user
- Forge CSRF tokens — perform state-changing actions on behalf of victims
- Bypass OTP verification — OTP hashes use
settings.SECRET_KEY as HMAC salt (game/views.py:901-903, 1048-1050)
- Forge password reset tokens — take over any account
The key is used extensively as a cryptographic salt in the OTP system:
# game/views.py:901-903 (register_view)
otp_hash = hashlib.sha256(
f"{otp}:{settings.SECRET_KEY}".encode()
).hexdigest()
# game/views.py:1048-1050 (verify_otp)
entered_otp_hash = hashlib.sha256(
f"{entered_otp}:{settings.SECRET_KEY}".encode()
).hexdigest()
# game/views.py:1186-1188 (resend_otp)
otp_hash = hashlib.sha256(
f"{otp}:{settings.SECRET_KEY}".encode()
).hexdigest()
Missing Content Security Policy (amplifies risk)
No CSP headers configured. The app loads chess piece images from external CDN (images.chesscomfiles.com) in board.js:20. Without CSP, a compromised CDN can inject arbitrary JS.
Proposed Approach
Fix 1: Enforce strong SECRET_KEY at startup
In core/settings.py, raise ImproperlyConfigured if the default key is used outside debug mode.
Fix 2: Add Content Security Policy middleware
Create middleware that injects CSP headers allowing only 'self' and the chess.com CDN for images.
Impact
Successful exploitation allows complete account takeover of any user including administrators.
Request
Please assign this issue to me (@namann5). I have already prepared a fix branch and will submit a PR shortly.
Description
Severity: CRITICAL
CWE: CWE-798 (Use of Hard-coded Credentials)
Affected file:
core/settings.py:27Vulnerability
Weak default SECRET_KEY
In
core/settings.py:27, SECRET_KEY falls back to a hardcoded value when the environment variable is not set:This key is publicly known (visible in source code). If any production deployment fails to set
SECRET_KEY, Django silently uses this weak key. An attacker can then:settings.SECRET_KEYas HMAC salt (game/views.py:901-903,1048-1050)The key is used extensively as a cryptographic salt in the OTP system:
Missing Content Security Policy (amplifies risk)
No CSP headers configured. The app loads chess piece images from external CDN (
images.chesscomfiles.com) inboard.js:20. Without CSP, a compromised CDN can inject arbitrary JS.Proposed Approach
Fix 1: Enforce strong SECRET_KEY at startup
In
core/settings.py, raiseImproperlyConfiguredif the default key is used outside debug mode.Fix 2: Add Content Security Policy middleware
Create middleware that injects CSP headers allowing only
'self'and the chess.com CDN for images.Impact
Successful exploitation allows complete account takeover of any user including administrators.
Request
Please assign this issue to me (@namann5). I have already prepared a fix branch and will submit a PR shortly.