Unify Logo Footer.svg
API Manager
Logo
CORS Policy

CORS Policy

Logo

4 mins READ

Control which origins (domains) can access your APIs from a browser, defining allowed methods, headers, and preflight caching behavior.

Overview

CORS Policy controls how resources on your API can be accessed from different origins (domains). It defines which external clients are allowed to interact with your APIs and what types of requests they can make — enforcing security by restricting unauthorized cross-origin access while enabling trusted domains to communicate with your backend services.

cors-2.png
cors-2.png

Field Reference

Field

Description

Policy Name *

A unique identifier used across logs, dashboards, and API group configurations.

Tags

Custom labels to organize and filter the policy by environment, team, or functionality.

Allowed HTTP Protocol *

The HTTP protocol version permitted for cross-origin requests (e.g., HTTP/1.1, HTTP/2).

Allowed Methods

HTTP methods permitted for cross-origin requests (e.g., GET, POST, PUT, DELETE). If not specified, all methods are allowed.

Allowed Origins

Domains permitted to access the API. Accepts explicit domains or regex patterns (prefix with ~). If not specified, all origins are allowed.

Require Origin Header

When enabled, requests without an Origin header are rejected.

Allowed Headers

Request headers that clients may include in cross-origin requests.

Exposed Headers

Response headers exposed to the client. Use * to expose all response headers.

Access Control Max Age

How long (in seconds) the browser can cache preflight results. Defaults to 900 seconds if not set.

cors-1.png
cors-1.png
cors.png
cors.png

How It Works

  1. Request initiated — A client (e.g., a browser) sends a cross-origin request to the API.

  2. Origin validation — The gateway checks whether the request's origin matches the configured allowed origins.

  3. Preflight handling — For complex requests, the browser first sends a preflight (OPTIONS) request. The gateway evaluates allowed methods, headers, and origins and responds accordingly.

  4. Policy enforcement — Compliant requests are allowed; non-compliant requests are rejected or blocked.

  5. CORS headers added — The gateway attaches appropriate CORS headers (e.g., Access-Control-Allow-OriginAccess-Control-Allow-Methods) to the response.

  6. Client access control — The browser enforces these headers to allow or deny the client access to the response.

Attaching to an API Group

Once a CORS Policy is created, attach it to one or more API Groups from the group's policy settings. Multiple policies can be applied to a single group; drag them into the desired execution order.

Notes

  • Avoid using * for Allowed Origins in production — enumerate specific trusted domains to prevent unintended cross-origin access.

  • Set Access Control Max Age to a value that reduces preflight overhead (e.g., 3600 seconds for non-sensitive APIs), but lower it for APIs where CORS rules change frequently.

  • Use regex patterns (prefixed with ~) in Allowed Origins to handle dynamic subdomains without maintaining a fixed list.

  • CORS policies protect browsers, not server-to-server calls — if your API is only called by backend services, a CORS policy is unnecessary.

FAQs

Do I need a CORS Policy for APIs called by other backend services?

No. CORS is a browser-enforced mechanism. If your API is only called by backend services (no browser clients), a CORS Policy is not needed.

What is a preflight request?

A preflight is an HTTP OPTIONS request that the browser sends automatically before a complex cross-origin request (e.g., POST with JSON body or custom headers). The gateway must respond with the appropriate CORS headers to allow the actual request to proceed

What does Access Control Max Age control?

It tells the browser how long (in seconds) it can cache the preflight response. A higher value reduces the number of preflight requests the browser makes, improving performance. The default is 900 seconds.

How do I allow all subdomains of a domain?

Use a regex pattern prefixed with ~ in the Allowed Origins field — for example, ~https://(.*)\.example\.com allows all subdomains of example.com.