Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions proxy/http/proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,10 @@ def wrap_client(self) -> None:

def authenticate(self) -> None:
if self.flags.auth_code:
if b'proxy-authorization' not in self.request.headers or \
self.request.headers[b'proxy-authorization'][1] != self.flags.auth_code:
if b'proxy-authorization' not in self.request.headers:
raise ProxyAuthenticationFailed()
parts = self.request.headers[b'proxy-authorization'][1].split()
if len(parts) != 2 and parts[0].lower() != b'basic' and parts[1] != self.flags.auth_code:
raise ProxyAuthenticationFailed()

def connect_upstream(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def initialize(input_args: Optional[List[str]], **opts: Any) -> Flags:
# Generate auth_code required for basic authentication if enabled
auth_code = None
if args.basic_auth:
auth_code = b'Basic %s' % base64.b64encode(bytes_(args.basic_auth))
auth_code = base64.b64encode(bytes_(args.basic_auth))

return Flags(
plugins=plugins,
Expand Down
9 changes: 3 additions & 6 deletions tests/http/test_protocol_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ def test_proxy_authentication_failed(
self._conn = mock_fromfd.return_value
self.mock_selector_for_client_read(mock_selector)
flags = Flags(
auth_code=b'Basic %s' %
base64.b64encode(b'user:pass'))
auth_code=base64.b64encode(b'user:pass'))
flags.plugins = Proxy.load_plugins([
b'proxy.http.proxy.HttpProxyPlugin',
b'proxy.http.server.HttpWebServerPlugin',
Expand Down Expand Up @@ -208,8 +207,7 @@ def test_authenticated_proxy_http_get(
server.buffer_size.return_value = 0

flags = Flags(
auth_code=b'Basic %s' %
base64.b64encode(b'user:pass'))
auth_code=base64.b64encode(b'user:pass'))
flags.plugins = Proxy.load_plugins([
b'proxy.http.proxy.HttpProxyPlugin',
b'proxy.http.server.HttpWebServerPlugin',
Expand Down Expand Up @@ -258,8 +256,7 @@ def test_authenticated_proxy_http_tunnel(
mock_selector, server)

flags = Flags(
auth_code=b'Basic %s' %
base64.b64encode(b'user:pass'))
auth_code=base64.b64encode(b'user:pass'))
flags.plugins = Proxy.load_plugins([
b'proxy.http.proxy.HttpProxyPlugin',
b'proxy.http.server.HttpWebServerPlugin'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_basic_auth(
mock_acceptor_pool.assert_called_once()
self.assertEqual(
flgs.auth_code,
b'Basic dXNlcjpwYXNz')
b'dXNlcjpwYXNz')

@mock.patch('time.sleep')
@mock.patch('builtins.print')
Expand Down