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.
Before you begin
Section titled “Before you begin”- Privilege:
MODIFYon the realm’scorsSettings, whichRealmOwnergives. - Where: the API.
- First: the exact origin each page is served from, and your session in
$CVYUH_SESSION(Call the API).
How it works
Section titled “How it works”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:
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 ContentAccess-Control-Allow-Origin: https://admin.example.comAccess-Control-Allow-Credentials: trueAccess-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, QUERYAccess-Control-Max-Age: 600Vary: originAccess-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,PUTorPATCHwhose body isn’t JSON (application/json, or a type ending in+json) is answered415. 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 withcredentials. A script that sends noOriginheader, and a call that sends anAuthorizationheader instead of the cookie, aren’t affected.
Set it up
Section titled “Set it up”Write the realm’s corsSettings object, whose id is corsSettings:
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 happens when it fails
Section titled “What happens when it fails”| What you see | Cause | What 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 twice | Write each origin as a browser sends it, once |
| The browser reports a CORS error, and your page can’t read the answer | The page’s origin isn’t listed | Add it |
403 on a write from your page | The page sends the session cookie, and its origin isn’t listed with credentials | List it with "credentials": true, if you control it |
415 on a write | The body isn’t JSON | Send Content-Type: application/json |
Limits and defaults
Section titled “Limits and defaults”| What | Default | Can it change |
|---|---|---|
| Origins listed | None: only the realm’s own pages | Add your own |
credentials per origin | false | Set per origin |
| How long a browser may keep a preflight answer | 600 seconds | No |
Plain http origins | Only localhost, 127.0.0.1 and [::1] | No |
Troubleshooting
Section titled “Troubleshooting”- It works in
curland fails in the browser.curldoesn’t enforce CORS. Send the preflight above with your page’sOrigin, and check the answer carriesAccess-Control-Allow-Origin. - Reads work and writes are refused with
403. The origin is listed withoutcredentials, and the write carries the session cookie. List it withcredentials, or have the page send anAuthorizationheader 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.
Audit record
Section titled “Audit record”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.
Good to know
Section titled “Good to know”- 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: nullis 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-Matchand the request-id header. The page may readLocation,ETag, the request id andWWW-Authenticate. - OAuth endpoints follow their own rule, set per client: see Browser apps.
Related
Section titled “Related”- 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.