<@U04UQ68083H> Adding CORS domains
# ory-copilot
b
@chilly-king-10285 Adding CORS domains
b
A message from kapa.ai
To add CORS domains in Ory Network, you need to configure the allowed origins for your project. Here’s how you can do it: 1. Via Ory Console (UI): - Go to your project in the [Ory Console](https://console.ory.sh/). - Navigate to BrandingCustom domains. - Add your custom domain and specify the CORS origins you want to allow. - Ory Network allows up to 50 origins. You can use wildcard subdomains (e.g.,
https://*.<http://yourdomain.com|yourdomain.com>
), but you cannot use
*
,
null
, or
localhost/127.0.0.1
as origins. For local development, use [Ory Tunnel](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel) instead of adding
localhost
directly as a CORS origin [Set up CORS for Ory Network](https://www.ory.sh/docs/guides/cors/), [Set up custom domains](https://www.ory.sh/docs/guides/custom-domains/). 2. Via Ory CLI: - You can enable and set CORS origins using the CLI with the following command:
Copy code
ory patch project <your-project-id> \        --replace '/cors_public/enabled=true' \        --replace '/cors_public/origins=["https://*.<http://yourdomain.com|yourdomain.com>"]'
- This command enables CORS and sets the allowed origins. For more details, see the [Ory CLI documentation](https://www.ory.sh/docs/guides/cli/config-with-cli#patch-configuration) [Set up CORS for Ory Network](https://www.ory.sh/docs/guides/cors/). 3. OAuth2 Client-Specific CORS: - For OAuth2 endpoints, you can also set per-client CORS origins in the OAuth2 client settings in the Ory Console. These settings are respected in addition to the global CORS settings [Set up CORS for Ory Network](https://www.ory.sh/docs/guides/cors/), [Setting up cross-origin resource sharing (CORS)](https://www.ory.sh/docs/hydra/guides/cors/). Note: - CORS is enabled by default on custom domains, but you must explicitly add the allowed origins. - For local development, use Ory Tunnel to proxy requests and handle CORS for
localhost
[Set up custom domains](https://www.ory.sh/docs/guides/custom-domains/). If you need more specific instructions for your use case (e.g., Kratos, Hydra, or Keto), let me know!
b
@chilly-king-10285 I want to allow requests to a custom dev domain
b
A message from kapa.ai
To allow requests to a custom dev domain in Ory Network, you need to add that domain as an allowed CORS origin in your project's settings. Here’s how you can do it: 1. Go to the Ory Console: Navigate to Branding → Custom domains in your project settings. 2. Add your custom dev domain: When configuring your custom domain, you can specify CORS origins. Enter your dev domain (e.g.,
<https://dev.yourdomain.com>
) in the list of allowed origins. 3. CORS Restrictions: - Ory Network does not allow
*
,
null
, or
localhost/127.0.0.1
as CORS origins. - You can use wildcard subdomains like
https://*.<http://yourdomain.com|yourdomain.com>
, but Ory recommends using exact matches for better security. - For local development with
localhost
, use [Ory Tunnel](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel) instead of adding
localhost
directly as a CORS origin. 4. Propagation: After updating your CORS settings, it may take some time for changes to propagate. The CORS status will show as "Inactive" while pending, and "Enabled" once active. You can update CORS settings independently of other custom domain settings [Set up custom domains](https://www.ory.sh/docs/guides/custom-domains/#waiting-for-propagation). Example: If your dev domain is
<https://dev.yourdomain.com>
, add this exact URL to the allowed CORS origins in the Ory Console. If you want to allow all subdomains, you can use
https://*.<http://yourdomain.com|yourdomain.com>
[Set up CORS for Ory Network](https://www.ory.sh/docs/guides/cors/), [Set up custom domains](https://www.ory.sh/docs/guides/custom-domains/). Note: If you encounter issues with CORS not being applied, ensure your domain is verified and active. There have been reports of CORS headers not being set correctly if the domain is still pending or if there are configuration issues [Cors doesn't seem to be activated with a custom domain on ory cloud](https://github.com/ory/network/issues/124). If you need to allow requests from a local development environment (e.g.,
localhost
), use Ory Tunnel for local development, as Ory Network does not allow
localhost
as a CORS origin [Set up CORS for Ory Network](https://www.ory.sh/docs/guides/cors/). Let me know if you need step-by-step instructions for a specific scenario!