checkCsrf
Decides whether a request may change state.
Decides whether a request may change state. Browsers label every request: the decision uses
Sec-Fetch-Site first, then Origin, then Referer, and rejects a request that carries none of
them unless allowMissingOrigin is set. Safe methods (GET, HEAD, OPTIONS) always pass.
A cross-site request passes only when its Origin is a trusted origin.
Import#
ts
import { checkCsrf } from "@shadow-js/dusk/server";
Signature#
ts
function checkCsrf(request: Request, context: CsrfContext): CsrfDecision
Parameters#
| Name | Description |
|---|---|
request |
The request. |
context |
Own origin and the allow-list. |
Returns#
The decision and the reason, for tests and logs.
Examples#
ts
checkCsrf(request, { origin: "https://app.test", trustedOrigins: new Set(), allowMissingOrigin: false });