CORS Policy Builder
Build Access-Control-* response headers and an nginx config that follow the Fetch standard. Nothing leaves your browser.
Allowed origins
one per lineGenerated policy
Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 86400
Vary: OriginExamples
Single-origin API with auth and preflight caching
Origins: https://app.example.com
Methods: GET, POST, OPTIONS
Request headers: Content-Type, Authorization
Expose headers: (empty)
Credentials: on
Max-Age: 86400Headers:
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Expose-Headers:
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 86400Even with credentials on, a single explicit origin is safe to echo back. The empty Access-Control-Expose-Headers line is intentional — the browser will not allow any extra response headers to be read by JS.
Multi-tenant API with credentials and three origins
Origins:
https://a.example.com
https://b.example.com
https://c.example.com
Methods: GET, POST, PUT, DELETE, OPTIONS
Request headers: Content-Type, Authorization, X-Request-Id
Expose headers: X-Request-Id, X-RateLimit-Remaining
Credentials: on
Max-Age: 3600Headers:
Access-Control-Allow-Origin: <request-origin>
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization, X-Request-Id
Access-Control-Expose-Headers: X-Request-Id, X-RateLimit-Remaining
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 3600
Nginx:
add_header Access-Control-Allow-Origin "$http_origin" always;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
add_header Access-Control-Allow-Headers "Content-Type, Authorization, X-Request-Id" always;
add_header Access-Control-Expose-Headers "X-Request-Id, X-RateLimit-Remaining" always;
add_header Access-Control-Allow-Credentials "true" always;
add_header Access-Control-Max-Age "3600" always;Multiple origins trigger the dynamic mode. The header placeholder (<request-origin>) and the Nginx directive ($http_origin) must be validated against a server-side allowlist; do not echo the Origin header verbatim.
Public read-only API with no credentials
Origins: *
Methods: GET, OPTIONS
Request headers: Content-Type
Expose headers: (empty)
Credentials: off
Max-Age: 86400Headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Expose-Headers:
Access-Control-Allow-Credentials: false
Access-Control-Max-Age: 86400
fetch example:
fetch("https://example.com/api/resource", {
method: "GET",
mode: "cors",
credentials: "omit",
headers: {
"Content-Type": "<value>"
},
})
.then((response) => response.json())
.then((data) => console.log(data))With credentials off, * is a valid Access-Control-Allow-Origin value. The fetch example uses credentials: 'omit' to match the chosen policy.
Use cases
Configuring a single-origin API
Document the exact Access-Control headers your frontend needs and ship the matching Nginx or Express snippet so the server block and the frontend code stay in sync.
Hardening a multi-tenant API
Multiple origins with credentials need a dynamic origin echo backed by a server-side allowlist. Use the generated $http_origin placeholder together with a custom validator in Nginx or your application layer.
Documenting a public read-only endpoint
A CDN-backed, public, read-only API can ship Access-Control-Allow-Origin: * with no credentials. The Headers tab gives you a copy-paste block for the spec.
Bootstrapping a new frontend client
Use the fetch example to seed a typed API client — the method, mode, credentials, and header names are filled in from the policy so the first request cannot be blocked by a missing preflight response.
Common mistakes
Mistake:Returning Access-Control-Allow-Origin: * together with Access-Control-Allow-Credentials: true.
Fix:The browser blocks the response. With credentials enabled, switch to a single explicit origin or echo the request Origin after validating it against a server-side allowlist.
Mistake:Listing every origin in Access-Control-Allow-Origin as a comma-separated value.
Fix:The header takes a single origin or *. Echo the request Origin header from a server-side allowlist when you need multiple origins with credentials.
Mistake:Forgetting to handle the OPTIONS preflight on the same route.
Fix:Preflight requests are issued against the same URL as the real request. Apply the CORS headers to both the real route and its OPTIONS handler, or use a middleware that short-circuits OPTIONS to 204.
Mistake:Setting Access-Control-Max-Age too short or too long.
Fix:Pick a value that matches how often your policy changes. 600 (10 min) is a safe default while iterating; 86400 (24 h) is fine for a stable policy. Anything past 86400 is clamped by most browsers.
Mistake:Trusting the generated example to be a complete CORS implementation.
Fix:The builder is a documentation aid. You still need to validate the dynamic origin server-side and to apply the policy to every route that the browser may preflight.
Frequently asked questions
What can this CORS builder generate?
It builds response headers, matching Nginx directives, and a JavaScript fetch example for the selected cross-origin policy.
Why is a preflight request important?
Browsers send an OPTIONS preflight for many non-simple cross-origin requests. The generated policy includes the methods and headers needed to answer it.
Should I allow every origin with a wildcard?
Usually no. Restrict Access-Control-Allow-Origin to trusted origins, especially when credentials or private data are involved.
Related guides
References & standards
Related tools
AES Encryption
Encrypt and decrypt text with AES-GCM and a passphrase, fully in your browser. Uses PBKDF2 key derivation and the Web Crypto API — your data and keys never leave your device.
Android Network Security Config Builder
Generate network_security_config.xml with cleartext rules, trust anchors, certificate pinning and debug-only CAs — plus the manifest snippet and file placement checklist.
Ansible Vault Encrypt/Decrypt
Encrypt secrets into $ANSIBLE_VAULT;1.1;AES256 format or decrypt vault content with its password — locally in your browser, drop-in compatible with ansible-vault.
Argon2 Hash Generator & Verifier
Generate Argon2id/2i/2d hashes with proper m/t/p parameters and verify PHC strings — reference algorithm in your browser, nothing uploaded.
AWS Signature V4 Builder
Build AWS Signature V4 headers and presigned URLs from a canonical request — signed curl, key chain and debug diff, computed locally in your browser.
Basic Auth Generator
Generate an HTTP Basic Authentication header from a username and password. Produces the Authorization header and ready-to-use curl and fetch snippets. Runs fully client-side.