From ce3ec131a6978654e10a4b7d980b4d187230cf46 Mon Sep 17 00:00:00 2001 From: glaszig Date: Tue, 30 Jul 2019 17:26:30 +0200 Subject: [PATCH] add csrf token header to all resource-modifying xhr --- js/custom.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/custom.js b/js/custom.js index 7d8875bf..96b1f163 100644 --- a/js/custom.js +++ b/js/custom.js @@ -162,6 +162,15 @@ function setupBtns() { }); } +$.ajaxSetup({ + beforeSend: function(xhr, settings) { + var csrfToken = $('meta[name=csrf_token]').attr('content'); + if (/^(POST|PATCH|PUT|DELETE)$/i.test(settings.type)) { + xhr.setRequestHeader("X-CSRF-Token", csrfToken); + } + } +}); + $().ready(function(){ csrf = $('#csrf_token').val(); pageCurrent = window.location.href.split("?")[1].split("=")[1];