- Added a new CSRF token verification Middleware.
- Added a new ActionLog middleware to catch every modifying request and save the changes made and the user who did. - Added a new RequestLog to catch every request made whenever required.
This commit is contained in:
1 parent
9571c6a462
commit
4b86ac9e82
42 files changed
+1331
-148
No files matched your search
@@ -156,31 +156,30 @@
|
||||
}
|
||||
|
||||
launchRequest(requestMethod, input.value, editor.getValue())
|
||||
.then((response) => {
|
||||
responseHead.querySelector('.response-code').innerText = response.status;
|
||||
responseHead.querySelector('.response-message').innerText = response.statusText;
|
||||
.then((response) => {
|
||||
responseHead.querySelector('.response-code').innerText = response.status;
|
||||
responseHead.querySelector('.response-message').innerText = response.statusText;
|
||||
|
||||
aceMode = parseContentType(response);
|
||||
aceMode = parseContentType(response);
|
||||
|
||||
return response.text();
|
||||
})
|
||||
.then(body => {
|
||||
if (aceMode === "json") {
|
||||
body = JSON.stringify(JSON.parse(body), null, 2);
|
||||
return response.text();
|
||||
})
|
||||
.then(body => {
|
||||
if (aceMode === "json") {
|
||||
body = JSON.stringify(JSON.parse(body), null, 2);
|
||||
responseEditorElement.innerHTML = DOMEncode(body);
|
||||
}
|
||||
else if (aceMode === "html") {
|
||||
let b64 = btoa(unescape(encodeURIComponent(body)));
|
||||
|
||||
responseEditorElement.innerHTML = DOMEncode(body);
|
||||
}
|
||||
else if (aceMode === "html") {
|
||||
let b64 = btoa(unescape(encodeURIComponent(body)));
|
||||
responseEditorElement.innerHTML = `<iframe style='width:100%; min-height:60vh' src="data:text/html;base64,${b64}"></iframe>`
|
||||
}
|
||||
else {
|
||||
responseEditorElement.innerText = body;
|
||||
}
|
||||
|
||||
responseEditorElement.innerHTML = `<iframe style='width:100%; min-height:60vh' src="data:text/html;base64,${b64}"></iframe>`
|
||||
}
|
||||
else {
|
||||
responseEditorElement.innerText = body;
|
||||
}
|
||||
|
||||
formatResponse("ace/mode/" + aceMode);
|
||||
}).finally(() => requestDebugger.classList.remove("loading"));
|
||||
formatResponse("ace/mode/" + aceMode);
|
||||
}).finally(() => requestDebugger.classList.remove("loading"));
|
||||
|
||||
responseResponse.classList.toggle('hide', false);
|
||||
});
|
||||
@@ -197,13 +196,41 @@
|
||||
}
|
||||
});
|
||||
|
||||
async function fetchCSRFToken() {
|
||||
let headers = {
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
|
||||
if (token.value) {
|
||||
headers['X-CSRF-Token'] = token.value;
|
||||
}
|
||||
|
||||
let responseData = {
|
||||
method: "GET",
|
||||
mode: "cors",
|
||||
cache: "no-cache",
|
||||
credentials: "same-origin",
|
||||
headers: headers,
|
||||
redirect: "follow",
|
||||
referrerPolicy: "no-referrer"
|
||||
};
|
||||
|
||||
let fetching = await fetch("{% route 'lean.api:security-csrf-generate' %}", responseData).then(j => j.json())
|
||||
|
||||
if (fetching.data.token === undefined) {
|
||||
throw new Error("An error occured trying to fetch a CSRF token.");
|
||||
}
|
||||
|
||||
return fetching.data.token;
|
||||
}
|
||||
|
||||
async function launchRequest(method = "POST", url = "", body = "{}") {
|
||||
let headers = {
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
|
||||
if (token.value) {
|
||||
headers['Authorization'] = `Bearer ${token.value}`;
|
||||
headers['X-CSRF-Token'] = token.value;
|
||||
}
|
||||
|
||||
method = method.toUpperCase();
|
||||
@@ -212,14 +239,15 @@
|
||||
method: method,
|
||||
mode: "cors",
|
||||
cache: "no-cache",
|
||||
credentials: headers.Authorization ? "omit" : "same-origin",
|
||||
credentials: "same-origin",
|
||||
headers: headers,
|
||||
redirect: "follow",
|
||||
referrerPolicy: "no-referrer"
|
||||
};
|
||||
|
||||
if ( [ "HEAD", "GET" ].indexOf(method) === -1 ) {
|
||||
if ( [ "HEAD", "GET", "OPTIONS", "TRACE", "CONNECT" ].indexOf(method) === -1 ) {
|
||||
responseData.body = body;
|
||||
responseData.headers['X-CSRF-Token'] = await fetchCSRFToken();
|
||||
}
|
||||
|
||||
requestDebugger.classList.add("loading");
|
||||
|
||||
Reference in new issue
Block a user