fix(ocr): send CSRF token when starting an OCR run #705
Reference in New Issue
Block a user
Delete Branch "fix/ocr-trigger-csrf"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Starting an OCR run failed with "Sitzungsfehler. Bitte laden Sie die Seite neu."
Root cause
createOcrJob(frontend/src/lib/ocr/useOcrJob.svelte.ts) defaulted itsfetchImplto barefetch. The document page instantiates it without afetchImpl, so the OCR triggerPOST /api/documents/{id}/ocrcarried noX-XSRF-TOKENheader. Spring Security's CSRF filter rejected it, returningCSRF_TOKEN_MISSING, which maps to the German "Sitzungsfehler…" message.This was the one remaining mutating client call still on bare
fetch— the transcription autosave hook (useBlockAutoSave) already usedcsrfFetch.Fix
Default the controller's
fetchImpltocsrfFetch. It injects the token only on mutating methods (POST/PUT/PATCH/DELETE) and passes GET polling (/ocr/jobs/{id},/ocr-status) through unchanged. Injected test mocks are unaffected.Test
Added a failing-first test asserting the trigger POST carries
X-XSRF-TOKENon the default (no-fetchImpl) path. All 23 tests in the file pass; prettier + eslint clean.🤖 Generated with Claude Code