Skip to content

Commit 34a8652

Browse files
Optional whitespace support in Authorization (#1350) (#17145)
Co-authored-by: Andrew Morgan <[email protected]>
1 parent 414ddcd commit 34a8652

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

changelog.d/17145.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for optional whitespace around the Federation API's `Authorization` header's parameter commas.

synapse/federation/transport/server/_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ def _parse_auth_header(header_bytes: bytes) -> Tuple[str, str, str, Optional[str
180180
"""
181181
try:
182182
header_str = header_bytes.decode("utf-8")
183-
params = re.split(" +", header_str)[1].split(",")
183+
space_or_tab = "[ \t]"
184+
params = re.split(
185+
rf"{space_or_tab}*,{space_or_tab}*",
186+
re.split(r"^X-Matrix +", header_str, maxsplit=1)[1],
187+
)
184188
param_dict: Dict[str, str] = {
185189
k.lower(): v for k, v in [param.split("=", maxsplit=1) for param in params]
186190
}

tests/federation/transport/server/test__base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,10 @@ def test_authorization_header(self) -> None:
147147
),
148148
("foo", "ed25519:1", "sig", "bar"),
149149
)
150+
# test that "optional whitespace(s)" (space and tabulation) are allowed between comma-separated auth-param components
151+
self.assertEqual(
152+
_parse_auth_header(
153+
b'X-Matrix origin=foo , key="ed25519:1", sig="sig", destination="bar", extra_field=ignored'
154+
),
155+
("foo", "ed25519:1", "sig", "bar"),
156+
)

0 commit comments

Comments
 (0)