Delay assignment of csrftoken (#1289)

This commit is contained in:
Craig 2022-09-24 22:59:53 +10:00 committed by GitHub
parent 541caa117e
commit 05d3df92e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,14 +10,6 @@
history, history,
location, location,
) { ) {
// Parse the cookie value for a CSRF token
var csrftoken;
var cookies = ("; " + document.cookie).split("; csrftoken=");
if (cookies.length == 2) {
csrftoken = cookies.pop().split(";").shift();
} else {
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
}
// Collect the URL parameters // Collect the URL parameters
var parameters = {}; var parameters = {};
@ -68,9 +60,19 @@
var headers = opts.headers || {}; var headers = opts.headers || {};
headers['Accept'] = headers['Accept'] || 'application/json'; headers['Accept'] = headers['Accept'] || 'application/json';
headers['Content-Type'] = headers['Content-Type'] || 'application/json'; headers['Content-Type'] = headers['Content-Type'] || 'application/json';
// Parse the cookie value for a CSRF token
var csrftoken;
var cookies = ("; " + document.cookie).split("; csrftoken=");
if (cookies.length == 2) {
csrftoken = cookies.pop().split(";").shift();
} else {
csrftoken = document.querySelector("[name=csrfmiddlewaretoken]").value;
}
if (csrftoken) { if (csrftoken) {
headers['X-CSRFToken'] = csrftoken headers['X-CSRFToken'] = csrftoken
} }
return fetch(fetchURL, { return fetch(fetchURL, {
method: "post", method: "post",
headers: headers, headers: headers,