Skip to content

harden(policy/django): deny the Django startup hooks inside apps/** - #124

Merged
bkd-dotcom merged 1 commit into
mainfrom
harden-django-startup-hooks
Sep 9, 2026
Merged

bkd-dotcom merged 1 commit into
mainfrom
harden-django-startup-hooks

Conversation

@bkd-dotcom

Copy link
Copy Markdown
Member

Follow-up to #123, which I reviewed and merged. The policy is sound; this closes one gap between what it promises and what it enforces.

The gap

django.yaml's summary says "Migrations, production settings and anything that runs at manage.py startup stay off-limits", and it denies **/conftest.py on exactly that reasoning — code that executes on import has a far larger blast radius than app code.

But AppConfig.ready() in apps.py, and the signal handlers it imports, run on every boot: every manage.py invocation, every worker, every test session. Both live under apps/**, which is otherwise allowed — so the promise did not hold for the two files that most obviously break it.

Verified against the real evaluate_contract before the change:

ADMIT  apps/billing/apps.py
ADMIT  apps/billing/signals.py

and after:

BLOCK  apps/billing/apps.py
BLOCK  apps/billing/signals.py
ADMIT  apps/billing/models.py
ADMIT  apps/billing/views.py
ADMIT  tests/test_billing.py
ADMIT  requirements/base.txt

Evidence, not assertion

apps/billing/apps.py is added to @policy blocks, so tests/test_policy_registry.py proves the deny through the production evaluator rather than trusting a comment — the registry's own rule.

Deliberately left alone

admin.py and management/commands/** stay admitted. Neither runs at startup, both are ordinary app code an agent should be able to write, and blocking them would be redesigning the contributor's policy rather than closing the gap it named.

The policy's summary promises that "anything that runs at manage.py startup
stays off-limits", and it denies **/conftest.py on exactly that reasoning —
code that executes on import has a far larger blast radius than app code.

AppConfig.ready() in apps.py, and the signal handlers it imports, run on
every boot: every manage.py invocation, every worker, every test session.
Both live under apps/**, which is otherwise allowed, so the promise did not
hold for the two files that most obviously break it.

Adds them to forbidden_paths and declares apps/billing/apps.py in
@Policy blocks, so tests/test_policy_registry.py proves the deny through
the real evaluate_contract rather than asserting it in a comment.
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Signetry Reviewer — 🟡 Needs human review

A human should decide — the required check is pending.

Deterministic gates (the authority)

Gate Status
Required status check ⏳ pending
Secret scan ✅ clean
CI permission / OIDC ✅ no forbidden change
Dependency skew ✅ ok
All green ❌

Findings

No issues found by the deterministic scanners.

Merge

A human should review and merge.

This review is advisory. It never merges on its own judgement — the deterministic gates + a human are the authority. Findings can have false negatives; a green bot verdict is not a guarantee.

@bkd-dotcom
bkd-dotcom merged commit c0a759f into main Sep 9, 2026
8 checks 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