2

Is there a way to block chrome or firefox from accessing anything located at localhost?

I built my web application on top of a LAMP stack @ localhost and it's kind of big (for me) and I would like to test it, but when I access site.com it loads all the resources that are linked on http://localhost/ because they are on my machine but it doesnt load those resources when I try to access the website from another computer.

So, I need to test the application and it would be nice to just block localhost completely.

A workaround I found was using a proxy addon in firefox and blacklisting http://localhost/* but it's extremely slow because the proxies are free.

So I would like to find a way to just block localhost completely in any of these browsers and that would make my life much easier.

3

Reading your post I got the impression that the website you are building uses absolute URLs to http://localhost/some.html If this is true, please fix your application to use relative URLs like some.html or /site.html.

If my impression was wrong and you still want to block localhost from your browser, you could misuse the "proxy auto-config" feature in your browser. Save the following into a local file (say, ~/proxy.pac):

function FindProxyForURL(url, host)
{
  if (isInNet(host, "127.0.0.1", "255.255.255.255"))
    {return "PROXY 127.0.0.1:65535";}
  if (dnsDomainIs(host, "localhost"))
    {return "PROXY 127.0.0.1:65535";}
  else
    {return "DIRECT";}
}

In Firefox, go to Preferences/Advanced/Network/Connection Settings... Choose "Automatic proxy configuration URL" and specify the full path for the saved file. The browser will try to use a SOCKS proxy at 127.0.0.1:65535 that does not exist and will fail reading any local files through http or https.

1
  • It looks like the latest Firefox ignores the proxy configuration for localhost. – Mikalai Daronin Jun 18 '19 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.