Skip to content

2.35.3: require SECRET_KEY and ALLOWED_HOSTS from config.ini on test/prod - #1464

Merged
jonfroehlich merged 3 commits into
masterfrom
1460-fail-closed-server-config
Nov 21, 2026
Merged

jonfroehlich merged 3 commits into
masterfrom
1460-fail-closed-server-config

Conversation

@jonfroehlich

@jonfroehlich jonfroehlich commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Part of #1460.

What changed

settings.py fell back to development defaults for SECRET_KEY and ALLOWED_HOSTS whenever config.ini did not set them, in every environment. Those fallbacks are now local-dev only. With DJANGO_ENV of PROD or TEST, a missing, blank, or dev-default value raises ImproperlyConfigured and the site does not start.

Both server config files were checked beforehand and set both options, so this changes nothing on either site today. It is a guard against a future config mistake going unnoticed.

  • read_server_setting() in makeabilitylab/settings.py
  • parse_allowed_hosts(): strips entries, and on test/prod raises if no hostname is left
  • website/tests/test_server_config.py: 13 cases, no DB
  • CI: the check --deploy step writes a throwaway config.ini first, since settings no longer load as PROD without one
  • Docs: docs/DEPLOYMENT.md and CLAUDE.md describe the requirement and how to verify a server's file without printing the key

Verification

  • New tests pass standalone; settings import as DJANGO_ENV=PROD without a key raises, and as local dev loads unchanged.
  • Full suite: CI on this PR.

After merge

A refusal to start does not fail the deploy job: docker compose up -d returns before the app boots, so the run goes green and the site answers 502/503. The error text only reaches the container's stdout on the Docker host. If -test is down after this deploys, revert this PR.

Review

An independent review (Opus 5.5, claude-opus-5-5) led to the third commit: a separate error for an unread config.ini, an empty-host-list check, corrected failure-mode docs, and 6 more tests.

🤖 Generated with Claude Code — Fable 5.2, claude-fable-5-2

jonfroehlich and others added 2 commits November 21, 2026 15:02
…config.ini

settings.py fell back to an in-repo SECRET_KEY and ALLOWED_HOSTS=['*'] whenever
config.ini lacked them, on any environment. Both fallbacks now apply only
off-server; with DJANGO_ENV of PROD or TEST, read_server_setting() raises
ImproperlyConfigured for a missing, blank, or dev-default value.

- tests: website/tests/test_server_config.py (7 cases, no DB)
- CI: the check --deploy step writes a throwaway config.ini first
- docs: DEPLOYMENT.md and CLAUDE.md describe the requirement and how to
  verify a server's config.ini without printing the key

Do not merge until both server config files are confirmed to set both options.

Part of #1460.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jonfroehlich jonfroehlich added Backend Maintenance Security Security: XSS, auth, dependency CVEs, hardening labels Nov 21, 2026
…t, correct docs

From an independent review of this branch:
- An unreadable/missing config.ini now gets its own error instead of being
  reported as a missing option; the startup CONFIG_FILE line says so too
  (the old `if not config` was never true).
- parse_allowed_hosts(): an ALLOWED_HOSTS that parses to no hostnames raises
  on PROD/TEST (Django would start and 400 every request); '*' is accepted
  with a printed warning.
- Docstring/CLAUDE.md no longer claim a refusal fails the deploy job: the job
  goes green and the site returns 502/503, so the response is to revert.
- Tests: 13 cases (was 7). CI: set the cleanup trap before writing config.ini.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jonfroehlich
jonfroehlich merged commit d16d5ed into master Nov 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend Maintenance Security Security: XSS, auth, dependency CVEs, hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant