Harden CSRF, ALLOWED_HOSTS, and social login security - #1515
Open
daiv-agent[bot] wants to merge 1 commit into
Open
Harden CSRF, ALLOWED_HOSTS, and social login security#1515daiv-agent[bot] wants to merge 1 commit into
daiv-agent[bot] wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security hardening across three fronts:
ALLOWED_HOSTSnow 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.pynow defaultsDJANGO_ALLOWED_HOSTSto 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) andtesting.pyoverride to["*"]sorunserverand the test client (Host: testserver) keep working;docs/reference/env-variables.mddocuments the new default.allauth.pysetsSOCIALACCOUNT_LOGIN_ON_GET = False(wasTrue), andaccount/login.htmlrenders 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.tests/unit_tests/chat/api/test_csrf.pypinning both halves of CSRF onPOST /api/chat/cancelwith Django's realClient(enforce_csrf_checks=True): a cookie-authenticated POST withoutX-CSRFTokenis rejected (403), and one carrying a matching token reaches the handler (200).daiv/daiv/api.pydocuments that django-ninja 1.x enforces CSRF per-route at the auth-class level (django_auth/SessionAuthrunscheck_csrf), not via aNinjaAPI(csrf=...)flag; Bearer/API-key clients are unaffected.AGENTS.mdupdated with theALLOWED_HOSTSfail-closed and ninja-CSRF invariants, plus theparablegit-source pinning note ([tool.uv.sources]revfreezes the commit, not the dep line).💡 Instructions for the reviewer: