SimpleCsrfProtectionHandlerPlugin adds basic CSRF protection to your oRPC server. It ensures requests originate from JavaScript code rather than native browser form submissions or direct navigation.
How it works
The plugin checks for a custom header (x-csrf-token: orpc by default) on every request. Native browser form submissions and direct URL navigation cannot set custom headers, so they are blocked. JavaScript fetch() calls can set this header freely.
This is a lightweight “is this from JavaScript?” check, not a full token-based CSRF system. It is sufficient for API endpoints consumed exclusively by JavaScript clients.
Usage
x-csrf-token: orpc header when using the standard RPCLink.
Options
The header name to check.
The expected header value.
Exclude specific procedures from CSRF protection. Useful for webhooks or public health-check endpoints.
The error thrown when the CSRF token is invalid.Default:
new ORPCError('CSRF_TOKEN_MISMATCH', { status: 403, message: 'Invalid CSRF token' })