tududi/frontend/components/Sidebar
Chris 6c9902b584
fix: add CSRF token support to frontend requests (#1025)
This commit implements CSRF token support for all session-based API
requests to fix the "CSRF token missing" and "CSRF token mismatch" errors
introduced after CSRF protection was added in commit 62c4cc84.

Changes:
- Created csrfService.ts utility for fetching and caching CSRF tokens
- Added getPostHeadersWithCsrf() helper to authUtils for async token injection
- Updated all service files (*Service.ts) to include CSRF tokens in POST/PUT/PATCH/DELETE requests
- Updated components with inline fetch calls to use getCsrfToken()
- Fixed CSRF middleware to use single lusca instance instead of creating new instances per request
- Improved generateToken() to use req.csrfToken() when available
- Added CalDAV path exemption to CSRF protection

Technical details:
- CSRF tokens are fetched from /api/csrf-token endpoint
- Tokens are cached and reused across requests to avoid unnecessary fetches
- Tokens are included in x-csrf-token header for state-changing requests
- Public endpoints (login, register) remain exempt from CSRF protection
- Bearer token authentication remains exempt from CSRF protection

Files modified:
- Backend: app.js, middleware/csrf.js
- Frontend: 13 service files, 8 component files
- New file: frontend/utils/csrfService.ts

This ensures all session-based requests properly include CSRF tokens while
maintaining support for API token authentication.
2026-04-14 15:06:56 +03:00
..
SidebarAreas.tsx Tweak playwright options (#303) 2025-09-09 12:53:40 +03:00
SidebarFooter.tsx Add custom keyboard shortcuts (#749) 2025-12-28 21:58:21 +02:00
SidebarHabits.tsx Feat: habits (#707) 2025-12-13 08:47:52 +02:00
SidebarHeader.tsx Fix static base path (#549) 2025-11-16 22:43:06 +02:00
SidebarNav.tsx feat: Add MCP Integration with client-agnostic instructions (#953) 2026-03-20 16:55:49 +02:00
SidebarNotes.tsx Fix sidebar active links highlight (#632) 2025-12-02 22:45:50 +02:00
SidebarProjects.tsx Feat/add project states (#354) 2025-09-29 16:04:25 +03:00
SidebarTags.tsx Tweak playwright options (#303) 2025-09-09 12:53:40 +03:00
SidebarViews.tsx fix: add CSRF token support to frontend requests (#1025) 2026-04-14 15:06:56 +03:00