summary refs log tree commit diff
path: root/synapse/federation
diff options
context:
space:
mode:
authorHubert Chathi <hubertc@matrix.org>2022-05-18 06:19:30 -0400
committerGitHub <noreply@github.com>2022-05-18 11:19:30 +0100
commit8afb7b55d0527f8c6af7690b162ebaabe9b5d9f5 (patch)
treee2c360534b4a76cea7c928c3177d458a6cb261ca /synapse/federation
parentMove methods that call add_push_rule to PushRuleStore (#12772) (diff)
downloadsynapse-8afb7b55d0527f8c6af7690b162ebaabe9b5d9f5.tar.xz
Make handling of federation Authorization header (more) compliant with RFC7230 (#12774)
The main differences are:
- values with delimiters (such as colons) should be quoted, so always
  quote the origin, since it could contain a colon followed by a port
  number
- should allow more than one space after "X-Matrix"
- quoted values with backslash-escaped characters should be unescaped
- names should be case insensitive
Diffstat (limited to 'synapse/federation')
-rw-r--r--synapse/federation/transport/server/_base.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/synapse/federation/transport/server/_base.py b/synapse/federation/transport/server/_base.py
index 103861644a..84100a5a52 100644
--- a/synapse/federation/transport/server/_base.py
+++ b/synapse/federation/transport/server/_base.py
@@ -169,14 +169,16 @@ def _parse_auth_header(header_bytes: bytes) -> Tuple[str, str, str, Optional[str
     """
     try:
         header_str = header_bytes.decode("utf-8")
-        params = header_str.split(" ")[1].split(",")
+        params = re.split(" +", header_str)[1].split(",")
         param_dict: Dict[str, str] = {
-            k: v for k, v in [param.split("=", maxsplit=1) for param in params]
+            k.lower(): v for k, v in [param.split("=", maxsplit=1) for param in params]
         }
 
         def strip_quotes(value: str) -> str:
             if value.startswith('"'):
-                return value[1:-1]
+                return re.sub(
+                    "\\\\(.)", lambda matchobj: matchobj.group(1), value[1:-1]
+                )
             else:
                 return value