If I make a POST request without using a form and want to prevent a CSRF attack, I can do this to set the csrf token in the meta tag and return it to the header when the request is launched. Is this a good practice?
<meta name="csrf-token" content="xxx">
Put the marker back through the header using jQuery, for example:
$.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } });
jquery meta-tags csrf
tony.0919
source share