I know
this question has already been asked so many times, but after hours of searching I still don't have a clear answer to my problem.
Even projects like https://github.com/pillarjs/understanding-csrf have been abandoned and have not answered to new questions and doubts over the years like this.
PROBLEM
Let's say I have:
- a back-end on
back.domain.comand - a front-end on
front.domain.com.
My back-end is a simply nodejs app with these rest endpoints:
POST /login:- accepts JSON body like:
{"username": "myname", "password": "mypass"} - verify credentials
- if OK gives 200 and create a cookie with session
- if NOT gives 401
- accepts JSON body like:
GET /players:- check session in cookie
- if OK gives 200 with {"players": "[...]"}
- if NOT gives 401
POST /player/1:- check session in cookie
- if OK gives 200 and edit player
- if NOT gives 401
My front-end app has:
/loginpage with a form (withusernameandpasswordfields) for issue aPOSTrequest toback.domain.com/login/playerswhich request aGETrequest toback.domain.com/playersa button which issues a
POSTrequest toback.domain.com/player/1
QUESTIONS
Do I need CSRF protection in this scenario?
I think YES, I need because an attacker can issue a request to
back.domain.com/player/1frommalicious.site.comand use my session cookie to edit player because I'm logged in (and I still have a session cookie) on mydomain.com.Do I need CSRF protection (e.g. an
X-CSRF-Tokenheader) when I the first time login onback.domain.com/login?- In this scenario I still don't have any session cookie in my browser.
- And also I don't know where to get my CSRF token for
X-CSRF-Tokenauthorization header too.
I read on https://fractalideas.com/blog/making-react-and-django-play-well-together-single-page-app-model they are creating a dedicated endpoint on back-end for this and they explain it's not a security vulnerability.
What do you think about?