CSRF
Reject POST and the like from other sites with csrf()
import { , } from "@senrijs/senri";
const = ();
.(());It uses no tokens. It looks at the headers the browser adds and rejects requests from other origins with 403.
What it looks at
For requests other than GET, HEAD and OPTIONS, in this order:
Sec-Fetch-Site: added by the browser. 403 if it is from another originOrigin: for older browsers withoutSec-Fetch-Site, the host ofOriginis compared withHost. The scheme is not compared, so it works behind a proxy that terminates TLS- Requests with neither header are not from a browser (curl, server to server), so they pass
GET and HEAD are not checked, so do not put state-changing work there.
Accept your other sites too
.(({ : ["https://admin.example.com"] }));Pass them to the one csrf() that covers the path. Adding app.use("/api", csrf({ origin })) after app.use(csrf()) does not help: the first csrf() already rejects the request with 403.
If a proxy rewrites Host, also put the right origin in origin.
Options
Prop
Type