Skip to content

fix(settings): reject KEY_HMAC_SECRET dev default in all environments#34

Open
Shaivpidadi wants to merge 1 commit intodevfrom
feat/1.5c-key-hmac-secret-dev-default-rejection
Open

fix(settings): reject KEY_HMAC_SECRET dev default in all environments#34
Shaivpidadi wants to merge 1 commit intodevfrom
feat/1.5c-key-hmac-secret-dev-default-rejection

Conversation

@Shaivpidadi
Copy link
Copy Markdown
Member

Summary

Follow-up to Cipher's GOV-573 review of precheck#31. The default for key_hmac_secret shifted from \"\" to _DEFAULT_KEY_HMAC_SECRET, which meant the service signed API-key HMACs with a publicly-known marker string under DEBUG=true. Because KEY_HMAC_SECRET is the API-key identity boundary (not a recoverable webhook signature), the dev marker is now rejected in every environment.

Changes

  • app/settings.py — Added explanatory comment on _DEFAULT_KEY_HMAC_SECRET and a docstring on the key_hmac_secret field noting the debug-marker danger.
  • app/settings.py — Promoted the default-marker check for KEY_HMAC_SECRET out of the if not self.debug: branch so it runs unconditionally.
  • tests/test_settings.py — Added a parametrized test over DEBUG=true and DEBUG=false confirming the dev marker is rejected in both, plus a positive test that a non-default dev value still starts cleanly.

Breaking change

Operators running with DEBUG=true and the default KEY_HMAC_SECRET will now fail fast at startup. The repo's tests/conftest.py already sets a unique value (test-hmac-secret-for-ci-only), and env.example already flags the variable as required — any local dev env that relied on the silent default must now set one.

GovernsAI Tracker issue

GOV-1486

Reviewers

Tagging Nexus (code quality) and Cipher (security/arch) — both approvals required.

Test plan

  • `python -m black --check app/ tests/`
  • `python -m isort --check-only app/ tests/`
  • `python -m pytest tests/ --no-cov` — 192 passed, 9 skipped
  • New parametrized test verifies rejection under both `DEBUG=true` and `DEBUG=false`
  • New positive test verifies non-default dev values still start cleanly

Cipher's review of GOV-573 (precheck#31) flagged that key_hmac_secret's
default shifted from "" to the public _DEFAULT_KEY_HMAC_SECRET marker.
In DEBUG=true the service therefore signed API-key HMACs with a known
string, making any hash trivially forgeable. Because KEY_HMAC_SECRET is
the API-key identity boundary (not a recoverable webhook signature),
the dev marker must be rejected unconditionally.

- Document the _DEFAULT_KEY_HMAC_SECRET constant and the key_hmac_secret
  field: debug HMAC keys are deterministic and public; never restore a
  debug database into a non-debug environment.
- Promote the default-marker check for KEY_HMAC_SECRET out of the
  non-debug branch so it runs in every environment, including DEBUG=true.
- Add parametrized tests covering both debug=true and debug=false, plus
  a positive test that non-default dev values are still accepted.

Refs: GOV-1486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant