Do I need cstf protection when backend and frontend have different domains?
I have:
- React app: https://myreact.com
- Django + DRF: https://mydjango.com
- React has a form that when submitted sends a POST request to
mydjango.com/handle-formwith all the cookies, because I speicfywithCredentials: truein my ajax request (thus all the cookies are sent).
As I can see it, there's no way to perform csrf attack, because browser stores cookies only for myreact.com. And if an attacker creates a domain myreact2.com with the same exact form (that upon submitting sends POST request to mydjango.com/handle-form), cookies from myreact.com won't be sent, meaning there's no csrf attack.
The questions:
- Am I right?
- Will browser store cookies only in myreact.com or in both domains, when I make an ajax request from myreact.com to mydjango.com and mydjango.com in response sends a Set-Cookie header?
I understand how it would work, when both frontend and backend shared the same domain. CSRF attack could be very possible without csrf token or something else. But my case bothers me.