How does Caddy DNS work? How is foo.bar.localhost resolving? Is this Chrome-specific magic?

I just started using Caddy, and couldn’t find this elsewhere. I started with this:

*.bar.localhost {
	reverse_proxy localhost:1337
}

And to my amazement, https://foo.bar.localhost/ resolves in Chrome, correctly proxied to http://localhost:1337! Firefox also resolves (though doesn’t accept the cert - a separate issue).

However, curl https://foo.bar.localhost reports “Cannot resolve host” (as expected).

But how does foo.bar.localhost resolve to anything in Chrome/Firefox? Does Caddy install its own DNS server somehow? Does it have some magic browser integration?

1 Like

I think modern browsers now resolve anything .localhost to 127.0.0.1 or ::1. Some OSes do this as well now with their system resolvers.

From a quick search, Firefox added support for this in this commit Bug 1220810 - Hardcode localhost to loopback, r=ckerschb,necko-review… · mozilla/gecko-dev@70d15af · GitHub

See here:

2 Likes

There’s an IETF draft about this topic:

1 Like

@francislavoie aha, thank you! So yeah, it turns out foo.bar.localhost resolves to 127.0.0.1 in Chrome and Firefox, and has done for quite a while - I just discovered this feature after installing Caddy, which is why I thought it was some dark magic in Caddy.

This browser override of standard DNS disturbs me a bit, but I must admit it’s convenient …

1 Like