CORS Response Header Generator

Dynamically generate correct Access-Control-Allow-* headers based on your origin, methods, headers, and credentials. Preview preflight (OPTIONS) requirements and security best practices. For developers, architects, and security engineers.

Specific origin (with protocol, port) or * (wildcard). Credentials cannot be used with *.
* https://myapp.com http://localhost:3000 https://api.myapp.com
Preflight cache duration. Recommended 7200 (2 hours). Negative values will be set to 0.
GET HEAD POST PUT DELETE PATCH OPTIONS
Click to toggle selection. At least one required.
Comma-separated, case-insensitive. Used in preflight Access-Control-Allow-Headers.
Frontend must use credentials: 'include' or withCredentials: true. Origin cannot be *.
Advanced — custom preflight & extra exposure
Privacy first: All processing happens locally in your browser. No data leaves your device.

Server Configuration Examples

Use these snippets with the generated headers above. Click any to copy.

Express.js middleware
// Enable CORS for specific routes
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', 'https://yourdomain.com');
  res.header('Access-Control-Allow-Methods', 'GET, POST, PUT');
  res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
  res.header('Access-Control-Max-Age', '7200');
  if (req.method === 'OPTIONS') {
    return res.sendStatus(204);
  }
  next();
});
Nginx location block
location /api {
    add_header Access-Control-Allow-Origin "https://frontend.com";
    add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
    add_header Access-Control-Allow-Headers "Authorization, Content-Type";
    add_header Access-Control-Max-Age 7200;
    
    if ($request_method = OPTIONS) {
        return 204;
    }
}
Apache .htaccess
Header set Access-Control-Allow-Origin "https://app.example.com"
Header set Access-Control-Allow-Methods "GET, POST, PUT"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
Header set Access-Control-Max-Age "7200"
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule .* - [R=204,L]
Spring Boot @Configuration
@Configuration
public class CorsConfig {
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                    .allowedOrigins("https://frontend.com")
                    .allowedMethods("GET", "POST", "PUT")
                    .allowedHeaders("Authorization", "Content-Type")
                    .maxAge(7200);
            }
        };
    }
}

What Developers Say

"This generator saved me hours of debugging CORS issues. The preflight preview and security notes are spot-on."
— Sarah Chen, Senior Frontend Architect
"I use this tool in every API project. The framework examples make it easy to explain to junior devs."
— Marcus Webb, Lead Backend Engineer

What is CORS and why precise configuration matters?

Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows browsers to request resources from a different origin (protocol+domain+port). It is the cornerstone of modern web security — without CORS, the default same-origin policy would block most cross-origin requests. However, misconfiguration (e.g., overly permissive * or unintended credentials exposure) can lead to serious vulnerabilities like data leakage or CSRF-style attacks.

A typical CORS preflight request/response flow:

OPTIONS /resource HTTP/1.1
Origin: https://client.com
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: X-Custom

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://client.com
Access-Control-Allow-Methods: PUT, POST
Access-Control-Allow-Headers: X-Custom
Access-Control-Max-Age: 7200

Why use a CORS header generator?

  • Eliminate guesswork – Manually crafting CORS headers often leads to errors (missing preflight, malformed headers).
  • Educational & audit – Clearly see which headers are required and when preflight is triggered.
  • Security baseline – The generator automatically flags dangerous combinations (e.g., * + credentials).
  • Rapid prototyping – Paste the generated headers directly into your backend configuration (Nginx, Apache, Express, etc.).

Core CORS response headers explained

Header Purpose Typical value
Access-Control-Allow-Origin Specifies which origins are permitted. https://example.com or *
Access-Control-Allow-Methods Lists HTTP methods allowed for cross-origin requests (used in preflight). GET, POST, PUT
Access-Control-Allow-Headers Indicates which headers can be used in the actual request. Content-Type, Authorization
Access-Control-Allow-Credentials Whether cookies/authorization credentials are allowed. true (only if origin is not *)
Access-Control-Expose-Headers Which response headers the browser can expose to frontend JavaScript. Content-Length, X-Custom
Access-Control-Max-Age How long preflight results can be cached (seconds). 7200
Security alert: Wildcard * is convenient, but it cannot be used with credentials and may be too permissive for production. Always restrict to specific origins when possible. Avoid blindly adding * in Access-Control-Allow-Headers (some browsers don't support it).

Real‑world case: React SPA calling a REST API

Scenario: React frontend on https://app.example.com, backend API on https://api.example.org

The frontend needs to send requests with an Authorization: Bearer <JWT> header. The CORS configuration would be:

  • Access-Control-Allow-Origin: https://app.example.com (exact origin, not wildcard)
  • Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
  • Access-Control-Allow-Headers: Content-Type, Authorization
  • Access-Control-Allow-Credentials: false (since token is in header, not cookies; keeping it false reduces risk)
  • Access-Control-Expose-Headers: X-Request-ID (if you want the frontend to read a custom correlation ID)

Our generator lets you input these values and instantly produces the exact headers to set in your server (e.g., Express middleware, Nginx add_header).

When does a preflight (OPTIONS) occur?

Not all cross-origin requests trigger a preflight. Simple requests (GET/HEAD/POST with only safe headers) skip it. Preflight is mandatory when:

  • HTTP method is PUT, DELETE, PATCH, or others beyond GET/HEAD/POST;
  • Request includes custom headers (e.g., Authorization, X-*);
  • Content-Type is not one of: application/x-www-form-urlencoded, multipart/form-data, text/plain (e.g., application/json);
  • Credentials mode is set to include and origin is not *.

Authoritative references & standards

Maintained by GetZenQuery Tech Team – Our team of five senior engineers (with backgrounds in API security, browser internals, and cloud architecture) ensures this tool stays aligned with the latest specifications. We monitor WHATWG Fetch, MDN, and OWASP recommendations to provide accurate, up-to-date guidance. The tool is used internally at GetZenQuery and has been validated against real-world scenarios since 2024.

v2.1.0 · 1,200+ GitHub stars · Reviewed March 2026

Frequently Asked Questions

No. The specification forbids using wildcard (*) together with credentials. The origin must be explicit (e.g., https://example.com). The generator will warn you if such a combination is detected.

Allow-Headers tells the server which request headers the client is permitted to send. Expose-Headers tells the browser which response headers it can make accessible to frontend JavaScript (by default only simple response headers are exposed).

It is not required but often included. The preflight response itself is an OPTIONS request; including OPTIONS in the method list has no negative effect and may improve compatibility.

When using a dynamic origin (not *), we recommend adding Vary: Origin to your server configuration to avoid cache issues. The generated headers do not include it automatically, but our production checklist reminds you.