Skip to content

Security: remove hardcoded Django SECRET_KEY from settings.py (projects-hub#56) - #2

Merged
lancer1977 merged 1 commit into
retropiefrom
security-remove-hardcoded-secret-key
Sep 5, 2026
Merged

Security: remove hardcoded Django SECRET_KEY from settings.py (projects-hub#56)#2
lancer1977 merged 1 commit into
retropiefrom
security-remove-hardcoded-secret-key

Conversation

@lancer1977

Copy link
Copy Markdown
Owner

Summary

project/settings.py had a hardcoded Django SECRET_KEY literal committed
to source control, tracked at
Polyhydra-Games/projects-hub#56.

This PR is the safe, decision-free slice of that issue, following the same
pattern used for lancer1977/TwitchySharp#2 (plaintext Discord webhook,
merged as PR RetroPie#3):

  • Replaces the literal SECRET_KEY = '...' value with
    SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', ''), so no key value
    lives in source control going forward. No fallback equal to the old
    leaked value was added anywhere.
  • Adds scripts/check-no-plaintext-secret-key.sh, a scanner that fails if
    project/settings.py ever again assigns SECRET_KEY a literal
    quoted value instead of an os.environ/os.getenv lookup, plus a
    fixture-based test (scripts/test-no-plaintext-secret-key.sh) proving
    the scanner catches a value-shaped literal and passes an
    environment-variable reference -- without ever printing a real secret
    value.
  • Wires both into the existing scripts/validate.sh (already run by
    .github/workflows/ci.yml on push/PR), rather than adding a second
    workflow, since this repo already has that lightweight validation
    pipeline (ci: tier RetroPie validation).

Note: this branch targets retropie, which is this repo's actual current
default branch (confirmed via gh repo view) and whose HEAD is the commit
the tracking issue cites (4e600f1da...) -- not master, which is a stale
2016-era branch that predates this repo's CI setup.

Out of scope (reserved for the security owner)

Per projects-hub#56's own stated scope boundary, this PR does not:

  • Rotate or revoke the actual leaked SECRET_KEY value.
  • Determine or state whether that key was ever deployed, or whether any
    instance relying on it is "safe" or "already rotated" -- there is no way
    to know that from this repo alone.
  • Touch any secret manager, deployment system, or runtime configuration.

This repo appears to be a mostly-dormant scaffold ("not maintained
anymore" per its README); whether it currently has runtime traffic
depending on this key is unconfirmed either way and is left to the
security owner to determine.

Test plan

  • bash scripts/validate.sh run locally on this branch -- all checks
    pass, including the new scanner confirming no hardcoded
    SECRET_KEY literal remains in project/settings.py.
  • CI (ci workflow) passes on this PR.

🐉 Polyhydra Games

https://claude.ai/code/session_01MMdUadpjqj5MfSNgvqS1eM

project/settings.py previously assigned SECRET_KEY a plaintext literal
value committed to source control. This replaces it with an
os.environ.get('DJANGO_SECRET_KEY', '') lookup, so no key value lives
in source control going forward.

Also adds a CI guard (scripts/check-no-plaintext-secret-key.sh, with a
fixture-based test in scripts/test-no-plaintext-secret-key.sh) that
scans project/settings.py for a hardcoded SECRET_KEY literal and fails
the check if one is reintroduced, wired into the existing
scripts/validate.sh / .github/workflows/ci.yml pipeline.

Rotation of the actual leaked key value, confirming whether any
deployed instance ever relied on it, and any other runtime/deployment
action are out of scope here and reserved for the security owner --
see Polyhydra-Games/projects-hub#56.

Co-Authored-By: Polyhydra Games <noreply@polyhydragames.com>
Claude-Session: https://claude.ai/code/session_01MMdUadpjqj5MfSNgvqS1eM
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T17:09:08.279547Z 4b6cf0f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b6cf0f34e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/validate.sh
set -euo pipefail

./scripts/test-no-plaintext-secret-key.sh
./scripts/check-no-plaintext-secret-key.sh project/settings.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scan and remove every tracked copy of the key

At this commit, a repository-wide search still finds the same non-placeholder key literal in tracked project/settings.py.old, and tracked project/settings.pyc also embeds it, but this validation invokes the scanner only on project/settings.py. CI therefore passes while checkouts and source archives continue distributing the credential; remove the backup/compiled artifacts and make the check cover all tracked candidate files.

AGENTS.md reference: AGENTS.md:L37-L37

Useful? React with 👍 / 👎.

Comment thread project/settings.py
# The key must be provided via the DJANGO_SECRET_KEY environment variable at
# runtime. No literal key value lives in source control -- see
# Polyhydra-Games/projects-hub#56 for the tracking issue and rotation status.
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Provision the key before making it mandatory

When DJANGO_SECRET_KEY is absent—as it is for a fresh clone following the README, make install, or rpmanager.sh, none of which provisions or documents this variable—the expression resolves to an empty string. Django 1.8 rejects an empty SECRET_KEY while initializing settings, so both the installation migration and documented launcher fail before the application can start; add a secure provisioning path before requiring the variable.

Useful? React with 👍 / 👎.

@lancer1977
lancer1977 merged commit e4ce9f4 into retropie Sep 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant