Closed Bug 1800222 Opened 3 years ago Closed 3 years ago

Built-in way to "spoof" DNS records like /etc/hosts

Categories

(Core :: Networking: DNS, enhancement)

Firefox 106
enhancement

Tracking

()

RESOLVED WONTFIX

People

(Reporter: coding, Unassigned)

Details

(Keywords: ux-control, ux-efficiency)

Expected results:

When moving a website to a new server (with another IP address) I always need to edit my hosts file (/etc/hosts on Linux) to point the domain to the new IP to test if everything works on the new server environment.

Sometimes Firefox doesn't pick that change up reliably, most often it requires a restart. Sometimes I need to compare things between the old and the new environment so I need to switch the line in the hosts file back and forth, always requiring a browser restart and there's no way to compare the environments side-by-side.

As it's not possible to intercept DNS via Browser extension I wish there would be a native way to add DNS Record overwrites to point a Domain to a specific IP. Maybe via DevTools or even better as a toolbar icon.
It would be perfect to be able to enable specific overwrites per tab. A less perfect solution would be per window or per not-private and private windows.

It should be somehow visible that the current Domain has a "spoofed" DNS, maybe via a different address bar color.

I just noticed "a different address bar color" wouldn't be a good way to show it as it may not look good with different themes.
But a button like the "Not secure" button for webpages with invalid https would be a nice way.

The Bugbug bot thinks this bug should belong to the 'Firefox::Address Bar' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Address Bar
Component: Address Bar → Toolbars and Customization
OS: Unspecified → All
Hardware: Unspecified → All

This report is a mixture between giving the possibility to add-ons to work as DNS and wondering why changing /etc/hosts is not immediately reflected...
The former sounds a bit scary to me, from a security point of view, an add-on could basically replace your dns and point you to copies of sites... not that today is impossible to do, but that'd make it trivial.

The Network question about dns cache, is more fit for the network component.

Component: Toolbars and Customization → Networking: DNS
Product: Firefox → Core

No, I DON'T want addons to be able to do this. Exactly for security reasons. That's why I'm asking for feature directly built into Firefox (that's what I meant with native).

It would be very helpful to be able to have two (or more) browser tabs with the same domain open, but the different Tabs point to different IPs, so we can compare the page in different environments, for example after an update or while migrating a page to a new server.

Summary: Native way to "spoof" DNS records like /etc/hosts → Built-in way to "spoof" DNS records like /etc/hosts

So, we already have the ability to override the native DNS results in firefox using https://searchfox.org/mozilla-central/source/netwerk/dns/nsINativeDNSResolverOverride.idl - we mostly use this for testing, but presumably they could be used for other reasons too :)
@Rafael, you can also do this in the browser console executing something like this:

Cc["@mozilla.org/network/native-dns-override;1"]
  .getService(Ci.nsINativeDNSResolverOverride)
  .addIPOverride("example.com", "127.0.0.1");

As to the reason why the browser sometimes doesn't pick up changes to /etc/hosts - that's a function of the operating system. We just call getaddrinfo and the system resolver takes care of checking /etc/hosts. You may want to restart your resolver or something.

Also, make sure you're not using DNS over HTTPS (set the network.trr.mode pref to 0 or 5) otherwise we might not be calling into the system resolver at all.

Adding UI for this in Firefox seems a bit niche. If anyone thinks this has a place in Firefox (maybe devtools), we can reopen this bug.

Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.