How do CORS settings permit authorized web applications to perform cross-origin REST requests against Salesforce?
Answer
Basics: Browsers enforce the same-origin policy, so a single-page app on https://app.example.com cannot read responses from https://mydomain.my.salesforce.com unless Salesforce replies with the right CORS headers. Adding the origin tells Salesforce to send them.
How it works:
- Setup > Security > CORS > New. Enter the origin, for example
https://app.example.com(a wildcard subdomain such ashttps://*.example.comis supported). - The browser sends a preflight
OPTIONSrequest, then the real call with anAuthorization: Bearer <token>header. - Salesforce checks the
Originheader against the allowlist and returnsAccess-Control-Allow-Origin. - The call still needs a valid OAuth access token.
Advanced / deep dive: CORS only concerns browsers. Server-to-server calls are unaffected. It covers supported Salesforce APIs, such as REST, UI API, Bulk API 2.0 and certain OAuth endpoints (verify the current list, which varies by endpoint), and it does not apply to SOAP. It is not an authorization mechanism, since attackers can call the API from any non-browser client, so token security and permissions still matter. For browser-held tokens use Authorization Code with PKCE. The opposite direction, where Salesforce pages load external resources, is controlled by CSP Trusted Sites and not by CORS. For Experience Cloud and LWR sites, use Trusted Sites for external APIs and CORS only when the external app calls into Salesforce.
Code / config example:
// Browser app on an allowlisted origin
const res = (, {
: { : }
});
data = res.();