Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix domain socket SOCKS proxy support #47

Closed
randomstuff opened this issue Dec 6, 2023 · 5 comments
Closed

Unix domain socket SOCKS proxy support #47

randomstuff opened this issue Dec 6, 2023 · 5 comments
Labels

Comments

@randomstuff
Copy link

randomstuff commented Dec 6, 2023

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,
  };
}
@randomstuff randomstuff changed the title Unix domain support Unix domain socket SOCKS proxy support Dec 6, 2023
@ericjung
Copy link
Contributor

ericjung commented Dec 6, 2023

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.

@erosman erosman added the area: socks SOCKS issues label Dec 6, 2023
@randomstuff
Copy link
Author

randomstuff commented Dec 6, 2023

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
Copy link
Author

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
Copy link
Collaborator

erosman commented Dec 6, 2023

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

True.....

On Firefox, FoxyProxy checks the selected option:

  • pattern -> sends to proxy.onRequest
  • host:port -> sends to proxy.onRequest
  • URL (i.e. it has :// in it) -> regards it as PAC URL & sends to proxy.settings

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. 🤔

@erosman
Copy link
Collaborator

erosman commented Dec 6, 2023

Fixed for v8.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants