Skip to content

Harden CSRF, ALLOWED_HOSTS, and social login security - #1515

Open
daiv-agent[bot] wants to merge 1 commit into
mainfrom
fix/harden-csrf-allowed-hosts-social-login
Open

Harden CSRF, ALLOWED_HOSTS, and social login security#1515
daiv-agent[bot] wants to merge 1 commit into
mainfrom
fix/harden-csrf-allowed-hosts-social-login

Conversation

@daiv-agent

@daiv-agent daiv-agent Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Security hardening across three fronts: ALLOWED_HOSTS now fails closed in production, CSRF enforcement on session-authenticated ninja routes is pinned by a regression test, and social (GitHub/GitLab) logins are POST-initiated to prevent login-CSRF.

Key Changes:

  • common.py now defaults DJANGO_ALLOWED_HOSTS to the empty list (was "*"), so Django refuses to serve until the operator configures hosts — blocking host-header poisoning from reaching login-by-code emails and OAuth metadata. debug.py (dev only) and testing.py override to ["*"] so runserver and the test client (Host: testserver) keep working; docs/reference/env-variables.md documents the new default.
  • allauth.py sets SOCIALACCOUNT_LOGIN_ON_GET = False (was True), and account/login.html renders the GitHub/GitLab provider links as POST forms with {% csrf_token %} instead of GET anchors, so a crafted GET link can no longer trigger a login.
  • Added tests/unit_tests/chat/api/test_csrf.py pinning both halves of CSRF on POST /api/chat/cancel with Django's real Client(enforce_csrf_checks=True): a cookie-authenticated POST without X-CSRFToken is rejected (403), and one carrying a matching token reaches the handler (200).
  • daiv/daiv/api.py documents that django-ninja 1.x enforces CSRF per-route at the auth-class level (django_auth/SessionAuth runs check_csrf), not via a NinjaAPI(csrf=...) flag; Bearer/API-key clients are unaffected.
  • AGENTS.md updated with the ALLOWED_HOSTS fail-closed and ninja-CSRF invariants, plus the parable git-source pinning note ([tool.uv.sources] rev freezes the commit, not the dep line).

⚠️ DAIV can make mistakes. Please review the changes and merge the MR if everything looks good.
🔗 Generated by DAIV — view sessions


💡 Instructions for the reviewer:

  • 💬 Just leave comments/reviews mentioning @daiv-agent to get DAIV to address them for you.

@daiv-agent daiv-agent Bot added the daiv Delegate issues to DAIV agent label Aug 19, 2026
@srtab srtab self-assigned this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

daiv Delegate issues to DAIV agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant