CORS allowed origin

Learn what an origin is, why browsers block cross-origin reads, and how CorsLayer allow origin opens an Axum API to one named origin

A frontend and an API often live at different addresses. The page might be served from https://frontend.example.com while the API runs on https://api.example.com. A browser treats those two addresses as different places, and by default it refuses to let JavaScript on one place read responses from the other. That refusal protects users, and it has a name, the same-origin policy. Cross-Origin Resource Sharing, usually shortened to CORS, is the mechanism a server uses to relax that policy in a controlled way. In Axum, CORS is handled by CorsLayer from the tower-http crate, and the setting that controls which places may call the API is allow_origin.

Where This Fits

The layer itself is the tool that adds CORS headers to responses. This page covers one of its settings, the list of origins that may read those responses. Think of the layer as a doorkeeper and the origin list as the guest list it checks. The doorkeeper does the checking, the list says who is on it, and this page is about writing that list.

The Smallest Working Version

Start with a small API that has no CORS configuration at all, then add one line that opens it to a single frontend. Create a project with this Cargo.toml. The cors feature is what makes CorsLayer exist at all, so it must be switched on.

Cargo.toml
[package]
name = "axum-project"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "=0.8.9"
tokio = { version = "=1.54.1", features = ["full"] }
tower-http = { version = "=0.7.1", features = ["cors"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Here is the server, split into two files so the tests later on this page can call the same application the server runs. The library file builds the router, and the main file only starts it.

src/lib.rs
use axum::{Json, Router, http::HeaderValue, routing::get};
use serde::Serialize;
use tower_http::cors::CorsLayer;

#[derive(Serialize)]
struct Message {
    text: String,
}

pub fn app() -> Router {
    let cors = CorsLayer::new()
        .allow_origin("https://frontend.example.com".parse::<HeaderValue>().unwrap())
        .allow_methods([axum::http::Method::GET, axum::http::Method::POST])
        .allow_headers([axum::http::header::AUTHORIZATION, axum::http::header::CONTENT_TYPE]);

    Router::new()
        .route("/", get(hello))
        .route("/api/data", get(api_data))
        .layer(cors)
}

async fn hello() -> &'static str {
    "Hello from the API!"
}

async fn api_data() -> Json<Message> {
    Json(Message {
        text: "Some data".to_string(),
    })
}
src/main.rs
use axum_project::app;

#[tokio::main]
async fn main() {
    let app = app();
    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();
    println!("Listening on http://127.0.0.1:3000");
    axum::serve(listener, app).await.unwrap();
}

Run it with cargo run, then ask for the data while pretending to be the allowed frontend. Curl is not a browser, so it never blocks a response for CORS reasons. That makes curl a good debugging tool, because it shows the raw headers the server sent.

curl -i -H "Origin: https://frontend.example.com" http://127.0.0.1:3000/api/data

The response carries the header that opens the door for that origin.

HTTP/1.1 200 OK
content-type: application/json
access-control-allow-origin: https://frontend.example.com
content-length: 22

{"text":"Some data"}

A browser on a page from https://frontend.example.com reads that header, sees its own origin in it, and hands the response to the JavaScript. Now ask from a different origin.

curl -i -H "Origin: https://evil.example.com" http://127.0.0.1:3000/api/data
HTTP/1.1 200 OK
content-type: application/json
access-control-allow-origin: https://frontend.example.com
content-length: 22

{"text":"Some data"}

The server still answered with status 200 and the same body. The header still names the allowed origin, not the origin that asked. The browser is the part that enforces the rule. It compares the header value with the origin of the page making the request, finds they differ, and blocks the JavaScript from reading the response. The protection comes from that comparison, not from the server withholding the answer. That fixed-value behaviour is specific to a single exact origin, and the list form later on this page behaves differently.

Working Setup:

If the response to a request from the allowed origin carries access-control-allow-origin with that exact origin, the setting works. If a request from another origin carries the same header with the allowed origin in it, that is also correct for a single exact origin. The browser does the blocking, not the server.

What an Origin Is

An origin is a combination of three parts, the scheme, the host, and the port. The scheme is http or https. The host is the domain name, such as frontend.example.com. The port is the number after the colon, such as 3000. Two addresses are the same origin only when all three parts match.

That rule is stricter than it looks. The addresses https://frontend.com and http://frontend.com are different origins, because the scheme differs. The addresses https://frontend.com and https://backend.com are different origins, because the host differs. The addresses https://frontend.com:3000 and https://frontend.com:4000 are different origins, because the port differs. During local development, http://localhost:3000 and http://localhost:5173 are different origins too, which is why a local frontend and a local API hit CORS errors even though both run on the same machine.

A beginner can think of an origin as a full return address on an envelope. Changing any line of the address sends the letter to a different house, even when most of the lines look the same. The browser checks the whole address, not just the part that looks familiar.

Address AAddress BSame origin
https://frontend.comhttps://frontend.comYes
https://frontend.comhttp://frontend.comNo, scheme differs
https://frontend.comhttps://api.frontend.comNo, host differs
https://frontend.com:3000https://frontend.com:4000No, port differs
http://localhost:3000http://localhost:5173No, port differs

An origin never includes a path. The address https://frontend.example.com is an origin. The address https://frontend.example.com/dashboard is a page inside that origin, and the origin part of it is still https://frontend.example.com. When you write an origin in allow_origin, write only the scheme, host, and port, with no trailing slash and no path.

The Same-Origin Policy and the Preflight

The same-origin policy says that JavaScript running on a page from one origin may only read responses from that same origin. Without that rule, a harmful website could use your browser to call your bank website and read your account data, because your browser would attach your cookies to the request on its own. The policy blocks that by default, and CORS lets a server say, in a precise way, which other origins may read its responses.

The browser handles cross-origin requests in two ways. A simple request uses only a GET, HEAD, or POST method, only a few basic headers, and a simple content type such as text/plain. The browser sends a simple request directly and then checks the response for CORS headers before letting JavaScript read it. Anything more complex is a preflighted request. A PUT or DELETE method, a custom header such as Authorization, or a JSON content type makes the request complex. Before sending the real request, the browser sends an OPTIONS request, called a preflight, that asks the server whether the real request would be allowed.

The preflight carries three headers. Origin says where the page making the request lives. Access-Control-Request-Method says which method the real request will use. Access-Control-Request-Headers lists the headers the real request will carry. The server answers with the CORS headers, and only then does the browser send the real request. CorsLayer handles both kinds of request on its own. You configure the rules once, and the layer adds the right headers to responses and answers preflight requests before they ever reach your handlers. You do not write an OPTIONS handler yourself.

1

Step 1: The browser sends a preflight

The page tries a complex cross-origin request, so the browser first sends an OPTIONS request with Origin, Access-Control-Request-Method, and Access-Control-Request-Headers.

curl -i -X OPTIONS \
  -H "Origin: https://frontend.example.com" \
  -H "Access-Control-Request-Method: GET" \
  -H "Access-Control-Request-Headers: authorization" \
  http://127.0.0.1:3000/api/data
2

Step 2: CorsLayer answers the preflight

The layer checks the origin against the allowed list and answers with the allowed origin, methods, and headers. The handler never runs for this request.

HTTP/1.1 200 OK
access-control-allow-methods: GET,POST
access-control-allow-headers: authorization,content-type
access-control-allow-origin: https://frontend.example.com
3

Step 3: The browser compares and decides

The browser compares the answer with what the page asked for. If the origin, the method, and every header match the allowed lists, the browser sends the real request. If any part does not match, the real request is never sent and the console shows a CORS error.

4

Step 4: The real request runs

The real request reaches the handler, the handler builds the response, and the layer adds access-control-allow-origin to it so the browser lets the JavaScript read the result.

The preflight answer in step 2 also shows something worth noticing. The methods and headers lists appear in it, because the smallest example allowed GET and POST and two headers. Those lists are separate settings from the origin, and each one has its own job. The origin list decides who may ask. The methods and headers lists decide what they may ask for.

A Failed Preflight Still Returns 200:

A preflight that asks for something not on the lists still gets status 200 from this server. The failure shows up in the headers, not in the status. The answer lists only what is allowed, and the browser notices that what was asked for is missing from that list. Do not look for a 4xx status when debugging a preflight. Look at the allowed headers in the answer.

Reading the allow_origin Call

The configuration in the smallest example has three pieces, and each one is worth understanding on its own. The first piece is the constructor.

let cors = CorsLayer::new()

CorsLayer::new() creates a layer that allows nothing at all. No origins, no methods, no headers. Not even the simple methods GET, HEAD, and POST are allowed. If you use it without any configuration, no cross-origin request succeeds. That is the safe default, and it is the right base for a production configuration, because every permission you add is a deliberate choice.

The second piece is the method itself.

.allow_origin("https://frontend.example.com".parse::<HeaderValue>().unwrap())

allow_origin sets the origins that may call the API, and it decides the value of the Access-Control-Allow-Origin response header. The origin is passed as a HeaderValue, which is the http crate type for a single header value. A plain string must be parsed into a HeaderValue first, and the parse can fail if the string is not a valid header value, so the example unwraps the result. In a learning project, unwrap is fine, because a bad origin string is a mistake you want to see at once. The unwrap runs when the server starts, so a bad value crashes the server at startup with a clear message instead of failing quietly on the first request.

The third piece is the way the layer is attached.

let app = Router::new()
    .route("/", get(hello))
    .route("/api/data", get(api_data))
    .layer(cors);

The .layer() call wraps the whole router, so every route in it carries the CORS headers. The layer is built first and stored in a variable, which keeps the router construction readable when the configuration grows. A short configuration can also be written inline in the .layer() call, and it behaves exactly the same way.

The Default Sends Nothing

A layer built with CorsLayer::new() and no allow_origin call sends no CORS headers at all. That was checked by running a server with the bare default and asking it for data from a named origin.

curl -i -H "Origin: https://frontend.example.com" http://127.0.0.1:3000/api/data
HTTP/1.1 200 OK
content-type: application/json
content-length: 22

{"text":"Some data"}

There is no access-control-allow-origin header in that response, and a preflight to the same server answers 200 with no allowed methods and no allowed origin either. The handler still runs and the body still arrives, because CORS never stops the server from answering. It only stops the browser from handing the answer to JavaScript. A missing CORS header is the most common cause of the console error that says no Access-Control-Allow-Origin header is present on the requested resource, and the fix is always an allow_origin call, not a change to the handler.

Forgetting the cors Feature:

Without features = ["cors"] on the tower-http dependency, the CorsLayer type does not exist and the import fails with a compile error saying the module could not be found. The fix is one word in Cargo.toml. If the compiler cannot find tower_http::cors, check the feature list before anything else.

Allowing Several Origins with One List

Most real applications have more than one frontend. A main application and an admin panel, or a production site and a staging site, each live on their own origin, and both need to call the same API. The way to allow them is one call that carries the whole list. AllowOrigin::list takes a collection of HeaderValue values and allows each of them.

src/main.rs
use axum::http::HeaderValue;
use tower_http::cors::{AllowOrigin, CorsLayer};

let cors = CorsLayer::new()
    .allow_origin(AllowOrigin::list([
        "https://frontend.example.com".parse::<HeaderValue>().unwrap(),
        "https://admin.example.com".parse::<HeaderValue>().unwrap(),
    ]))
    .allow_methods([axum::http::Method::GET, axum::http::Method::POST]);

The list form behaves differently from the single origin form, and the difference matters. With a list, the server echoes the requesting origin back only when that origin is on the list, and an unlisted origin gets no header at all. That was checked by running the list configuration and asking from three origins.

curl -s -D - -o /dev/null -H "Origin: https://frontend.example.com" http://127.0.0.1:3000/api/data
HTTP/1.1 200 OK
access-control-allow-origin: https://frontend.example.com
curl -s -D - -o /dev/null -H "Origin: https://admin.example.com" http://127.0.0.1:3000/api/data
HTTP/1.1 200 OK
access-control-allow-origin: https://admin.example.com
curl -s -D - -o /dev/null -H "Origin: https://evil.example.com" http://127.0.0.1:3000/api/data
HTTP/1.1 200 OK

The third response has no access-control-allow-origin header, so the browser blocks it. A preflight from the unlisted origin behaves the same way. It answers 200 with the allowed methods and headers, and no allowed origin, and the browser never sends the real request.

You can also pass an array of HeaderValue values directly to allow_origin, because an array converts into an AllowOrigin the same way a list does.

src/main.rs
use axum::http::HeaderValue;
use tower_http::cors::CorsLayer;

let origins = [
    "https://frontend.example.com".parse::<HeaderValue>().unwrap(),
    "https://admin.example.com".parse::<HeaderValue>().unwrap(),
];

let cors = CorsLayer::new()
    .allow_origin(origins)
    .allow_methods([axum::http::Method::GET, axum::http::Method::POST]);

Both spellings do the same thing. The AllowOrigin::list form reads more clearly when the list is long, and the array form is shorter when there are only two or three origins. Pick one and use it everywhere in the project, so the configuration is easy to scan.

A beginner can think of the single origin as a name badge printed in advance and the list as a doorkeeper who checks the guest list and repeats back the name of the guest who arrived. The badge is the same for everyone who sees it. The doorkeeper only speaks to guests who are on the list.

Calling allow_origin Twice Does Not Add Origins

This is the mistake that catches almost everyone. Calling allow_origin twice does not accumulate origins. Each call overwrites the previous one, so only the last origin survives. That was checked by running a layer built with two chained calls, first https://first.example.com and then https://second.example.com. A request from the first origin and a request from the second origin both answered with the same header.

access-control-allow-origin: https://second.example.com

The first origin was gone entirely. The wrong code looks like this.

// Wrong - the second call replaces the first, it does not add to it
let cors = CorsLayer::new()
    .allow_origin("https://first.example.com".parse::<HeaderValue>().unwrap())
    .allow_origin("https://second.example.com".parse::<HeaderValue>().unwrap());

The fix is the single list call from the section above. Every builder method on CorsLayer replaces the previous value for that setting, so the same overwrite rule applies to the methods and headers lists too. If a frontend suddenly stops working after a second origin is added, check whether the code chained two calls instead of passing one list.

Chained allow_origin Calls Overwrite Each Other:

Every builder method on CorsLayer replaces the previous value for that setting. Chaining allow_origin twice keeps only the last origin. Pass all origins in one AllowOrigin::list call, or one array, instead.

Allowing Any Origin

If the API is public, with no login and no private data, any website may call it. The Any value, imported from tower_http::cors, means any origin.

src/main.rs
use tower_http::cors::{Any, CorsLayer};

let cors = CorsLayer::new()
    .allow_origin(Any)
    .allow_methods([axum::http::Method::GET, axum::http::Method::POST]);

This answers every request with access-control-allow-origin: *, where the star means any value is allowed. That was checked by asking the server from an origin that was never listed anywhere.

curl -s -D - -o /dev/null -H "Origin: https://evil.example.com" http://127.0.0.1:3000/api/data
HTTP/1.1 200 OK
access-control-allow-origin: *

Any only opens the origin. It does not touch methods or headers, which stay at their default of nothing allowed, so the methods list in the example above is still needed. CorsLayer::permissive() is a separate shortcut that opens origins, methods, headers, and exposed headers all at once, and it is a development tool, not a production setting. The manual version with Any gives control over each piece separately, which is the point of building the configuration by hand.

One limit applies to the star and it is worth stating here, even though the full story belongs with credentials. A star origin never goes together with credentials such as cookies. A browser refuses that combination, and the layer refuses to build it. When the API has a login, use a named origin or a list of named origins, never Any.

Origins Decided by a Rule

Sometimes the list of allowed origins is not fixed in advance. A product that gives each customer their own subdomain, such as customer1.example.com and customer2.example.com, cannot list them all when the code is written. AllowOrigin::predicate lets you decide with a function that receives the request origin and returns true or false.

src/main.rs
use axum::http::HeaderValue;
use tower_http::cors::{AllowOrigin, CorsLayer};

let cors = CorsLayer::new().allow_origin(AllowOrigin::predicate(
    |origin: &HeaderValue, _parts: &axum::http::request::Parts| {
        origin.as_bytes().ends_with(b".example.com")
    },
));

The closure receives the origin as bytes and checks whether it ends with .example.com. Any subdomain passes, and any other domain fails. The second parameter carries the request parts, which you can use when the decision needs more than the origin itself, for example checking a header. There is also an async version, AllowOrigin::async_predicate, for decisions that need to wait on something, such as fetching the allowed list from a database.

A predicate is a sharper tool than a list, and it needs a sharper rule. A check like "ends with .example.com" also matches notexample.com, because that string ends with the same letters. A rule that is meant to match subdomains should check for a dot before the domain, or compare against a list of known subdomains. A loose predicate quietly allows origins the developer never meant to allow, and the browser will not catch that mistake, because the server told it the origin was fine.

A Plain Text Diagram of the Flow

The origin check sits between the browser and the handler, and it runs on every cross-origin request.

page on https://frontend.example.com
        |
        v
browser sends request with Origin header
        |
        v
CorsLayer checks the origin
        |
        +-- single exact origin --> always sends that origin back
        |                              |
        |                              v
        |                         browser compares, allows on match
        |
        +-- origin on the list --> echoes the requesting origin back
        |                              |
        |                              v
        |                         browser compares, allows on match
        |
        +-- origin not on the list --> no allow-origin header
        |                              |
        |                              v
        |                         browser blocks the response
        |
        +-- Any --> sends * back
                                       |
                                       v
                                  browser allows any origin

The diagram has one point that surprises beginners. In every branch except the unlisted one, the server still runs the handler and still sends the body. The decision that matters happens in the browser, after the response arrives. CORS is a browser rule, not a server rule, and the server side of it is only the headers.

Testing It

Three tests cover the behaviours of this page. The first three use the application from the final example below, where the frontend and the admin origins are both on the list. The fourth builds a small single-origin router of its own, because the fixed-value behaviour of one exact origin can only be seen on a router that uses one.

tests/cors_origin_test.rs
use axum::{
    body::Body,
    http::{HeaderValue, Request, StatusCode},
    routing::get,
    Router,
};
use axum_project::app;
use tower::ServiceExt;
use tower_http::cors::CorsLayer;

async fn get_with_origin(app: Router, origin: &str) -> axum::response::Response {
    app.oneshot(
        Request::builder()
            .uri("/api/data")
            .header("origin", origin)
            .body(Body::empty())
            .unwrap(),
    )
    .await
    .unwrap()
}

#[tokio::test]
async fn listed_frontend_origin_is_echoed_back() {
    let response = get_with_origin(app(), "https://frontend.example.com").await;
    assert_eq!(response.status(), StatusCode::OK);
    assert_eq!(
        response.headers().get("access-control-allow-origin").unwrap(),
        "https://frontend.example.com"
    );
}

#[tokio::test]
async fn listed_admin_origin_is_echoed_back() {
    let response = get_with_origin(app(), "https://admin.example.com").await;
    assert_eq!(
        response.headers().get("access-control-allow-origin").unwrap(),
        "https://admin.example.com"
    );
}

#[tokio::test]
async fn unlisted_origin_gets_no_header() {
    let response = get_with_origin(app(), "https://evil.example.com").await;
    assert_eq!(
        response.headers().get("access-control-allow-origin"),
        None
    );
}

#[tokio::test]
async fn single_origin_always_sends_the_configured_origin() {
    let single = Router::new()
        .route("/api/data", get(|| async { "Some data" }))
        .layer(
            CorsLayer::new().allow_origin(
                "https://frontend.example.com".parse::<HeaderValue>().unwrap(),
            ),
        );
    let response = get_with_origin(single, "https://evil.example.com").await;
    assert_eq!(
        response.headers().get("access-control-allow-origin").unwrap(),
        "https://frontend.example.com"
    );
}

The first two tests guard the list behaviour. If somebody replaces the list with a single origin, the admin test fails, because the admin origin would receive the frontend origin instead of its own. The third test guards the other side. If somebody replaces the list with Any, the third test fails, because every origin would receive a star. The fourth test guards the fixed-value behaviour. If the single origin ever started echoing the requester, that test would fail, because it asks from an origin that was never allowed and still expects the configured one back.

The tower crate is needed as a dev dependency.

Cargo.toml
[dev-dependencies]
tower = { version = "=0.5.3", features = ["util"] }

Run the tests with cargo test. A test that checks a header value is more useful here than a test that checks a status, because CORS failures never change the status. The header is the whole answer.

Common Beginner Mistakes

Adding a Trailing Slash or a Path to the Origin

// Wrong - an origin has no path, so this never matches the page origin
.allow_origin("https://frontend.example.com/".parse::<HeaderValue>().unwrap())

The page origin is https://frontend.example.com, with no slash at the end. A configured origin with a trailing slash is a different string, and the browser compares strings, so it blocks the response even though the site looks the same to a human. The fix is to write the origin as scheme, host, and port only.

Expecting the Server to Block the Wrong Origin

// Wrong thinking - the handler still runs for every origin
async fn api_data() -> Json<Message> {
    Json(Message {
        text: "Some data".to_string(),
    })
}

Nothing in the handler checks the origin, and nothing needs to. The handler runs for every request, from every origin, and the layer adds the headers afterwards. If the data itself must stay private, the route needs authentication, not a CORS list. CORS decides which pages may read the response in a browser. It never decides which clients may reach the server, because any client that is not a browser, such as curl, ignores CORS entirely.

Using the Wrong Scheme in Development

A frontend served over http://localhost:5173 and an API configured for https://localhost:5173 are different origins. The scheme is part of the origin, and local development almost always uses plain http. When a local frontend gets a CORS error and the origin looks right, compare the scheme character by character before changing anything else.

Forgetting That Methods Need Their Own List

The smallest example on this page allowed GET and POST alongside the origin. An origin on its own is not enough, because CorsLayer::new() allows no methods by default. A frontend that only reads data still needs GET on the list, and a frontend that sends data needs POST there too. The methods list is a separate setting with its own rules, and leaving it empty makes every preflight fail even when the origin is correct.

Final Complete Example

Here is everything from this page put together. Two named origins on one list, a greeting route, a JSON route, a reusable configuration function, and the tests from the section above. The project layout is the one the smallest example used, with the application split into a library so the tests can call it.

src/lib.rs
use axum::{Json, Router, http::HeaderValue, routing::get};
use serde::Serialize;
use tower_http::cors::{AllowOrigin, CorsLayer};

#[derive(Serialize)]
struct Message {
    text: String,
}

pub fn cors_layer() -> CorsLayer {
    CorsLayer::new()
        .allow_origin(AllowOrigin::list([
            "https://frontend.example.com".parse::<HeaderValue>().unwrap(),
            "https://admin.example.com".parse::<HeaderValue>().unwrap(),
        ]))
        .allow_methods([axum::http::Method::GET, axum::http::Method::POST])
        .allow_headers([axum::http::header::AUTHORIZATION, axum::http::header::CONTENT_TYPE])
}

pub fn app() -> Router {
    Router::new()
        .route("/", get(hello))
        .route("/api/data", get(api_data))
        .layer(cors_layer())
}

async fn hello() -> &'static str {
    "Hello from the API!"
}

async fn api_data() -> Json<Message> {
    Json(Message {
        text: "Some data".to_string(),
    })
}
src/main.rs
use axum_project::app;

#[tokio::main]
async fn main() {
    let app = app();
    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();
    println!("Listening on http://127.0.0.1:3000");
    axum::serve(listener, app).await.unwrap();
}
Cargo.toml
[package]
name = "axum-project"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "=0.8.9"
tokio = { version = "=1.54.1", features = ["full"] }
tower-http = { version = "=0.7.1", features = ["cors"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[dev-dependencies]
tower = { version = "=0.5.3", features = ["util"] }

The headers list in the final example names the two request headers the frontend sends, the token header and the JSON content type header. Each list in the configuration earns its place. The origins list names exactly the two frontends that exist. The methods list names the two methods the frontend uses. Nothing is allowed that the frontend does not use.

Run the checks with these commands.

cargo check
cargo test
cargo run

Summary

The origin is the first question CORS asks, and it is also the question that decides the shape of every answer that follows. A single exact origin is a fixed value the server sends on every response, and the browser does the blocking by comparing it with the page origin. A list echoes only its members and stays silent for everyone else, which is the behaviour most production APIs want. A star opens the door to every origin at once, which fits a public API and nothing that has a login. A predicate decides by a rule when the list cannot be written in advance, and a loose rule is worse than a short list, because the server will vouch for origins nobody meant to allow.

The decision framework to carry forward has two branches. If the API is public, with no login and no private data, a star is honest and simple. If the API has a login, a session, or private data, list the exact origins and nothing else, and open up one origin at a time when a real frontend needs it. Each origin on the list is a deliberate choice, and the configuration reads as a record of those choices. The next question after who may ask is what they may do once they are allowed in, and that question is answered by the methods list.