Cross-Origin Access Control

CORS Header Generator

Build Cross-Origin Resource Sharing headers for your API. Configure allowed origins, methods, credentials, and cache settings. Read the guide.

Access-Control-Allow-Origin

Which origins can access your resources

Weak

Wildcard origin (*) allows any website to read your API responses.

Any website can make cross-origin requests to your API and read the response. This is the most permissive setting and appropriate only for fully public APIs with no authentication.

Access-Control-Allow-Methods

HTTP methods allowed for cross-origin requests

Standard read and submit methods. GET and POST are the most common for APIs. OPTIONS is needed for preflight requests.

Access-Control-Allow-Headers

Request headers the client is allowed to send

Authorization header is included. Make sure your API validates tokens on every request, since cross-origin callers can now send auth credentials.

Access-Control-Allow-Credentials

Allow cookies and auth headers in cross-origin requests

Cross-origin requests will not include cookies or auth headers. This is safer but means the API cannot identify users via session cookies from other origins.

Access-Control-Max-Age

How long to cache preflight results (seconds)

Preflight results cached for 1 day(s). Good for stable APIs where allowed methods and headers rarely change.

Access-Control-Expose-Headers

Response headers the client JavaScript can access (optional)

No extra headers are exposed. The browser only lets cross-origin JavaScript read the default safe headers (Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma).

CORS Strength
Weak
Generated Headers
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 86400

Understanding CORS

Why CORS exists

Browsers enforce the same-origin policy by default, which means JavaScript on one domain cannot read responses from another domain. CORS relaxes this restriction in a controlled way. Without it, any website could silently call your API using the visitor's cookies and read the response. CORS headers let your server declare exactly which origins are trusted. For a detailed walkthrough, see our CORS guide.

Common pitfalls

The most frequent mistakes are using * with credentials (browsers will block it), forgetting to handle the OPTIONS preflight method, and not varying the Vary: Origin header when dynamically setting the origin. Test your CORS setup with browser DevTools and watch for blocked requests in the Console and Network tabs.

Frequently Asked Questions

What is CORS?

Cross-Origin Resource Sharing (CORS) is a browser mechanism that lets servers declare which origins can access their resources. Without CORS headers, browsers block JavaScript from reading responses to cross-origin requests. CORS protects users by preventing malicious sites from silently calling your API with their cookies.

When do I need CORS headers?

You need CORS headers whenever client-side JavaScript on one domain makes requests to an API on a different domain. Common examples include a React frontend on localhost calling an API on api.example.com, or a single-page app hosted on a CDN talking to your backend. Same-origin requests do not need CORS.

What is a preflight request?

A preflight is an automatic OPTIONS request the browser sends before the actual request when it uses methods like PUT, DELETE, or PATCH, or when it includes custom headers. The server must respond with the correct CORS headers to allow the real request to proceed. The Access-Control-Max-Age header controls how long preflight results are cached.

Why can I not use wildcard (*) with credentials?

When Access-Control-Allow-Credentials is true, the browser requires the server to echo back the exact requesting origin instead of *. This prevents malicious sites from using the wildcard to send authenticated requests on behalf of users. You must specify the allowed origin explicitly.

Is Access-Control-Allow-Origin: * dangerous?

For public APIs that serve only non-sensitive, read-only data, wildcard is acceptable. However, if your API returns private data or accepts mutations, wildcard means any website can call it. Always pair wildcard with no credentials and read-only methods, or switch to a specific origin list.

How do I allow multiple origins?

The CORS spec only allows a single origin value per response. To support multiple origins, your server must check the incoming Origin header against an allowlist and dynamically set Access-Control-Allow-Origin to the matching origin. Most CORS middleware libraries handle this automatically.

Confirm your CORS headers are live

After deploying your CORS configuration, scan your site to verify the headers are being served correctly and check the rest of your security headers at the same time.

Scan your website