/** * Origin-header CSRF protection for non-preflighted POSTs and other state-mutating verbs. A cross-origin request reaches * the server without a CORS preflight only when its Content-Type is `application/x-www-form-urlencoded`, * `multipart/form-data`, `text/plain`, or missing, so those are the cases gated here; browsers always send `Origin` on a * non-GET cross-origin request, making the comparison sufficient. * * Production refuses every protected form submission until `proxy.origin` or `proxy.hostHeader` tells the framework what * origin to trust. Development logs a `logger.warn` line instead and lets the request through, so callers pass * `development` explicitly rather than leaving prod-vs-dev intent implicit. * * Limitations: * - Some legacy clients and privacy proxies strip `Origin` and will be rejected; * allow-list them via `trustedOrigins`. * - JSON/octet-stream endpoints (`Mochi.api(...)`) go unchecked, since the browser * already requires a CORS preflight to send those cross-origin. */ import { applyFilter } from '../extensions'; import { logger } from '../utils/log'; import { resolveExpectedOrigin, type MochiProxyOptions } from './proxy'; /** The three types a cross-origin `