How to Fix Cloudflare Workers Error 1042: “Worker tried to fetch from another Worker on the same domain”

How to Fix Cloudflare Workers Error 1042: “Worker tried to fetch from another Worker on the same domain”

If you’ve ever tried to have two Cloudflare Workers call each other (e.g., Worker A → Worker B → Worker A, or even just Worker A calling Worker B on the same zone), you’ve probably hit the dreaded Error 1042:

Worker tried to fetch from another Worker on the same domain, which is disallowed for security reasons.


This restriction exists to prevent infinite request loops and potential abuse, but sometimes you legitimately need one Worker to fetch from another (microservices-style architecture, shared logic, etc.).

The Fix: Enable the global_fetch_strictly_public Compatibility Flag

Cloudflare provides an opt-in flag that relaxes this restriction and allows Workers to fetch each other as long as the request goes to a public hostname (i.e., your custom domain or *.pages.dev, not a workers.dev subdomain that is private).

Step-by-step:

  1. Log into the Cloudflare dashboard.
  2. Go to Workers & Pages → select your Worker → SettingsRuntime.
  3. Scroll down to Compatibility flags.
  4. Add the flag: global_fetch_strictly_public
  5. Click Deploy (or Save & Deploy).

Do this for both Workers (the one making the request and the one being requested).

That’s it!

Important Notes

  • The flag only allows fetches to public hostnames. Example that works: fetch("https://api.yourdomain.com/some-path") Example that still fails: fetch("https://my-worker.my-subdomain.workers.dev") if that workers.dev URL is not public.
  • Always use your custom domain (or a public *.pages.dev) for inter-Worker communication after enabling the flag.
  • Reference: Cloudflare Docs – global_fetch_strictly_public

Once the flag is enabled on both sides, your Worker-to-Worker fetches will work without Error 1042.

Happy building! 🚀

The Best Shopify Growth Course Online Today

Stuck with sales or starting a new ecommerce shop? Take your Shopify store to the next level. Our comprehensive online course is expertly crafted to equip you with the skills, tools, and knowledge you need to boost your store’s sales and make a real-world impact

Leave a comment

Please note, comments need to be approved before they are published.

Tags

Thank You For Reading Our Articles!

We're committed to delivering real answers, valuable insights, and efficient knowledge online. Join us by subscribing, sharing, and engaging with our community to make a difference!