1

Laravel(backend) and VueJS(frontend created with Vue CLI) are separated, hence have different domains and repositories. I am wondering what is the best way to pass a CSRF token from Laravel to VueJS safely.

I've found some old questions here and on Laracasts but they are either irrelevant, outdated or have no answer. Here are a few:

Pass csrf token from Laravel to Vue

Creating a sign up token for Laravel app from separate frontend app

(Laracasts forum) CSRF in separate angular app

I am aware that Laravel ships with $except array in VerifyCSRFToken middleware. Adding frontend's URL to this list will create a security flaw, am I correct?

7
  • checkout this one: stackoverflow.com/questions/42242513/… Commented Dec 18, 2019 at 10:10
  • You need to add <meta> of CSRF in the index page and add the CSRF in each ajax call ! Commented Dec 18, 2019 at 10:11
  • 1
    @Maraboc I've mentioned that Laravel does not generate any view in this case, so I can't parse meta tag. I have a completely separate, standalone Vue instance. Commented Dec 18, 2019 at 10:14
  • @Maraboc that is how laravel does it if you don't separate frontend from backend. When separated, it makes no sense to store it in HTML. Andrii: for SPAs, you shouldnt use sessions for authentication but rather JWT authentication, e.g. with Laravel Passport. If you don't use sessions anymore, your CSRF token becomes obsolete. Commented Dec 18, 2019 at 10:23
  • @MatthiasS makes sense, now I get it. I think this should be an answer to my question. Feel free to post it. Commented Dec 18, 2019 at 15:14

1 Answer 1

2

In case of using a standalone application (vue, react, angular ....) the best solution is to use Laravel Passport instead of using CSRF tokens.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.