21

On Linux I'm starting chrome as google-chrome --proxy-server=127.0.0.1:8888 --proxy-bypass-list="" however it's still not using the proxy for localhost requests.

How can I force chrome to use my proxy for localhost?

You may wonder why I wanna do this, I'm trying to record all the requests, using jmeter, to an application running on local environment.

4 Answers4

7

Finally I've found a tricky solution for this. It was clear from the beginning that this is a browser issue, since I was able to make requests with curl --proxy.

The trick is that the DNS resolution also happens through the proxy, therefore on the remote machine. So just add a new entry to your remote /etc/hosts file:

127.0.0.1       local

Then you can access the remote "localhost" on your local machine, since Chrome knows nothing about this new host name. For example by: http://local:8080/mysite.

6

You were almost there, but the answer lies in the Chromium docs for the bypass option you were using. You need to subtract the defaults by adding a dash in front of whatever you want to remove, which in this case is the loopback interface, which is literally written <loopback>.

Whereas regular bypass rules instruct the browser about URLs that should not use the proxy, this rule has the opposite effect and tells the browser to instead use the proxy.

The full parameter is --proxy-bypass-list="<-loopback>"

A little bit unfortunate that this is not mentioned or linked up from the Network Settings page for Chromium ...

oligofren
  • 1,426
  • 1
  • 25
  • 41
3

For Windows10, this is a System issue, that localhost will always goto current PC, and won't go through proxy.

U can set this in the OS's proxy setting to force localhost go proxy.

  • Open the OS's proxy setting
  • Ensure your proxy server(host & port) are set.
  • Below, there will be a input for you, says Use the proxy server except for address that start with the following entries. Use semicolons(;) to separate entries
  • Add <-loopback> into that input.
  • Save.

Then your request of localhost to go under proxy.

Note:

  • Though broswers will bypass localhost by default, the CMD will work even without this setting. curl -x http://{proxyserIp}:{proxyPort} http://localhost:3000
  • If u r using some browser extension(like SwitchyOmega), u can also add <-loopback into it's Bypass list, this still works.

refer: https://docs.microsoft.com/en-us/archive/blogs/fiddler/fiddler-and-the-ie9-release-candidate https://stackoverflow.com/questions/37700079/how-to-intercept-local-server-web-requests-using-burp-in-internet-explorer

-1

If you are using mitmproxy or charles to debug localhost requests, try using Chrome 69 in macos with system proxy set.