Skip to main content

CORS — cross-origin resource sharing

This section uses a single On/Off switch at the top to turn CORS on or off for the domain. Off deletes the domain's entire CORS configuration (all rules).

CORS (Cross-Origin Resource Sharing) lets the edge generate the Access-Control-Allow-* headers itself, so that browsers on a website with a different origin are allowed to call your domain's resources, instead of leaving this to your origin. Each domain has a list of rules matched by path and hostname that define which origins, methods and headers are allowed. The edge also answers preflight requests (OPTIONS) with 204 without going to the origin.

Use it when your API, fonts or images are called from another website (a frontend on a different domain) through the browser. Example: a React app at https://app.example.net needs to call the API at https://api.example.com. Add one CORS rule that allows the origin https://app.example.net.

Before you start​

  • The domain has been added and points to VNIS.
  • You know the exact origin(s) allowed to make calls (in the form https://domain-name).

How to configure​

This section uses a single On/Off switch at the top: On creates and applies the CORS configuration (saved immediately); Off deletes all CORS rules for the domain. Rules are shown even when the switch is Off, so you can add or edit them first and then switch On.

  1. Go to Domains → select a domain → CORS tab. Go to Domains → select a domain → CORS tab
  2. Click Add Rule. Set Path Pattern and Match Type, enter Allowed Origins (at least 1), choose Allowed Methods, and optionally set Allowed/Expose Headers, Allow Credentials and Max-Age.
  3. Turn the switch On at the top of the section. For later edits, click Save (shown only when the switch is On and there are unsaved changes).

Configuration fields​

Section level:

FieldMeaningValuesDefaultNotes
On/Off switch (section corner)Turns CORS on or off for the domain — On creates, Off deletesSwitchOff (not configured)Off means no CORS headers are added, OPTIONS requests are not short-circuited, and the configuration is deleted (you must configure it again to turn it back on). You cannot switch On while a rule has errors
RulesList of rules≤ 50 rules—The first matching rule by priority is applied (first-match)

Each rule:

FieldMeaningValuesDefaultNotes
PriorityOrder in which rules are evaluatedInteger ≥ 0, must be unique0 (the UI sets it to max+1)Lower numbers are evaluated first (ascending order). Two rules with the same priority → 400
Path PatternPath pattern the rule applies toString, not empty, ≤500 characters (bytes) for every Match Type/*Regex must be valid. Over 500 → 400
Match TypeHow the path is comparedexact / prefix / regexprefix—
Match HostnamesRestrict by hostname (OR)≤20Empty (= all hosts)Operators equals/contains/starts_with/ends_with/wildcard/regex
Allow OriginsAllowed origins≥1 (up to 100); * = any origin—Empty → 400
Allow MethodsAllowed methods (sent only in the preflight response)Subset of GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONSGET,HEAD,OPTIONSUnknown method → 400
Allow HeadersHeaders the client may send (preflight)List—Joined into Access-Control-Allow-Headers
Expose HeadersHeaders the client may read (actual response)List——
Allow CredentialsAllow cookies/credentials to be sentOn/offOffCannot be turned on together with * in Allow Origins → 400
Max-AgeHow long the preflight response is cachedSeconds, ≤ 8640086400> 86400 → 400

Configuration examples​

Rules are evaluated by priority (lower numbers first), and evaluation stops at the first rule that matches the path and hostname.

Example 1 — Allow a specific frontend to call the entire API.

  • Path Pattern /* (prefix) · Allow Origins [https://app.example.net] · Allow Methods GET,POST,OPTIONS · Max-Age 600
  • Result: requests with Origin: https://app.example.net receive Access-Control-Allow-Origin: https://app.example.net + Vary: Origin; the OPTIONS preflight receives 204 + Access-Control-Allow-Methods: GET, POST, OPTIONS.
  • Check: curl -I -H "Origin: https://app.example.net" https://api.example.com/ → the Access-Control-Allow-Origin header is present.

Example 2 — Public resources for any origin (images/fonts, no credentials).

  • Path Pattern /assets/ (prefix) · Allow Origins [*] · Allow Credentials off · Allow Methods GET,HEAD,OPTIONS
  • Result: /assets/* returns Access-Control-Allow-Origin: * for every origin.
  • Because * is used, you cannot turn on Allow Credentials.
  • Check: curl -I -H "Origin: https://any-site.example" https://example.com/assets/logo.png.

Example 3 — An API that needs to send cookies (credentials) from one explicitly named origin.

  • Path Pattern /api/ (prefix) · Allow Origins [https://portal.example.com] · Allow Credentials on · Allow Methods GET,POST,PUT,OPTIONS
  • Result: the edge reflects exactly that origin (not *) + Access-Control-Allow-Credentials: true + Vary: Origin.
  • Check: send a request with cookies and the correct Origin → you receive both headers; a different origin → no headers.

Order of evaluation​

  • The On/Off switch controls whether the configuration exists: On creates the CORS record; Off deletes all CORS rules for the domain.
  • First-match by priority (lower numbers first). If two rules both match the path and hostname, the rule with the lower priority wins.
  • If a rule matches the path but the request's origin is not in Allow Origins, the edge adds no headers (safe by default).
  • Preflight OPTIONS requests with an Origin header are answered by the edge with 204 without going to the origin.
  • When Allow Credentials is on, the edge never uses *; it always reflects the specific origin and adds Vary: Origin.
  • If the combination credentials + "*" exists (for example, from imported data), the edge drops all CORS headers (fail-closed) to stay safe.

Troubleshooting​

SymptomCommon causeFix
Cannot turn the switch On (greyed out)A rule has errors (missing origin / unknown method / Max-Age / credentials+*)Fix all errors, then try again
Saving returns 400 "allow_credentials cannot be used with wildcard"Allow Credentials is on together with *List specific origins instead of *, or turn off credentials
Saving returns 400 "at least one origin is required"Allow Origins is emptyAdd at least 1 origin
Saving returns 400 "invalid method"Unknown method (for example TRACE)Use only valid methods
Saving returns 400 on Max-Age> 86400Reduce to ≤ 86400
The browser still reports a CORS errorThe request origin does not match Allow Origins, or another rule with a lower priority takes precedenceCheck the exact origin and the priority order
Credentials are not sent* is used (not valid with credentials)List specific origins and turn on Allow Credentials

FAQ​

  • Can I use *? Yes, for public resources without credentials. If you need to send cookies/credentials, you must list specific origins.
  • Do preflight OPTIONS requests go to the origin? No. The edge answers with 204 itself when CORS is on and the request has an Origin header.
  • Why is there a Vary: Origin header? When the edge reflects a specific origin, it adds Vary: Origin so the cache keeps separate entries per origin.
  • Where do Allow Methods/Headers appear? Only in the preflight response. Expose Headers appear in the actual response.