fix: only add CSRF body field on POST requests, not GET
This commit is contained in:
parent
037791bbd5
commit
78cae8dea4
1 changed files with 5 additions and 5 deletions
10
web/app.js
10
web/app.js
|
|
@ -23,12 +23,13 @@ function showToast(message, type) {
|
|||
async function apiFetch(path, opts) {
|
||||
opts = opts || {};
|
||||
opts.headers = opts.headers || {};
|
||||
// Send CSRF token both as header AND in POST body (Zoraxy validates via form field)
|
||||
var method = (opts.method || 'GET').toUpperCase();
|
||||
var isPost = (method === 'POST' || method === 'PUT' || method === 'PATCH');
|
||||
|
||||
if (csrfToken && csrfToken !== '{{.csrfToken}}') {
|
||||
opts.headers['X-Zoraxy-Csrf'] = csrfToken;
|
||||
opts.headers['X-CSRF-Token'] = csrfToken;
|
||||
// For POST requests, also include in body
|
||||
if (!opts.method || opts.method.toUpperCase() === 'POST') {
|
||||
// For POST requests, include token in body (Zoraxy validates via form field)
|
||||
if (isPost) {
|
||||
if (opts.body && typeof opts.body === 'object') {
|
||||
opts.body.csrfToken = csrfToken;
|
||||
} else {
|
||||
|
|
@ -45,7 +46,6 @@ async function apiFetch(path, opts) {
|
|||
try {
|
||||
var data = JSON.parse(text);
|
||||
} catch (e) {
|
||||
// Zoraxy may intercept error responses and return HTML
|
||||
throw new Error('Unexpected response (status ' + res.status + '). Check plugin is running.');
|
||||
}
|
||||
if (!res.ok) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue