How to fix: CORS preflight result not cached
Missing Access-Control-Max-Age forces browsers to send preflight OPTIONS on every cross-origin request.
Why it matters
Without preflight caching, every cross-origin API call from browser clients triggers an extra OPTIONS round-trip, doubling perceived latency for API consumers and increasing server load under heavy traffic.
Missing Access-Control-Max-Age forces browsers to send preflight OPTIONS on every cross-origin request.
How to fix it
- 1Add Access-Control-Max-Age: 600 (10 minutes) for stable CORS configs
- 2Do not set it above 86400 (24 hours); a stale policy can block legitimate requests after a config change
Code examples
Express cors(): set max age
import cors from 'cors';
app.use(cors({
origin: ['https://app.example.com'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Authorization', 'Content-Type'],
maxAge: 600,
}));Nginx: CORS preflight with max age
location /api/ {
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin 'https://app.example.com';
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE';
add_header Access-Control-Allow-Headers 'Authorization, Content-Type';
add_header Access-Control-Max-Age 600;
return 204;
}
}References
Detected automatically by VulnRadar. The check id is api-cors-preflight-cache-missing, stable across every scan so you can filter or diff on it.
More api checks
- LowTRACE method referenced in API response body
- InfoREST endpoint allows DELETE
- LowGraphQL introspection field suggestions
- MediumGraphQL endpoint has no rate-limit headers
- LowOpenAPI server URL leaks internal host
- HighBearer token in URL query string
- MediumJSONP callback parameter accepted
- InfoPUT method listed in Allow header
Questions
- How severe is CORS preflight result not cached?
- VulnRadar rates this low severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id api-cors-preflight-cache-missing, which stays the same between runs so you can filter, diff, or gate CI on it.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.