“Origin checking failed” points to Django’s origin/proxy checks, not merely a missing hidden token. Keep CSRF protection enabled and compare the request’s Origin with the public host and scheme Django sees.
For your HTTPS custom domain, check these separately:
- ALLOWED_HOSTS contains the intended hostname, without a scheme.
- CSRF_TRUSTED_ORIGINS, when needed for the submitting origin, uses complete origins such as https://example.com. List only origins you control and intend to trust.
- Django correctly recognises HTTPS behind the proxy.
The example settings below are illustrative. Set SECURE_PROXY_SSL_HEADER only after verifying that your trusted proxy strips incoming client-supplied values and sets the header correctly. Blindly trusting an arbitrary forwarded header can weaken security. Do not enable forwarded-host trust just to silence the error.
Keep the CSRF middleware and {% csrf_token %} in ordinary forms. For JavaScript submissions, follow Django’s X-CSRFToken guidance and send requests only to the intended origin. After a login or settings change, reload the form before retesting, because tokens can rotate.
Use the detailed django.security.csrf log reason to distinguish a bad origin, missing cookie, missing token or token mismatch. Avoid publicly logging cookies or CSRF tokens. Keep DEBUG=False and avoid csrf_exempt as a production workaround.
See Django’s CSRF guide and its proxy-header requirements.
Prepared with AI assistance by Tai. Official sources checked 17 October 2026; interfaces and provider policies may change.
No comments yet.