diff --git a/src/start.ts b/src/start.ts index ace8d04..d51d7ae 100644 --- a/src/start.ts +++ b/src/start.ts @@ -2,11 +2,19 @@ import { sentryGlobalFunctionMiddleware, sentryGlobalRequestMiddleware, } from '@sentry/tanstackstart-react'; -import { createStart } from '@tanstack/react-start'; +import { createCsrfMiddleware, createStart } from '@tanstack/react-start'; + +// Server functions are same-origin RPC endpoints; reject cross-site requests to +// them (same-origin check via Sec-Fetch-Site / Origin, with a Referer fallback). +const csrfMiddleware = createCsrfMiddleware({ + filter: ctx => ctx.handlerType === 'serverFn', +}); export const startInstance = createStart(() => { return { - requestMiddleware: [sentryGlobalRequestMiddleware], + // Sentry first (outermost) so it observes the whole request, including any + // CSRF rejection raised by the middleware after it. + requestMiddleware: [sentryGlobalRequestMiddleware, csrfMiddleware], functionMiddleware: [sentryGlobalFunctionMiddleware], }; });