-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unhandled error in connectproxyclient.py (503 status response from CONNECT proxy) #15883
Comments
To explain plainly what's going on, this just means your Tor proxy is returning
Not being able to |
Agreed with MadLittleMods here; this is an error coming from your proxy I'm afraid (503 = Service Unavailable). If you search around for '503 tor privoxy' you can see a few people having similar problems with other applications. I'm afraid I can't really help you out with this; but as a basic sanity check you might want to try and see whether |
It shouldn't matter if the error is 503 from privoxy or 404 from http server, Synapse just shouldn't just raise |
If your forward proxy is not working, this is as bad as e.g. the database not working and I don't see why Synapse should not raise critical errors for that — indeed, this is something that, on a heavy production service, you'd want to be woken up for in order to fix. I don't currently see how this would lead to security issues — do you have any more information on that? |
Who said it's not working? I said explicitly:
It's perfectly normal situation that some network connections fail. This shouldn't cause a critical error inside the library handling the connection, such connections should be retried or closed gracefully. Unhandled errors are a well-identified anti-pattern of system design. I couldn't tell you what specific attack vector (if any) is possible due to this specific mistake, you should probably ask for a code review if you wish to know more. More on the topic: https://owasp.org/www-community/Improper_Error_Handling |
A related issue, but I'm not creating a ticket for this today, is that when synapse receives an inbound connection from |
Your logs are showing that the proxy is giving a 503 error, which is not how a proxy should operate normally. This is why I say it's not working. |
To summarise, I think there are three points in this report.
We agree on 1. We are not particularly convinced by 2. I doubt there is a performance cost---this is Python, and exceptions are being raised internally all the time. I also don't see how there is a security problem. Your OWASP link recommends not failing open and not presenting error messages to users; AFAICS Synapse does neither of these things in this situation. On 3: fair enough. There may be some better way to drive twisted here. It looks like synapse/synapse/http/connectproxyclient.py Lines 169 to 173 in 1c802de
would be the natural place to attempt a reCONNECT. (Do you see the debug message in your logs?) Unfortunately the core team is unlikely to find the time to improve this. We would gladly review a PR which reproduces the problem in a test case and finds a better way to handle the CONNECT failure. |
A 2-kB error message (as shown above) is occurring on average 60k times on my log daily, yielding 120 MB of critical error logs daily, just because of connection errors. I'd say that just spamming the logfile is a plausible attack vector on availability of the instance - a malicious agent could create a network of instances that will attract such connections and cause enormous disk space usage. Also, it forces a reasonable homeserver admin like myself to either disable logging completely (this is a critical loglevel after all) or work with log files that are not at all informative as consist mostly of those unwanted log entries. Now this was just a security side, I don't have to tell you how silly it looks.
Debug logs follow (another occurrence of the issue though, synapse 1.91, python 3.11 and such, redacted with XXX):
Now, I'm not really an expert on synapse federation protocols, but from what I understand, it does some level on retrying of its own, that's why I'm getting these messages daily. Since I enabled debug for a moment, I'm observing a lot of:
Perhaps this one should observe the connection error and stop trying to reach the instance that can't understand connections incoming from Tor. I suppose this also causes a lot of messages in the instances that receive such connections. The only PR, if any I can provide at this point, would be to catch and ignore this level intentionally, as an INFO message. |
Connection errors to your proxy are a critical fault though; if something critical like that happens you'd want to know about it as in theory it might be indicating that federation is not working at all. Of course it's not ideal to have logs fill your disk but in this instance it seems like it should be justifiable, because something is actually wrong. |
I've tried to summarise what I think we should do about this in #16462 to save future people from having to make sense of this thread. That issue supersedes this one. |
Description
Hundreds of critical log entries claiming an error wasn't handled in either:
synapse/http/connectproxyclient.py
twisted/web/http.py
twisted/protocols/basic.py
synapse/http/connectproxyclient.py
twisted/internet/tcp.py
My instance is being blocked by some other ones, or they are simply unreachable/out of order. This doesn't cause any errors when I'm not using proxy, I suppose the error should be handled in a lower layer and not cause a critical log entry with all the call stack. I also observe performance degradation because of these errors.
Steps to reproduce
Homeserver
my own homeserver
Synapse Version
{"server":{"name":"Synapse","version":"1.87.0"}}
Installation Method
Debian packages from packages.matrix.org
Database
Single PostgreSQL, ported with portdb, never restored from a backup
Workers
Single process
Platform
Linux 6.1.0-9-amd64 Debian 6.1.27-1 x86_64 GNU/Linux
Configuration
Configured to support Tor connections by adding this to the systemd service definition:
Running privoxy on port 8118 with the config including:
Running tor on port 9050 with the config including:
Using Tor for DNS resolution, in
/etc/resolv.conf
:And the
homeserver.yaml
includes:Relevant log output
Anything else that would be useful to know?
Using caddy as reverse proxy, no delegation.
Further config details and rationale in: #5152 (this is not a tor2tor instance but a regular one plus proxy).
Tried to investigate and patch it myself but twisted is not too straight.
The text was updated successfully, but these errors were encountered: