Skip to content

[CRITICAL] Weak default SECRET_KEY enables full system compromise in production deployments #2010

@namann5

Description

@namann5

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GSSoCUnder GirlScript Summer of CodebugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions