foxyproxy / browser-extension

Version 8 and above. Browser extension source code for Firefox, Chrome, and other Chromium-based browsers
GNU General Public License v2.0
199 stars 29 forks source link

Unix domain socket SOCKS proxy support #47

Closed randomstuff closed 6 months ago

randomstuff commented 7 months ago

On Firefox, FoxyProxy Classic supports configuring SOCKS proxy over Unix domain sockets. This is done by configuring a host of the form file:///path/to/socket. The port is ignored.

This does not seems to be working anymore with the new version of FoxyProxy. Using a Unix domain socket SOCKS proxy actually works with proxy.onRequest():

browser.proxy.onRequest.addListener(handleProxyRequest, {urls: ["<all_urls>"]});

function handleProxyRequest(requestInfo) {
  return {
    type: "socks",
    host: "file:///run/user/1000/proxy.socks",
    port: 9999,
    proxyDNS: true,
  };
}
ericjung commented 7 months ago

I'm trying to run your project based on the README so that I can attempt some rudimentary debugging. I'm on linux mint machine

In one terminal:

  ./soxidizer "/run/user/1000/soxidizer.socks" --directory "/run/user/1000/publish"
  2023-12-06T02:09:35.728160Z  INFO soxidizer: Listening to Unix domain socket /run/user/1000/soxidizer.socks

in another:

flask run --host=unix:///run/user/1000/publish/app.foo.localhost_80

 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Traceback (most recent call last):
  File "/usr/bin/flask", line 33, in <module>
    sys.exit(load_entry_point('Flask==2.0.1', 'console_scripts', 'flask')())
  File "/usr/lib/python3/dist-packages/flask/cli.py", line 990, in main
    cli.main(args=sys.argv[1:])
  File "/usr/lib/python3/dist-packages/flask/cli.py", line 596, in main
    return super().main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/flask/cli.py", line 849, in run_command
    run_simple(
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 1010, in run_simple
    inner()
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 950, in inner
    srv = make_server(
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 782, in make_server
    return ThreadedWSGIServer(
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 688, in __init__
    super().__init__(server_address, handler)  # type: ignore
  File "/usr/lib/python3.10/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/lib/python3.10/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.10/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
FileNotFoundError: [Errno 2] No such file or directory
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 153, in apport_excepthook
    with os.fdopen(os.open(pr_filename,
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_bin_flask.1000.crash'

Original exception was:
Traceback (most recent call last):
  File "/usr/bin/flask", line 33, in <module>
    sys.exit(load_entry_point('Flask==2.0.1', 'console_scripts', 'flask')())
  File "/usr/lib/python3/dist-packages/flask/cli.py", line 990, in main
    cli.main(args=sys.argv[1:])
  File "/usr/lib/python3/dist-packages/flask/cli.py", line 596, in main
    return super().main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/flask/cli.py", line 849, in run_command
    run_simple(
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 1010, in run_simple
    inner()
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 950, in inner
    srv = make_server(
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 782, in make_server
    return ThreadedWSGIServer(
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 688, in __init__
    super().__init__(server_address, handler)  # type: ignore
  File "/usr/lib/python3.10/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/lib/python3.10/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.10/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
FileNotFoundError: [Errno 2] No such file or directory

I know the flask app is working because I can run it normally with flask run, visit http://127.0.0.1:5000, and see the webpage.

What do I need to do?

Also, is it possible you can share your FoxyProxy settings (new FoxyProxy) so I can see how you've configured it? There's an export option.

randomstuff commented 7 months ago

You can actually reproduce the issue independently of my project. The link to my project was there as a reference on how to configure a Unix-domain-socket SOCKS proxy.

Apparently the issue happens only when not using "proxy by patterns". In the following screenshots, I'm configuring the usage of a proxy which is not running.

Configuring a non-existent 127.0.0.1 proxy without patterns results in connection failure (i.e. the proxy is used):

image

Configuring a non-existent /tmp/test.socks SOCKS proxy without patterns results in working communications (i.e. the proxy is not used):

image

Configuring a non-existent 127.0.0.1 SOCKS proxy by patterns results in connection failure (i.e. the proxy is used):

image

Configuring a non-existent /tmp/test.socks SOCKS proxy by patterns results in connection failure (i.e. the proxy is used):

image

randomstuff commented 7 months ago

The error you are seeing when running flask might be because the /run/user/1000/publish directory is absent? When the directory is absent I am getting this error:

$ flask run --host=unix:///run/user/1000/publish/app.foo.localhost_80
 * Debug mode: off
No such file or directory

Fixed with:

$ mkdir /run/user/1000/publish/
$ flask run --host=unix:///run/user/1000/publish/app.foo.localhost_80
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on unix:///run/user/1000/publish/app.foo.localhost_80
Press CTRL+C to quit
erosman commented 7 months ago

Apparently the issue happens only when not using "proxy by patterns".

True.....

On Firefox, FoxyProxy checks the selected option:

In this particular case, file:///run/user/1000/proxy.socks is seen as PAC URL.

As we have seen in #49, file:/// can also be used as PAC URL in Firefox (has issues on Chrome). It is easy to fix, but we have to make sure it wont create other issues. :thinking:

erosman commented 7 months ago

Fixed for v8.3