Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TheFriendlyHacker's avatar

Vue XSS and CSRF protection...

If I were to create an SPA using Vue.js, what extra steps should I take to make sure I'm not vulnerable to CSRF and XSS attacks?

Assume that I'm using localstorage to keep JWT tokens on the client-side.

0 likes
2 replies
christopher's avatar

Add the csrf_token in your html head as a meta tag

<meta id="token" name="token" content="{{ csrf_token() }}">

Then in your Vue.js Main File add this token to your Vue Instance.

Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('content');

Please or to participate in this conversation.