Achieve Cross-Origin Resource Sharing
Created November 6, 2026 · Updated November 6, 2026 · Achieve 3.1.0 · Qualified runtime: Node.js 24.22.2
Achieve denies cross-origin resource access unless an allowOrigins() policy matches. Policies select origins, application paths, and asset names without changing normal routing or resource containment.
Configuration
achieve.allowOrigins(
"https://example.com",
"/api/",
["catalog.json", "status.jss"]
);Each argument can be a single value or array. Omitted paths and assets default to *. Calls accumulate across different origin/path pairs; repeating one pair replaces its asset set.
Matching
Requests without Origin and requests marked Sec-Fetch-Site: same-origin continue normally. For a cross-origin request, Achieve first chooses an exact-origin policy map; the wildcard-origin map is used only when no exact-origin map exists. Within that map, the most specific matching path wins, then the asset name or * is checked.
An allowed response receives the request Origin in Access-Control-Allow-Origin and appends Origin to Vary. A denied request receives 403 before its static resource, servlet, or registered-method handler runs.
Preflight and OPTIONS
An OPTIONS request containing Origin and Access-Control-Request-Method is checked against the target policy. An allowed preflight returns 204 with Allow, Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers: Content-Type. Registered methods appear in the advertised method list. OPTIONS * is a server-wide capability response and does not perform resource CORS matching.
Limits and verification
The built-in policy does not advertise credentials, arbitrary requested header names, exposure fields, or max age. Applications needing those semantics must design and test them explicitly. CORS tests cover exact and wildcard origins, specificity, replacement, assets, static resources, servlets, GET, HEAD, POST, registered methods, approved and denied preflights, Vary, and handler non-invocation.
