fix: attach CSRF token to state-changing requests
ci / docker (push) Successful in 5m20s

This commit is contained in:
2026-09-05 17:33:30 +08:00
parent 0dff033a7f
commit 799b522f9b
7 changed files with 391 additions and 5 deletions
+8 -1
View File
@@ -6,6 +6,7 @@ import {
Settings, Trash2, X, CalendarRange, Repeat2,
} from 'lucide-vue-next'
import { filterTasks, fromDateTimeLocal, groupTaskTree, renderMarkdown, toDateTimeLocal } from './lib/task-utils'
import { csrfHeader } from './lib/csrf'
import MvpPanel from './MvpPanel.vue'
type FolderItem = { id: string; name: string }
@@ -77,9 +78,15 @@ watch(showCompleted, () => {
})
async function api(path: string, options: RequestInit = {}) {
const headers = new Headers(options.headers || {})
if (!headers.has('Content-Type') && options.body && !(options.body instanceof FormData)) {
headers.set('Content-Type', 'application/json')
}
const csrf = csrfHeader(options.method)
if (csrf['x-csrf-token']) headers.set('x-csrf-token', csrf['x-csrf-token'])
const response = await fetch('/api/v1' + path, {
credentials: 'include',
headers: { 'Content-Type': 'application/json', ...(options.headers || {}) },
headers,
...options,
})
if (!response.ok) {