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

Timeout in HTTP_Proxy.py throws an exception instead of correctly sending the client an error #252

Open
TheraNinjaCat opened this issue Oct 4, 2023 · 0 comments

Comments

@TheraNinjaCat
Copy link

When processing the socket errors in the HTTP proxy, when capturing the socket.error it attempts to index into the object, and if that fails (as it should always do for most error objects if my understanding is correct) then it will attempt to send the error object itself into self.send_error, however this method is expecting a single line string (i.e. "Not Found", "Bad Request", or "Internal Server Error") rather than an error object, so it attempts to use a string method (s.replace) which causes another error.

In this specific example it is also attempting to send a 404 response for a socket timeout, where potentially it should be sending a 504 Gateway Timeout (I'm not familiar with the code, but as this module is called HTTP_Proxy.py I'm assuming this error occurs when the upstream connection fails so this feels more accurate)

----------------------------------------
<ip> - - [05/Oct/2023 10:35:36] code 404, message [Errno 110] Connection timed out
<ip> - - [05/Oct/2023 10:35:36] "CONNECT mtalk.google.com:5228 HTTP/1.1" 404 -
----------------------------------------
Exception occurred during processing of request from ('<ip>', 60475, 0, 0)
Traceback (most recent call last):
  File "/usr/share/responder/servers/HTTP_Proxy.py", line 221, in _connect_to
    try: soc.connect(host_port)
         ^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/socketserver.py", line 691, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.11/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.11/socketserver.py", line 755, in __init__
    self.handle()
  File "/usr/share/responder/servers/HTTP_Proxy.py", line 213, in handle
    self.__base_handle()
  File "/usr/lib/python3.11/http/server.py", line 436, in handle
    self.handle_one_request()
  File "/usr/lib/python3.11/http/server.py", line 424, in handle_one_request
    method()
  File "/usr/share/responder/servers/HTTP_Proxy.py", line 248, in do_CONNECT
    if self._connect_to(self.path, soc):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/responder/servers/HTTP_Proxy.py", line 225, in _connect_to
    self.send_error(404, msg)
  File "/usr/lib/python3.11/http/server.py", line 482, in send_error
    'message': html.escape(message, quote=False),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/html/__init__.py", line 19, in escape
    s = s.replace("&", "&amp;") # Must be done first!
        ^^^^^^^^^
AttributeError: 'TimeoutError' object has no attribute 'replace'
----------------------------------------

except socket.error as arg:
try: msg = arg[1]
except: msg = arg
self.send_error(404, msg)
return 0

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

No branches or pull requests

1 participant