|
| 1 | +--- |
| 2 | +pcx_content_type: concept |
| 3 | +title: Worker Isolation |
| 4 | +sidebar: |
| 5 | + order: 1 |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +### Untrusted Mode (Default) |
| 10 | + |
| 11 | +By default, Workers inside of a dispatch namespace are considered "untrusted." This provides the strongest isolation between Workers and is best in cases where your customers have control over the code that's being deployed. |
| 12 | + |
| 13 | +In untrusted mode: |
| 14 | + |
| 15 | +- The [`request.cf`](/workers/runtime-apis/request/#incomingrequestcfproperties) object is not available in Workers (see [limits](/cloudflare-for-platforms/workers-for-platforms/platform/limits/#cf-object) for more information) |
| 16 | +- Each Worker has an isolated cache, when using the [Cache API](/workers/runtime-apis/cache/) or when making subrequests using `fetch()`, which egress via [Cloudflare's cache](/cache/) |
| 17 | +- [`caches.default`](/workers/reference/how-the-cache-works/#cache-api) is disabled for all Workers in the namespace |
| 18 | + |
| 19 | +This mode ensures complete isolation between customer Workers, preventing any potential cross-tenant data access. |
| 20 | + |
| 21 | +### Trusted Mode |
| 22 | + |
| 23 | +If you control the Worker code and want to disable isolation mode, you can configure the namespace as "trusted". This is useful when building internal platforms where your company controls all Worker code. |
| 24 | + |
| 25 | +In trusted mode: |
| 26 | + |
| 27 | +- The [`request.cf`](/workers/runtime-apis/request/#incomingrequestcfproperties) object becomes available, providing access to request metadata |
| 28 | +- All Workers in the namespace share the same cache space when using the Cache API |
| 29 | + |
| 30 | +:::note |
| 31 | +In trusted mode, Workers can potentially access cached responses from other Workers in the namespace. Only enable this if you control all Worker code or have appropriate cache key isolation strategies. |
| 32 | +::: |
| 33 | + |
| 34 | +To convert a namespace from untrusted to trusted: |
| 35 | +```bash |
| 36 | +curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/dispatch/namespaces/{namespace_name}" \ |
| 37 | + -H "Authorization: Bearer {api_token}" \ |
| 38 | + -H "Content-Type: application/json" \ |
| 39 | + -d '{ |
| 40 | + "name": "{namespace_name}", |
| 41 | + "trusted_workers": true |
| 42 | + }' |
| 43 | + ``` |
| 44 | + |
| 45 | +If you enable trusted mode for a namespace that already has deployed Workers, you'll need to redeploy those Workers for the `request.cf` object to become available. Any new Workers you deploy after enabling trusted mode will automatically have access to it. |
| 46 | + |
| 47 | +### Maintaining cache isolation in trusted mode |
| 48 | +If you need access to `request.cf` but want to maintain cache isolation between customers, use customer-specific [cache keys](/workers/examples/cache-using-fetch/#custom-cache-keys) or the [Cache API](/workers/examples/cache-api/) with isolated keys. |
| 49 | + |
| 50 | +## Related Resources |
| 51 | +* [Platform Limits](/cloudflare-for-platforms/workers-for-platforms/platform/limits) - Understanding script and API limits |
| 52 | +* [Cache API Documentation](/workers/runtime-apis/cache/) - Learn about cache behavior in Workers |
| 53 | +* [Request cf object](/workers/runtime-apis/request/#the-cf-property-requestcf) - Details on the cf object properties |
0 commit comments