Skip to content
PlatformMarkdown

Allowed origins

Choose which of your own web pages may call the realm's APIs from a browser, and whether they act as the signed-in user.

AvailableAPIFetch (CORS), RFC 6454

The dashboard calls the realm’s APIs from the realm’s own host name, so it needs nothing here. A page you serve from anywhere else does: your own admin tool, a status page, or a sign-in page of your own design. A browser lets such a page read the realm’s answers only if the realm lists the page’s origin in its corsSettings: the scheme, host and port the page is served from, such as https://admin.example.com. A realm lists nothing until you add it.

For each origin you list, you also choose whether its requests may carry the signed-in user’s session.

  • Privilege: MODIFY on the realm’s corsSettings, which RealmOwner gives.
  • Where: the API.
  • First: the exact origin each page is served from, and your session in $CVYUH_SESSION (Call the API).

Before a cross-origin write, the browser asks the realm first (a preflight). You can make the same request yourself to see what a browser would be told:

Terminal window
curl -i -X OPTIONS https://foobar.cvyuh.com/api/v0/am/objects/v1/group \
-H "Origin: https://admin.example.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: content-type"

For a listed origin, the realm answers, in part:

HTTP/1.1 204 No Content
Access-Control-Allow-Origin: https://admin.example.com
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, QUERY
Access-Control-Max-Age: 600
Vary: origin

Access-Control-Allow-Credentials appears only for an origin listed with credentials. An origin that isn’t listed gets the 204 with none of the Access-Control- headers, and the browser stops there.

Two more rules protect writes, whatever you list:

  • Every write sends JSON. A POST, PUT or PATCH whose body isn’t JSON (application/json, or a type ending in +json) is answered 415. So a browser always asks the realm before a cross-origin write.
  • A write carrying the session cookie comes only from where it may. It is refused (403) unless it comes from the realm’s own pages or from an origin listed with credentials. A script that sends no Origin header, and a call that sends an Authorization header instead of the cookie, aren’t affected.

Write the realm’s corsSettings object, whose id is corsSettings:

Terminal window
curl -X PUT https://foobar.cvyuh.com/api/v0/am/objects/v1/corsSettings/corsSettings \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
-H "Content-Type: application/json" \
-d '{ "origins": [
{ "origin": "https://admin.example.com", "credentials": true },
{ "origin": "https://status.example.com" } ] }'

Each entry names one origin, written as a browser sends it, and credentials (false by default): whether that origin’s requests carry the signed-in user’s session. Call the API shows how to get $CVYUH_SESSION.

What you seeCauseWhat to do
400 when you save the list*, null, a wildcard, a path, upper case, a default port, plain http off loopback, or an origin listed twiceWrite each origin as a browser sends it, once
The browser reports a CORS error, and your page can’t read the answerThe page’s origin isn’t listedAdd it
403 on a write from your pageThe page sends the session cookie, and its origin isn’t listed with credentialsList it with "credentials": true, if you control it
415 on a writeThe body isn’t JSONSend Content-Type: application/json
WhatDefaultCan it change
Origins listedNone: only the realm’s own pagesAdd your own
credentials per originfalseSet per origin
How long a browser may keep a preflight answer600 secondsNo
Plain http originsOnly localhost, 127.0.0.1 and [::1]No
  • It works in curl and fails in the browser. curl doesn’t enforce CORS. Send the preflight above with your page’s Origin, and check the answer carries Access-Control-Allow-Origin.
  • Reads work and writes are refused with 403. The origin is listed without credentials, and the write carries the session cookie. List it with credentials, or have the page send an Authorization header instead.
  • Your page never receives the session. The browser sends the cookie only within the realm host name’s own registered domain; see Good to know.

Each change to corsSettings is a change record naming who made it, before and after. Read it as the setting’s change history: GET https://foobar.cvyuh.com/api/v0/am/objects/v1/corsSettings/corsSettings/history.

  • With credentials, an origin’s scripts act as the signed-in user. They read and write as that user. List an origin that way only if you control it.
  • Each realm’s list is its own. No realm inherits its parent’s list.
  • An origin is written exactly as a browser sends it: https://admin.example.com, lowercase, no path, no default port.
  • Origin: null is never allowed. A sandboxed frame or a local file can’t be listed, and its writes with the session are refused.
  • The session cookie goes only where the browser sends it. With the default cookie setting, a browser sends it to pages under the same registered domain as the realm’s host name, and not to an unrelated domain, whatever the list says.
  • What a page may send and read. Requests may send Content-Type, If-Match, If-None-Match and the request-id header. The page may read Location, ETag, the request id and WWW-Authenticate.
  • OAuth endpoints follow their own rule, set per client: see Browser apps.
  • Call the API: the calls a page of yours makes, and how a script calls them instead.
  • Browser apps: which origins may call the realm’s OAuth endpoints.
  • Realm base URL: the one public address of the realm.