Worker fetch to a hostname on your own zone fails with error 1042

Add the global_fetch_strictly_public compatibility flag so outbound fetches to hostnames on your own account resolve like a public client would.

Workers

· Chapter

1

·

2

min read

The answer. When a Worker calls fetch() on a hostname that belongs to a zone on the same Cloudflare account, the subrequest is routed internally through Cloudflare instead of leaving as a public request, and the edge rejects it with error 1042 ("tried to fetch another Worker"). The request never reaches the origin. Fix: add global_fetch_strictly_public to compatibility_flags. The global fetch() then resolves every hostname the way an outside client would.

The pattern.

# wrangler.toml
name = "my-api"
main = "src/index.ts"
compatibility_date = "2026-04-01"
# Without this, fetch() to a hostname on your own account is routed
# internally and can die with edge error 1042 before leaving Cloudflare.
compatibility_flags = ["nodejs_compat", "global_fetch_strictly_public"]
// Probe Worker: deploy once without the flag, once with it, compare.
export default {
  async fetch(_req: Request) {
    const r = await fetch("https://automation.example.com/webhook/ping");
    return new Response(`upstream ${r.status}`);
  },
};

The receipt. In our API Worker, July 2026: dispatch to the self-hosted n8n instance (a hostname on the same account, different zone) started failing as "n8n returned 503" with an empty body. The VPS never logged a request; the 503 was the edge's translation of a 1042. An isolated probe Worker reproduced it cleanly: 1042 without the flag, 200 with it. The flag shipped on 2026-07-25 and dispatch recovered on that deploy. Side effect: our release-contract test builds the expected Worker config from wrangler.toml, and a hard-coded fixture hadn't been told about the new flag. It was one of two fixture drifts behind 122 red release tests, cleared on 2026-07-27.

Watch out.

  • The symptom looks like the upstream's fault. Before debugging the origin, check whether it saw the request at all.
  • Anything that diffs deployed config against the repo (release gates, contract tests) treats a new flag as drift. Update the fixture in the same commit.
  • If you actually want Worker-to-Worker calls, use a Service Binding. The flag doesn't change that.

Related: production-canary-version-pinned-cutover · cache-api-poisoned-by-transient-error