websockify
websockify copied to clipboard
LibProxyServer incorrectly overwrites token_plugin and auth_plugin with None in __init__
Title: [Bug] LibProxyServer incorrectly overwrites token_plugin and auth_plugin with None in init
Issue Body:
Description
When using the --libserver option (LibProxyServer), configured plugins passed via --token-plugin or --auth-plugin are extracted from kwargs in LibProxyServer.__init__ but are immediately overwritten with None.
This causes plugin-related features to fail silently when running under the SocketServer engine:
- If an authentication plugin is specified with
--libserver --auth-plugin=...(or--web-auth),self.server.auth_pluginevaluates toNone, causingProxyRequestHandler.auth_connection()to exit early and bypass authentication. - If a token plugin is specified with
--libserver --token-plugin=...,self.server.token_pluginevaluates toNone, causingProxyRequestHandler.validate_connection()to skip token lookup and fail downstream connections.
Location
File: websockify/websocketproxy.py (Lines 779–786)
class LibProxyServer(ThreadingMixIn, HTTPServer):
"""
Just like WebSocketProxy, but uses standard Python SocketServer
framework.
"""
def __init__(self, RequestHandlerClass=ProxyRequestHandler, **kwargs):
# Save off proxy specific options
self.target_host = kwargs.pop('target_host', None)
self.target_port = kwargs.pop('target_port', None)
self.wrap_cmd = kwargs.pop('wrap_cmd', None)
self.wrap_mode = kwargs.pop('wrap_mode', None)
self.unix_target = kwargs.pop('unix_target', None)
self.ssl_target = kwargs.pop('ssl_target', None)
self.token_plugin = kwargs.pop('token_plugin', None)
self.auth_plugin = kwargs.pop('auth_plugin', None)
self.heartbeat = kwargs.pop('heartbeat', None)
self.token_plugin = None
self.auth_plugin = None
self.daemon = False
### Root Cause
- kwargs.pop('token_plugin', None) and kwargs.pop('auth_plugin', None) properly retrieve the instantiated plugin instances configured during CLI initialization (websockify_init()).
- Lines 783–784 re-assign both self.token_plugin = None and self.auth_plugin = None, discarding the valid plugin objects.
Steps to Reproduce
- Start websockify with an authentication plugin and --libserver:
`websockify --libserver --auth-plugin=BasicHTTPAuth --auth-source="user:pass" 8080 target_host:target_port`
- Inspect server.auth_plugin on the instantiated LibProxyServer object or send a client connection request.
- Observe that server.auth_plugin is None instead of the instantiated BasicHTTPAuth object.
Expected Behavior
LibProxyServer should retain the token_plugin and auth_plugin values extracted from kwargs, matching the behavior of WebSocketProxy.
Proposed Fix
Remove the redundant None reassignments in websockify/websocketproxy.py:
diff
--- a/websockify/websocketproxy.py
+++ b/websockify/websocketproxy.py
@@ -780,8 +780,6 @@ class LibProxyServer(ThreadingMixIn, HTTPServer):
self.auth_plugin = kwargs.pop('auth_plugin', None)
self.heartbeat = kwargs.pop('heartbeat', None)
- self.token_plugin = None
- self.auth_plugin = None
self.daemon = False
# Server configuration