Skip to content
oRPC
Esc
navigateopen⌘Jpreview
On this page

Simple CSRF Protection Plugin

Use SimpleCsrfProtectionHandlerPlugin to add a first line of defense against Cross-Site Request Forgery (CSRF) attacks by rejecting requests with unsafe fetch modes.

How It Works

The plugin inspects the Sec-Fetch-Mode header and blocks requests with a mode of navigate, no-cors, or websocket, which may be triggered by cross-site links, forms, or other passive browser features.

Setup

import { OpenAPIHandler } from '@orpc/openapi/fetch'
import { SimpleCsrfProtectionHandlerPlugin } from '@orpc/server/plugins'

const handler = new OpenAPIHandler(router, {
  plugins: [
    new SimpleCsrfProtectionHandlerPlugin(),
  ],
})

Learn More

For implementation details, see the source code.

Last updated on August 6, 2026

Was this page helpful?