CORS Header Checker

Understand Cross-Origin Resource Sharing (CORS), build CORS policies interactively, and generate server configurations. Learn how preflight requests work and debug common CORS errors with the reference guide below.

CORS Policy Builder


Generated Headers

Nginx Configuration

Express.js (Node.js)

Apache (.htaccess)

CORS Header Checker
Figure 1 — CORS Header Checker

What Is CORS?

Cross-Origin Resource Sharing (CORS) is a security mechanism that allows or restricts web pages from making requests to a different domain than the one that served the page. By default, browsers block cross-origin requests (the Same-Origin Policy). CORS headers tell the browser which cross-origin requests are permitted.

CORS is fundamental to modern web development, where frontends and APIs often live on different domains. It is also relevant for network tools — if you are building a dashboard that queries your router's API from a different origin, or using a DNS lookup service, CORS policies determine whether those requests succeed.

CORS Headers Reference

Here is a complete reference of all CORS-related HTTP headers:

HeaderDirectionPurposeExample Value
Access-Control-Allow-OriginResponseWhich origins can access the resourcehttps://example.com or *
Access-Control-Allow-MethodsResponseWhich HTTP methods are allowedGET, POST, PUT, DELETE
Access-Control-Allow-HeadersResponseWhich request headers are allowedContent-Type, Authorization
Access-Control-Max-AgeResponseHow long to cache preflight results86400 (24 hours)
Access-Control-Allow-CredentialsResponseWhether cookies/auth are includedtrue
Access-Control-Expose-HeadersResponseWhich response headers JS can readX-Request-Id, X-Total-Count
OriginRequestThe requesting page's originhttps://myapp.com
Access-Control-Request-MethodRequest (preflight)The method the actual request will useDELETE
Access-Control-Request-HeadersRequest (preflight)Headers the actual request will sendAuthorization

Pro Tip: Never use Access-Control-Allow-Origin: * with Access-Control-Allow-Credentials: true — browsers reject this combination for security reasons. If you need credentials, you must specify the exact origin. Use dynamic origin checking on the server to support multiple origins with credentials. For APIs behind your port-forwarded server, always use specific origins.

How Preflight Requests Work

When a cross-origin request uses methods other than GET/POST or includes custom headers, the browser sends a preflight OPTIONS request first. Understanding this flow is critical for debugging CORS issues:

StepWhat HappensWho Initiates
1. Simple request checkBrowser checks if the request qualifies as "simple" (GET/POST with standard headers)Browser
2. Preflight sentIf not simple, browser sends OPTIONS request with CORS request headersBrowser (automatic)
3. Server respondsServer returns CORS response headers indicating what is allowedServer
4. Preflight cachedBrowser caches the preflight response for Access-Control-Max-Age secondsBrowser
5. Actual requestIf preflight approved, browser sends the actual requestBrowser
6. Response checkedBrowser verifies response headers match preflight approvalBrowser

Common CORS Errors and Fixes

CORS errors are among the most confusing issues in web development. Here are the most common ones and how to fix them:

Error: No Access-Control-Allow-Origin header

# Error message:
# "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header
# is present on the requested resource."

# Fix: Add the header to your server response
# Nginx:
add_header 'Access-Control-Allow-Origin' 'https://yourapp.com' always;

Error: Wildcard origin with credentials

# Error message:
# "The value of the 'Access-Control-Allow-Origin' header must not be '*'
# when the request's credentials mode is 'include'."

# Fix: Use specific origin instead of wildcard
add_header 'Access-Control-Allow-Origin' $http_origin always;
add_header 'Access-Control-Allow-Credentials' 'true' always;

Error: Method not allowed

# Error message:
# "Method DELETE is not allowed by Access-Control-Allow-Methods"

# Fix: Include the method in allowed methods
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;

For a comprehensive security setup, combine proper CORS with other security headers like CSP and HSTS. Also ensure your API authentication is properly configured.

Note: CORS is enforced by the browser, not the server. Server-side requests (like those from a Node.js backend) are not subject to CORS restrictions. If you are making API calls from your server rather than a browser, CORS headers are irrelevant. However, if your server acts as a reverse proxy for browser clients, you still need to set CORS headers on the proxy response.

CORS Security Best Practices

Misconfigured CORS can expose your API to cross-origin attacks. Follow these guidelines to balance functionality with security, much like how you balance convenience and security on your home network:

  1. Never use wildcard (*) with credentials — Specify exact origins when authentication is involved.
  2. Validate origins server-side — Do not simply reflect the Origin header. Maintain a whitelist of allowed origins.
  3. Minimize allowed methods — Only allow the HTTP methods your API actually uses.
  4. Restrict allowed headers — Only permit headers your API expects.
  5. Use long max-age for caching — Reduce preflight request overhead by caching results (86400 seconds is standard).
  6. Combine with authentication — CORS alone does not replace proper authentication. Use strong API keys or OAuth tokens.
  7. Monitor CORS errors — Log blocked CORS requests to detect misconfigurations or attack attempts.

CORS vs CSP: Understanding the Difference

CORS and Content Security Policy (CSP) are often confused, but they serve different purposes. Understanding both is essential for web security:

FeatureCORSCSP
DirectionControls incoming requests to your serverControls outgoing requests from your page
Enforced byBrowser + server headersBrowser from server-sent policy
PurposeAllow/block cross-origin API accessPrevent XSS and resource injection
ConfigurationServer response headersServer response header or meta tag
ScopeFetch/XHR/API requestsAll page resources (scripts, styles, images, etc.)

For complete web security, configure both CORS and CSP. See our HTTP Headers Checker and Mixed Content Checker for complementary security tools.

Key Takeaways
  • CORS controls which origins can access your server's resources from a browser context.
  • Preflight OPTIONS requests are sent automatically for non-simple cross-origin requests.
  • Never use wildcard origins with credentials — always specify exact allowed origins.
  • Set Access-Control-Max-Age to cache preflight results and reduce request overhead.
  • CORS is browser-enforced — server-to-server requests are not affected by CORS policies.
  • Combine CORS with CSP and other security headers for comprehensive protection.

Video: CORS Explained

Related Guides

Frequently Asked Questions

Why do I get CORS errors only in the browser?

CORS is a browser security mechanism. When you make the same request from Postman, curl, or a server-side script, there is no CORS check because there is no browser to enforce it. The browser adds the Origin header and enforces the Same-Origin Policy; other HTTP clients do not.

Can I disable CORS in the browser?

You can disable CORS for development using browser flags or extensions, but this is dangerous for security and should never be done in production. The proper fix is always to configure correct CORS headers on your server.

Why does my preflight request fail?

The most common cause is the server not handling OPTIONS requests. Many frameworks route OPTIONS to a 404 by default. Ensure your server returns a 204 response to OPTIONS requests with the correct CORS headers. Check that your server is not requiring authentication for OPTIONS requests.

What is a "simple request" in CORS?

A simple request uses only GET, HEAD, or POST methods with standard headers (Accept, Content-Type with form values, Content-Language). Simple requests do not trigger a preflight — the browser sends them directly and checks CORS headers on the response. Any other combination triggers a preflight.

Should I use Access-Control-Allow-Origin: * for my public API?

For truly public APIs that do not use cookies or authentication, wildcard (*) is acceptable. However, if your API uses any form of authentication (API keys in headers, session cookies), you must use specific origins. Even for public APIs, consider using specific origins for better security.

How do I handle CORS with a reverse proxy?

If your reverse proxy (Nginx, Apache) sits in front of your application, you can add CORS headers at the proxy level instead of in your application code. This centralizes CORS configuration. However, ensure you are not duplicating headers — having the same header set twice can cause issues.

Does CORS protect my API from abuse?

No. CORS only prevents browser-based cross-origin requests. Attackers can bypass CORS entirely using curl, Postman, or any non-browser HTTP client. Always implement proper authentication, rate limiting, and input validation regardless of CORS settings. Use strong API credentials for all protected endpoints.

About Tommy N.

Tommy is the founder of RouterHax and a network engineer with 10+ years of experience in home and enterprise networking. He specializes in router configuration, WiFi optimization, and network security. When not writing guides, he's testing the latest mesh WiFi systems and helping readers troubleshoot their home networks.

Promotion for FREE Gifts. Moreover, Free Items here. Disable Ad Blocker to get them all.

Once done, hit any button as below