Permissive CORS
Access-Control-Allow-Origin: *, cors() with no config, origin: true
warningSecurity
cors-configSeverity depends on context. Critical when the wildcard comes with credentials.
Why this matters
A wildcard CORS policy lets any website make authenticated requests to your API. This enables CSRF-style attacks where a malicious site can read your users' data.
Example
app/api/data/route.tsexport async function GET(req: Request) {
return new Response(JSON.stringify(data), {
headers: {
"Access-Control-Allow-Origin": "*",
},
});
}app/api/data/route.tsconst ALLOWED_ORIGINS = [
"https://myapp.com",
"https://staging.myapp.com",
];
export async function GET(req: Request) {
const origin = req.headers.get("origin") ?? "";
const cors = ALLOWED_ORIGINS.includes(origin)
? origin : "";
return new Response(JSON.stringify(data), {
headers: {
"Access-Control-Allow-Origin": cors,
},
});
}How to fix
Replace wildcard '*' with an explicit allowlist of trusted origins. Validate the Origin header against the list on every request.
Reference
- In the output
- Findings carry
"ruleId": "cors-config"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line cors-config- Silence a whole file
// prodlint-disable cors-configat the top of the file- How it works
- Matches text patterns. Source on GitHub