Open frederikhors opened 5 years ago
@frederikhors Browsers automatically fire off OPTIONS pre-flight requests when they're needed to determine CORS headers.
Note the section on pre-flighted requests here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
The options handler is a single request, and the login post is a follow-up to that that happens after the options is complete. There is no first request failure happening.
It's actually possible there's a bug here because in order for the browser to send back that header it may have to be specified in the CORS headers.
For anyone else, Authboss puts CSRF token in the header. If you are importing Authboss into a new server(project), it may be a good idea to put CSRF token in form or somewhere else, or your tokens will fail on both sides. I use echo framework with Authboss and I put token in the form.
e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
TokenLookup: "form:csrf", // Please use token in form // authboss puts token in header causing clashes
}))
Issue opened for the creation of a wiki page that summarizes the doubts and problems for newbies (https://github.com/volatiletech/authboss/issues/210).
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:
back.domain.com
andfront.domain.com
.My back-end is a simply app with these rest endpoints:
POST /login
:{"username": "myname", "password": "mypass"}
GET /players
:POST /player/1
:My front-end app has:
/login
page with a form (withusername
andpassword
fields) for issue aPOST
request toback.domain.com/login
/players
which request aGET
request toback.domain.com/players
a button which issues a
POST
request 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/1
frommalicious.site.com
and 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-Token
header) when I the first time login onback.domain.com/login
?X-CSRF-Token
authorization 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.
I saw in
authboss-sample
you just add theX-CSRF-TOKEN
header onOPTIONS
calls.But why are you using that?
Are you using that token in javascript after the
OPTIONS
call?But the very first one call is failing, right?
I'm confused.
What do you think about using the dataInjector func to inject csrf token in json response? In fact it is like when we render csrf token in html. Right?