Hardly Working with Cloudflare Workers
Apologies for the missing documentation on `resolveOverride`; it seems they were accidentally lost during our recent rewrite of the docs. I actually fixed this last week (in response to a support request which I imagine came from you?). You can now find the feature properly documented here:<p><a href="https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;workers&#x2F;runtime-apis&#x2F;request" rel="nofollow">https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;workers&#x2F;runtime-apis&#x2F;reque...</a><p>The reason we don&#x27;t allow setting the `Host` header different from the hostname used for routing purposes has nothing to do with &quot;The Web Platform&quot;, but rather is important to protect the security of other Cloudflare customers specifically.<p>Cloudflare customers rely on Cloudflare to block attacks directed at their origin server. This only works if the attacker cannot simply bypass Cloudflare and talk to the origin directly. So, origins need to verify that requests actually came through Cloudflare. The best way to do that is to use Argo Tunnel or Authenticated Origin Pulls (with a unique customer-provided keypair). However, many customers instead rely on firewalling their origin so that it only accepts traffic from Cloudflare&#x27;s IP ranges.<p>The problem with this is that anyone can sign up for a Cloudflare account and plug in your origin&#x27;s IP address as their own. Then, when they send requests to their domain through Cloudflare, those requests will be sent to your origin -- coming from Cloudflare IPs! We have no way to authenticate that the origin IP address actually belongs to the customer.<p>The main thing that mitigates this attack is that the requests will end up having the `Host` header set to the attacker&#x27;s domain, not yours. So if your origin server only accepts requests with a `Host` header it recognizes, then you are OK.<p>Now enter Workers. Workers allow customers to make requests to anywhere on the internet -- from Cloudflare IPs! If the request is directed to another Cloudflare customer, though, we&#x27;ll treat it as a request coming from the internet, and apply that other customer&#x27;s security settings. So this does not allow an attacker to bypass Cloudflare&#x27;s security protections on other customers&#x27; domains. But if the attacker could make a request to their own origin, while rewriting the `Host` header to match the victim&#x27;s hostname, then they could set the victim&#x27;s origin as their own as described above, while bypassing the `Host` header mitigation. We can&#x27;t allow that.<p>`resolveOverride`, however, only works when fetching to hostnames within your own zone, essentially allowing you to rewrite your host&#x27;s DNS mapping on the fly. Since you already have the power to modify your own DNS, this does not give an attacker any new capabilities. Meanwhile, it solves most use cases where people want to rewrite the `Host` header.<p>==========================<p>All that said, it&#x27;s not clear to me if your use case needs Workers. Could you have configured the DNS entry for www.peergrade.io to be a CNAME of peergrade.wpengine.com? That would cause Cloudflare to forward requests to peergrade.wpengine.com while still having `Host: www.peergrade.io`, which seems like what you want?<p>==========================<p>FWIW, the reason we chose &quot;The Web Platform&quot; instead of Node is because web APIs are described by standards that are intended to have multiple implementations, whereas Node&#x27;s APIs are defined by their implementation. We can&#x27;t literally use Node.js&#x27;s implementation because it isn&#x27;t a sandbox and it doesn&#x27;t scale to support thousands of tenants on a single machine, which are both critical to the edge compute use case. So, to support Node, we would have to re-implement the Node APIs from scratch. This is something we&#x27;re considering doing in the future, but it was much easier to get started implementing standardized web APIs.