Suppose the interface has frontend.example.com and backend domain backend.example.com. (If you are something like a Django rest framework) If you can use two methods, you can enable the ie ,. CSRF or CORS protection
For CORS,
pip install django-cors-headers
and then set this to INSTALLED_APPS, MIDDLEWARE_CLASSES and add the external domain to CORS_ORIGIN_WHITELIST.
CORS_ORIGIN_WHITELIST = ( 'frontend.example.com' )
CORS blocks any HTTP request originating from any domain other than frontend.example.com
For CSRF,
CSRF_COOKIE_DOMAIN = ".mydomain.com"
and if you are using an Angular app, follow these steps:
$httpProvider.defaults.xsrfCookieName = 'csrftoken'; $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; $httpProvider.defaults.withCredentials = true;
and then add the headers and then make an http request.
headers : { "x-csrftoken" : $cookies.csrftoken }
source share