Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix http/s proxy authentication with long username/passwords #16504

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions changelog.d/16504.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in Synapse 1.41 where HTTP(S) forward proxy authorization would fail when using basic HTTP authentication with a long `username:password` string.
2 changes: 1 addition & 1 deletion synapse/http/connectproxyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def as_proxy_authorization_value(self) -> bytes:
a Proxy-Authorization header.
"""
# Encode as base64 and prepend the authorization type
return b"Basic " + base64.encodebytes(self.username_password)
return b"Basic " + base64.b64encode(self.username_password)
clokep marked this conversation as resolved.
Show resolved Hide resolved


@attr.s(auto_attribs=True)
Expand Down
14 changes: 14 additions & 0 deletions tests/http/test_proxyagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ def test_parse_proxy(
)


class TestBasicProxyCredentials(TestCase):
def test_long_user_pass_string_encoded_without_newlines(self) -> None:
"""Reproduces https://github.com/matrix-org/synapse/pull/16504."""
creds = BasicProxyCredentials(
b"looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonguser:[email protected]:9988"
)
auth_value = creds.as_proxy_authorization_value()
self.assertNotIn(b"\n", auth_value)
self.assertEqual(
creds.as_proxy_authorization_value(),
b"Basic: bG9vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vbmd1c2VyOnBhc3M=",
clokep marked this conversation as resolved.
Show resolved Hide resolved
)


class MatrixFederationAgentTests(TestCase):
def setUp(self) -> None:
self.reactor = ThreadedMemoryReactorClock()
Expand Down
Loading