Replies: 3 comments 1 reply
-
Nothing immediately pops out - however - you should only need to use one mechanism - either a cookie or a GET to fetch the CSRF token. As to your 'preferred' implementation - what exactly do you mean by 'default endpooints'> Are you just referring to the endpoint names e.g. /login or to the views/forms behind them? Endpoint names can easily be changed. |
Beta Was this translation helpful? Give feedback.
-
I am having a similar problem with a Next.js/React frontend and the Flask-Security JSON API. Frontend is running on I cannot get Flask-Security to set a XSRF-Token cookie. My setup is almost identical to the docs except for a few things. Settings were copied exactly into my Flask settings file. CSRFProtect is initialized before Flask-Security. Flask-CORS docs says it takes a list for
It seems like the CORS settings are active, because in my console under network, I see the response headers has My axios request is pretty basic:
In network console, I can see that a The Flask-Security user registration process happens with no problem. Since CSRF token is returned in the body of the register form, I'm guessing I could just save that in a cookie client side, but I would like to use the actual features of Flask-Security. |
Beta Was this translation helpful? Give feedback.
-
The XSRF-Cookie is only set once the user has successfully logged in (and presumable you have SECURITY_CSRF_IGNORE_UNAUTH_ENDPOINTS=True set as the docs suggest). So you should see that cookie set in the response from /login. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am trying to create an app that uses a REST API as a back end, and a Vue front end. I am trying to use Flask Security for both basic and token-based authentication, as well as CSRF protection. This is where I seem to be struggling, and I'd really appreciate some helm.
I followed the example for configs given in the docs, and I have read through the various patterns. So far, I seem unable to be able to get CSRF protection to work. I have set up Flask-Security to pass the CSRF token as a
XSRF-Token
cookie. I use Axios to make a Get request to retrieve a csrf token from the login page, but even when I get Axios to return the token as aX-XSRF-Token
header, I still get 'csrf token is missing' as an error on the form.My configs for Flask-Security are as follows:
My preferred implementation would be to not use the default endpoints provided by Flask-Security, and instead define my own endpoints. Any suggestions about what I may be doing wrong, and what I may have missed?
Beta Was this translation helpful? Give feedback.
All reactions