Skip to main content
HeadersLow PriorityPro

Access-Control-Max-Age

Updated November 2026·SecScanner Team

This header specifies how long browsers can cache preflight request results.

Results in 1–3 minutes · Free · No signup required

Want the result for your own site? Free CORS Checker — paste your domain, get the report.

Why It Matters

Proper caching reduces preflight requests, improving performance. However, overly long cache times can cause issues when CORS policy changes.

How We Check

We verify the max-age value is reasonable (typically 86400 seconds / 24 hours) and consistent across responses.

Good vs Bad Values

Good and bad values for Access-Control-Max-Age
ValueVerdictWhy
Access-Control-Max-Age: 86400Good24 hours. A sensible value; browsers that cap lower (Chromium-based browsers use 2 hours) simply apply their own ceiling.
Access-Control-Max-Age: 7200GoodTwo hours, the longest period Chromium-based browsers honour, so no value is wasted.
Access-Control-Max-Age: 3600GoodOne hour. A good fit when the CORS policy changes often or you deploy several times a day.
Access-Control-Max-Age: 600GoodTen minutes. Short and safe for APIs that tighten policies during incidents, with only a small preflight cost.
Header absent (with Access-Control-Allow-Origin present)BadBrowsers use a default of 5 seconds, so almost every non-simple request is preceded by an extra OPTIONS round trip. The scanner flags it as a performance issue.
Access-Control-Max-Age: 604800WeakExactly seven days passes the scanner, but browsers cap the value anyway, so there is no benefit over 86400 and a policy change takes longer to reach anyone who honours it.
Access-Control-Max-Age: 31536000BadOne year. Long values are capped by browsers and signal that nobody reviewed the policy. Where honoured, a tightened policy would linger in caches.
Access-Control-Max-Age: -1WeakValid in the specification (it disables preflight caching) and useful while debugging, but the scanner treats negative values as invalid, and it multiplies preflight traffic.
Access-Control-Max-Age: 0WeakNo caching of preflight results. Acceptable in tests and wasteful in production.
Access-Control-Max-Age: 86400sWeakThe scanner reads the leading digits, but browsers require an integer and fall back to the default if the value has a unit.

How to Fix

Set Access-Control-Max-Age: 86400 for daily caching. Adjust based on how frequently your CORS policy changes.

Express with cors:

app.use(cors({
  origin: ["https://app.example.com"],
  maxAge: 86400, // seconds
}));

Nginx — in the preflight handler:

if ($request_method = OPTIONS) {
    add_header Access-Control-Allow-Origin "https://app.example.com" always;
    add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
    add_header Access-Control-Allow-Headers "Content-Type, Authorization" always;
    add_header Access-Control-Max-Age 86400 always;
    add_header Vary Origin always;
    return 204;
}

Apache (requires mod_headers):

Header always set Access-Control-Max-Age "86400"

Next.js — in a route handler that answers OPTIONS:

export function OPTIONS() {
  return new Response(null, {
    status: 204,
    headers: {
      "Access-Control-Allow-Origin": "https://app.example.com",
      "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
      "Access-Control-Allow-Headers": "Content-Type, Authorization",
      "Access-Control-Max-Age": "86400",
      "Vary": "Origin",
    },
  });
}

Cloudflare: let your origin or a Worker answer the preflight; a static Transform Rule would attach the header to every response, which is unnecessary but harmless.

Verify with curl -si -X OPTIONS https://api.example.com/items -H 'Origin: https://app.example.com' -H 'Access-Control-Request-Method: POST' | grep -i max-age, and then watch DevTools → Network: the second identical request within the period should show no preflight.

Common Mistakes

  • Believing a larger number means a faster API. Browsers enforce their own ceilings (Chromium 2 hours, Firefox 24 hours), so anything above them is ignored.
  • Setting it on every response. The header is only read from the answer to an `OPTIONS` preflight, so put it in the preflight handler or set it globally in a CORS library.
  • Expecting a high value to remove preflights altogether. The cache key covers URL, origin, method and headers, so each distinct endpoint still needs its own first preflight.
  • Writing a time unit or text (`1d`, `24h`, `86400s`). The value is an integer number of seconds.
  • Reducing it to 0 during an incident and forgetting to restore it, which doubles API requests afterwards.
  • Trying to avoid preflights by loosening the request type instead. If the request is not simple, a preflight is part of the protocol; cache it and move on.

Frequently Asked Questions

What is Access-Control-Max-Age?

This header specifies how long browsers can cache preflight request results.

Why does Access-Control-Max-Age matter for website security?

Proper caching reduces preflight requests, improving performance. However, overly long cache times can cause issues when CORS policy changes.

How do I fix Access-Control-Max-Age issues?

Set Access-Control-Max-Age: 86400 for daily caching. Adjust based on how frequently your CORS policy changes.

Related Security Checks

Related Tool

CORS Checker

Run all 6 related checks with our free cors checker

Check Your Website Now

Run a free security scan to check for Access-Control-Max-Age issues and 61 other security checks.

Scan Your Website Free