My project is deploying iframes on several 3rd party sites, that are all known and registered within the django application.
In these iframes, users can trigger some ajax-form events. Opening the site directly, everything works fine. If I open the 3rd party site, containing the iframe, django is throwing an error after firing the ajax event (403), saying that CSRF failed.
In the form I used {% csrf_token %} which is set in the html. However it does not set the corresponding cookie, when calling the site through the iframe (found out both using inspection mode in browser).
I do know that I could use a decorator @csrf_exempt
, but that will disable csrf-protection all in one, which I don´t want to do.
So my questions are:
- Why does django not set the CSRF Cookie, when the whole page is loaded through an iframe?
- Is it possible to get django to set the cookie OR is it possible to only exempt the known urls from csrf?
- Is there a way I dont see?
Thanks a lot for your time! :)