CorsWhitelistOrigin represents one entry in Salesforce's CORS allowlist. CORS, or cross-origin resource sharing, lets browser-based code hosted at one origin request resources from another. For example, JavaScript on an external website can request Salesforce resources. The urlPattern setting identifies the requesting origin or group of origins covered by the entry, not the Salesforce resource being requested.
Key Elements
| Element | What the Element Controls |
|---|---|
urlPattern |
A string defining the allowed requesting origin. Supported forms include HTTPS web origins, subdomain wildcard patterns such as https://*.example.com, IP-address origins, and Chrome or Firefox extension origins. Each form has specific syntax requirements. |
Behavior and Constraints
For a CORS request from an allowlisted origin, Salesforce returns that origin in the Access-Control-Allow-Origin HTTP response header, along with additional CORS headers. If the origin is not allowlisted, Salesforce returns HTTP status code 404. In this context, a 404 can indicate an origin-allowlist mismatch rather than a missing resource.
The origin pattern determines the scope of the entry:
- Web origins: Use HTTPS and include a domain name. A port is optional.
-
Subdomain wildcards: The wildcard character
*must appear before a second-level domain name. For example,https://*.example.comcovers all subdomains ofexample.com, broadening the entry beyond a single host. - IP addresses: IP-address origins are supported. An IP address and a domain name resolving to that address are different origins. Add separate allowlist entries if browser code uses both; matching DNS resolution does not make them interchangeable.
-
Chrome extensions: Use
chrome-extension://followed by a 32-character identifier containing no digits or uppercase letters. -
Firefox extensions: Use
moz-extension://followed by lowercase alphanumeric characters in an8-4-4-4-12grouping.
The Chrome and Firefox extension schemes are supported alternatives to the HTTPS pattern used for web origins.
Deployment and Retrieval
In Metadata API format, CorsWhitelistOrigin components use the .corswhitelistorigin suffix and reside in the corswhitelistorigins folder.
The type supports the * wildcard in package.xml. To select all entries for deployment or retrieval, use this type block within the package manifest:
<types><members>*</members><name>CorsWhitelistOrigin</name></types>
This manifest wildcard selects components. It is separate from a wildcard inside urlPattern, which controls the origins an individual entry covers.
A deployment error saying that a component was named in package.xml but was not found in the zipped directory can concern file-format handling rather than an invalid urlPattern. The reported source-conversion case below does not establish a general requirement to rename CORS metadata files.
Reported Issues
-
A missing-component error was reported after source conversion. In a 2023-2024 discussion, an author reported that
CorsWhitelistOrigincomponents were named inpackage.xmlbut not found in the zipped directory when deploying converted Metadata API-format files throughproject deploy start. The author observed that conversion removed the source files'-meta.xmlending. They reported resolving the problem after updating Node.js and runningsf project deploy startdirectly from the project root without conversion. This is a conditional tooling report, not a required deployment procedure or a universal filename workaround. See the deployment discussion.
Common Questions
Why does a Salesforce CORS request return 404?
An origin that is not allowlisted receives HTTP status code 404. For a CORS request, an origin mismatch is therefore a possible cause, even when the requested resource exists.
Does a domain allowlist entry also cover its IP address?
No. A domain name and an IP address are different origins even when the domain resolves to that address. They need separate entries if both are used.
Can I allowlist Chrome and Firefox extension origins?
Yes. Chrome uses chrome-extension:// with a 32-character identifier containing no digits or uppercase letters. Firefox uses moz-extension:// with lowercase alphanumeric characters in an 8-4-4-4-12 grouping. These schemes are alternatives to HTTPS web origins.
How do I retrieve all CorsWhitelistOrigin entries?
Include CorsWhitelistOrigin in package.xml with * as the members value. In Metadata API format, the components reside in corswhitelistorigins and use the .corswhitelistorigin suffix.