Skip to content

chore: add CSRF middleware for server functions - #9

Merged
seokju-na merged 2 commits into
mainfrom
chore/csrf-middleware
Jul 1, 2026
Merged

seokju-na merged 2 commits into
mainfrom
chore/csrf-middleware

Conversation

@seokju-na

@seokju-na seokju-na commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

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 + lint pass.
  • ✅ 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.

Written for commit 3a6add6. Summary will update on new commits.

Review in cubic

Silence the TanStack Start warning by protecting server-function RPC endpoints
with the recommended CSRF middleware (same-origin check, scoped to serverFn
requests), composed with the existing Sentry middleware.

Low-risk here — the only server function is the read-only docs page loader with
no auth or mutations — but the fix is trivial, follows the framework's
recommendation, and covers any state-changing server function added later.
Verified: build/lint pass, the warning is gone, and docs pages still load.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhaZ2zL7bAqT3c8mRWTSs9
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
webview-bundle-website 3a6add6 Commit Preview URL

Branch Preview URL
Jul 01 2026, 03:39 PM

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/start.ts Outdated
Keep Sentry outermost so it observes the full request, including any CSRF
rejection. Addresses cubic review on #9.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhaZ2zL7bAqT3c8mRWTSs9
@seokju-na
seokju-na merged commit ffb51e6 into main Jul 1, 2026
4 checks passed
@seokju-na
seokju-na deleted the chore/csrf-middleware branch July 1, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant