chore: add CSRF middleware for server functions
Adds the recommended CSRF middleware to src/start.ts to silence the TanStack Start warning:
TanStack Start server functions are not protected by the CSRF middleware.
const csrfMiddleware = createCsrfMiddleware({
filter: ctx => ctx.handlerType === 'serverFn',
});
// composed with the existing Sentry request/function middleware
Is it actually needed?
For this site the risk is low ā the only server function is the read-only docs page loader (no auth, no mutations, no user state), so a forged cross-site request could only fetch public docs. But the fix is one line, it's the framework's recommended default, and it protects any state-changing server function added later. So: worth doing to resolve the warning properly rather than suppressing it.
The middleware validates same-origin (Sec-Fetch-Site / Origin, with a Referer fallback) only for serverFn requests; legitimate same-origin calls pass unchanged.
Verified
- ā
build+lintpass. - ā The CSRF warning no longer appears.
- ā Docs pages still load (the server function works under the middleware).
š¤ Generated with Claude Code
https://claude.ai/code/session_01HhaZ2zL7bAqT3c8mRWTSs9
Summary by cubic
Add CSRF middleware for TanStack Start server functions to block cross-site calls and remove the framework warning. Uses createCsrfMiddleware from @tanstack/react-start, scoped to serverFn requests and composed after the Sentry request middleware so Sentry sees any CSRF rejections.