Skip to content

Commit a5b4f0f

Browse files
committed
Send X-CSRF-TOKEN in AJAX calls
Signed-off-by: yubiuser <github@yubiuser.dev>
1 parent 6eb4628 commit a5b4f0f

10 files changed

Lines changed: 21 additions & 0 deletions

scripts/js/groups-clients.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"use strict";
1212

1313
let table;
14+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1415

1516
function reloadClientSuggestions() {
1617
$.ajax({
@@ -107,6 +108,7 @@ function initTable() {
107108
url: document.body.dataset.apiurl + "/clients",
108109
dataSrc: "clients",
109110
type: "GET",
111+
headers: { "X-CSRF-TOKEN": csrfToken },
110112
},
111113
order: [[0, "asc"]],
112114
columns: [

scripts/js/groups-domains.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
let table;
1414
let GETDict = {};
15+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1516

1617
$(() => {
1718
GETDict = utils.parseQueryString();
@@ -105,6 +106,7 @@ function initTable() {
105106
url: document.body.dataset.apiurl + "/domains",
106107
dataSrc: "domains",
107108
type: "GET",
109+
headers: { "X-CSRF-TOKEN": csrfToken },
108110
},
109111
order: [[0, "asc"]],
110112
columns: [

scripts/js/groups-lists.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
let table;
1414
let GETDict = {};
15+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1516

1617
$(() => {
1718
GETDict = utils.parseQueryString();
@@ -176,6 +177,7 @@ function initTable() {
176177
url: document.body.dataset.apiurl + "/lists",
177178
dataSrc: "lists",
178179
type: "GET",
180+
headers: { "X-CSRF-TOKEN": csrfToken },
179181
},
180182
order: [[0, "asc"]],
181183
columns: [

scripts/js/groups.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"use strict";
1111

1212
let table;
13+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1314

1415
function handleAjaxError(xhr, textStatus) {
1516
if (textStatus === "timeout") {
@@ -32,6 +33,7 @@ $(() => {
3233
error: handleAjaxError,
3334
dataSrc: "groups",
3435
type: "GET",
36+
headers: { "X-CSRF-TOKEN": csrfToken },
3537
},
3638
order: [[0, "asc"]],
3739
columns: [

scripts/js/messages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
let table;
1313
const toasts = {};
14+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1415

1516
$(() => {
1617
const url = document.body.dataset.apiurl + "/info/messages";
@@ -19,6 +20,7 @@ $(() => {
1920
url,
2021
type: "GET",
2122
dataSrc: "messages",
23+
headers: { "X-CSRF-TOKEN": csrfToken },
2224
},
2325
order: [[0, "asc"]],
2426
columns: [

scripts/js/network.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"use strict";
1111

1212
let tableApi;
13+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1314

1415
// How many IPs do we show at most per device?
1516
const MAXIPDISPLAY = 3;
@@ -217,6 +218,7 @@ $(() => {
217218
url: document.body.dataset.apiurl + "/network/devices",
218219
type: "GET",
219220
dataType: "json",
221+
headers: { "X-CSRF-TOKEN": csrfToken },
220222
data: {
221223
max_devices: 999,
222224
max_addresses: 25,

scripts/js/queries.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
"use strict";
1111

12+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
13+
1214
// These values are provided by the API
1315
// We initialize them as null and populate them during page init.
1416
let beginningOfTime = null; // seconds since epoch
@@ -592,6 +594,7 @@ $(() => {
592594
url: apiURL,
593595
error: handleAjaxError,
594596
dataSrc: "queries",
597+
headers: { "X-CSRF-TOKEN": csrfToken },
595598
data(d) {
596599
if (cursor !== null) {
597600
d.cursor = cursor;

scripts/js/settings-api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let ownSessionID = null;
1414
let deleted = 0;
1515
let TOTPdata = null;
1616
let apppwSet = false;
17+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1718

1819
function renderBool(data, type) {
1920
// Display and search content
@@ -36,6 +37,7 @@ $(() => {
3637
url: document.body.dataset.apiurl + "/auth/sessions",
3738
type: "GET",
3839
dataSrc: "sessions",
40+
headers: { "X-CSRF-TOKEN": csrfToken },
3941
},
4042
order: [[1, "asc"]],
4143
columns: [

scripts/js/settings-dhcp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
let dhcpLeaesTable = null;
1313
const toasts = {};
14+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1415

1516
// DHCP leases tooltips
1617
// Bootstrap 5 has no jQuery-plugin tooltip delegation, so lazily instantiate
@@ -50,6 +51,7 @@ $(() => {
5051
url: document.body.dataset.apiurl + "/dhcp/leases",
5152
type: "GET",
5253
dataSrc: "leases",
54+
headers: { "X-CSRF-TOKEN": csrfToken },
5355
},
5456
order: [[1, "asc"]],
5557
columns: [

scripts/js/settings-dns-records.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/* global utils: false, apiFailure:false, setConfigValues: false */
99

1010
"use strict";
11+
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
1112

1213
function hostsDomain(data) {
1314
// Split record in format IP NAME1 [NAME2 [NAME3 [NAME...]]]
@@ -82,6 +83,7 @@ function populateDataTable(endpoint) {
8283
url: document.body.dataset.apiurl + "/config/dns/" + endpoint,
8384
type: "GET",
8485
dataSrc: `config.dns.${endpoint}`,
86+
headers: { "X-CSRF-TOKEN": csrfToken },
8587
},
8688
autoWidth: false,
8789
columns,

0 commit comments

Comments
 (0)