npm install @ferrow/cors-config-builderCORS policy engine with origin matching, preflight handling, and footgun prevention.
import CORSBuilder from "cors-config-builder";
const cors = new CORSBuilder({
origins: ["https://app.example.com", /^https:\/\/[\w-]+\.example\.com$/],
methods: ["GET", "POST"],
headers: ["Content-Type"],
credentials: true,
maxAge: 3600,
});
const response = cors.evaluate(request.origin, request.method);
// → { allowed: true, headers: { "Access-Control-Allow-Origin": "..." } }Accepts partial config; throws if credentials=true and origins=["*"] (security footgun).
Returns { allowed: boolean, headers: Record<string, string> } for preflight (OPTIONS) or regular requests.
- No actual middleware/interceptor binding (headers evaluation only)
- Credentials + wildcard-origin error prevents misconfiguration
Part of the ferrow-toolkit collection · Sponsored by Ferrow