skip to content

An internal Cloudflare billing Worker must be reachable only through service bindings; which Wrangler settings keep it off the internet, and how does it know which Worker called it?

level: seniorimportance: should knowfreq 30%

answer

  1. workers.dev is on by default
  2. preview URLs are a second door
  3. no routes, no custom domains
  4. config wins over the dashboard
  5. props set by the deployer

basics

~20 s

Set workers_dev and preview_urls to false and configure no routes or custom domains, in the Wrangler file so every deploy keeps them. The Worker identifies callers by ctx.props, which each caller's binding sets and only those allowed to deploy the billing Worker can change.

solid answer

~50 s

A Worker with no `routes` gets a public `<name>.<subdomain>.workers.dev` URL, because `workers_dev` defaults to `true` when no route is configured. So the billing Worker's Wrangler file sets `"workers_dev": false`, and also `"preview_urls": false`: turning off workers.dev does not turn off Version and Preview URLs, and for an existing Worker an omitted `preview_urls` keeps whatever setting it already has. It declares no `routes`, `route` or custom domain, and the settings live in config because a dashboard-only change is undone by the next `wrangler deploy`. Reachability then comes only from bindings, and a binding can only target a Worker on the same account. To know the caller, each caller's binding sets `props`, such as `{ "caller": "gateway" }`, which the callee reads as `this.ctx.props`; Workers only lets someone allowed to edit and deploy the receiving Worker set it, so it needs no signature. Named entrypoints narrow what each caller can invoke.

code

json · 7 lines
json
{
  "name": "billing-worker",
  "main": "src/index.js",
  "compatibility_date": "2026-10-01",
  "workers_dev": false,
  "preview_urls": false
}

go deeper

for a junior

Recall that a Worker gets a public workers.dev URL by default, and that workers_dev set to false in the Wrangler file turns it off.

for a middle

Explain every door: workers.dev, Version and Preview URLs, routes and custom domains, and why preview_urls must be set as well as workers_dev.

for a senior

Show the review you would run: settings in config rather than the dashboard, bindings limited to the account, and ctx.props plus named entrypoints to identify and limit callers.

for a principal

Name the trust boundary: once no public URL exists, account deploy rights decide who can bind, so govern those rights and the props each binding carries.

## Every public door a Worker can have A Worker that is meant to be internal can still be exposed in several ways. Each is closed by a different setting: | Exposure | Default | How to close it | |---|---|---| | `<name>.<subdomain>.workers.dev` | on when the config has no `route` or `routes` | `"workers_dev": false` | | Version URLs and Preview URLs | for a new Worker, follows `workers_dev`; if omitted later, the existing setting is kept | `"preview_urls": false` | | Routes on a zone | none unless configured | declare no `route` or `routes` | | Custom Domains | none unless configured | attach none | Two traps sit in that table: - **workers.dev is on by default.** A Worker with no routes gets a public `workers.dev` URL on deploy unless `workers_dev` is `false`. Adding `routes` makes Wrangler infer `false`, but an internal Worker has no routes, so it must say so explicitly. - **Preview URLs are a separate switch.** Disabling the `workers.dev` route does not disable Version URLs or Preview URLs, which are served on `workers.dev` hostnames too. If a team only adds `"workers_dev": false` to a Worker that already has Preview URLs enabled, they stay enabled, and in an interactive deploy Wrangler warns: `You are disabling the 'workers.dev' subdomain for this Worker, but Preview URLs are still enabled.` That warning is skipped in CI, so the config must carry `"preview_urls": false`. ## Keep the settings in the Wrangler file Disabling workers.dev in the dashboard alone does not last: if the Wrangler file does not say `"workers_dev": false`, the `workers.dev` route is **re-enabled on the next deploy** with Wrangler. The Wrangler file is the source of truth for every door in the table, so a deploy from CI cannot quietly reopen one. The same goes for routes: when routes are changed in the dashboard, the next deploy overwrites them with the ones in the Wrangler file. ## Who can reach the billing Worker after that With no public URL, the only way in is a **service binding**, and a binding's `service` must name a Worker **on the same Cloudflare account**. Nothing on the callee lists allowed callers: any Worker deployed to that account can declare a binding to `billing-worker`. So the real boundary is **who holds deploy rights on the account**, and the billing Worker still needs to know which caller it is serving. ## Identifying the caller with ctx.props A binding entry can carry `props`, an arbitrary JSON value. The callee reads it as `this.ctx.props` in a `WorkerEntrypoint` (or `ctx.props` in a handler): 1. The gateway's binding sets `"props": { "caller": "gateway", "scopes": ["charge"] }`. 2. The billing Worker's `BillingApi` checks `this.ctx.props.caller` and `scopes` before charging. 3. A reporting Worker's binding sets its own `props` with read-only scopes and binds to a `ReportsApi` entrypoint. The platform is designed so that `ctx.props` can only be set by someone with permission to edit and deploy the Worker it is delivered to, so its content is authentic and needs **no shared secret or signature**. Combined with **named entrypoints**, which give each caller only the methods of the class it binds to, this gives a small, auditable permission model inside one account. Two related facts: - **Cloudflare Access does not propagate through bindings.** If the gateway sits behind Access, its `ctx.access` identity does not reach the billing Worker over HTTP or RPC. Pass the end user's identity explicitly as arguments, and treat it as the gateway's claim. - **A Worker that also keeps a public URL** cannot rely on `ctx.props` for those requests; internet traffic carries no props. Keep internal and public entry points in separate Workers, or authenticate the public path separately. ## A review checklist for an internal Worker - `workers_dev` is `false` and `preview_urls` is `false` in the Wrangler file. Both keys are inheritable, so setting them at the top level covers every Wrangler environment, unless an environment block overrides one back to `true`; check each block. - No `route`, `routes` or custom domain is configured. - Each caller binds to a named entrypoint with only the methods it needs. - Each binding sets `props` that the callee checks before doing privileged work. - Deploy rights on the account are limited to the people trusted to change those bindings.

  • Someone disabled the billing Worker's workers.dev URL in the dashboard, yet it was public again a week later. What happened?
    A deploy with Wrangler re-enabled it. When the Wrangler file does not say `"workers_dev": false`, the next `wrangler deploy` applies the default, which is `true` for a Worker with no routes. Put `"workers_dev": false` and `"preview_urls": false` in the config so every deploy, including CI, keeps the Worker private.
  • Should the billing Worker also check a shared-secret header from the gateway?
    For calls through a binding it adds little: `ctx.props` comes from the caller's deployed configuration, and the platform is designed so only people allowed to edit and deploy the receiving Worker can set it, so it is authentic without a secret or signature. A secret check earns its keep mainly on a path that internet traffic can reach, which an internal Worker should not have.
  • The gateway runs behind Cloudflare Access. Can the billing Worker read the signed-in user from `ctx.access`?
    No. Access does not propagate `ctx.access` from one Worker to another, over HTTP or RPC. The gateway must pass the user's identity explicitly, for example as an argument to `charge()`, and the billing Worker should treat it as the gateway's assertion, trusting it because `ctx.props` says the call came from the gateway.

  • A Worker with no routes is unreachable from the internet.
  • Setting workers_dev to false also turns off its Preview URLs and Version URLs.
  • Disabling workers.dev in the dashboard stays in effect across later deploys.
  • Any Worker on any Cloudflare account can bind to the billing Worker by name.
  • ctx.props must carry an HMAC signature because a caller could forge it at runtime.
  • The gateway's Cloudflare Access identity reaches the bound Worker automatically.

Assumes Wrangler 4.44 or later (4.149 pinned): an omitted preview_urls follows workers_dev for a new Worker and keeps an existing setting otherwise; earlier Wrangler 4 releases defaulted it to true, then to false.