-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
This issue is laid out in detail here:
The api url is using djangorestframework. Everything works as expected when trying to POST data from http://example.com
to http://api.example.com
. However, when we moved to prod over https, we see the following error:
detail: "CSRF Failed: Referer checking failed - https://example.com/some/url does not match https://api.example.com/."
Both sites are secure (https) and both sites are trusted. The same_origin
check happens in the CsrfViewMiddleware (below) [1] which is subclassed in djangorestframework [2]:
if not same_origin(referer, good_referer):
reason = REASON_BAD_REFERER % (referer, good_referer)
return self._reject(request, reason)
However, this would never seem to allow me to post across subdomains since it won't be the same_origin. It seems logical for POST requests to be made across subdomains, right? Am I just missing something? All GET requests work as expected over https.
I've already added the necessary csrftoken headers via:
- http://www.django-rest-framework.org/topics/ajax-csrf-cors/
- https://docs.djangoproject.com/en/dev/ref/csrf/#ajax
and I'm using the django-cors-headers lib as well.
[1] https://github.com/django/django/blob/eef95ea96faef0b7dbbe0c8092202b74f68a899b/django/middleware/csrf.py#L159
[2] https://github.com/tomchristie/django-rest-framework/blob/010f2ee9bd8696f8332e67d73b9ad488b4423d20/rest_framework/authentication.py#L27