From 84963af916f38c22c3847c7f533f8ce6f5f4524d Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 31 Oct 2019 11:31:35 +0000 Subject: [PATCH 1/6] rstrip slashes from url on appservice On many occasions users have written registration files that contain an ending slash. Synapse already prefixes every request with a slash and this tends to trip up users more often than not. It seems wise here to just remove any trailing slashes on initiation. --- synapse/appservice/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 33b357942578..24bd9ea8546f 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -94,7 +94,7 @@ def __init__( ip_range_whitelist=None, ): self.token = token - self.url = url + self.url = url.rstrip("/") # url must not end with a slash self.hs_token = hs_token self.sender = sender self.server_name = hostname From aefb86a35af4822abb7c1384690a671951394b02 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 31 Oct 2019 11:34:29 +0000 Subject: [PATCH 2/6] newsfile --- changelog.d/6306.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6306.bugfix diff --git a/changelog.d/6306.bugfix b/changelog.d/6306.bugfix new file mode 100644 index 000000000000..c7dcbcdce84a --- /dev/null +++ b/changelog.d/6306.bugfix @@ -0,0 +1 @@ +Appservice requests will no longer contain a double slash prefix when the appservice url provided ends in a slash. From 2103d5788dbca732bd32f0a9a01b154cfd2cad0f Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 31 Oct 2019 11:39:59 +0000 Subject: [PATCH 3/6] space --- synapse/appservice/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 24bd9ea8546f..c9a95f65486a 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -94,7 +94,7 @@ def __init__( ip_range_whitelist=None, ): self.token = token - self.url = url.rstrip("/") # url must not end with a slash + self.url = url.rstrip("/") # url must not end with a slash self.hs_token = hs_token self.sender = sender self.server_name = hostname From 21464f46da0e4a96ad4b71ca92c6a8eed4283669 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 31 Oct 2019 13:18:08 +0000 Subject: [PATCH 4/6] only strip if url is a string --- synapse/appservice/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index c9a95f65486a..404f256a13f7 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -94,7 +94,7 @@ def __init__( ip_range_whitelist=None, ): self.token = token - self.url = url.rstrip("/") # url must not end with a slash + self.url = None if url is None else url.rstrip("/") # url must not end with a slash self.hs_token = hs_token self.sender = sender self.server_name = hostname From 95bd2319d4aafe6f0c7588deded2e95c7d6180f2 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 31 Oct 2019 16:09:04 +0000 Subject: [PATCH 5/6] Update __init__.py --- synapse/appservice/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 404f256a13f7..6add28965a0c 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -94,7 +94,9 @@ def __init__( ip_range_whitelist=None, ): self.token = token - self.url = None if url is None else url.rstrip("/") # url must not end with a slash + self.url = ( + None if url is None else url.rstrip("/") + ) # url must not end with a slash self.hs_token = hs_token self.sender = sender self.server_name = hostname From 68c89b9e2b164fce331edc194b3697997395d215 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 31 Oct 2019 16:31:16 +0000 Subject: [PATCH 6/6] Update synapse/appservice/__init__.py Co-Authored-By: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- synapse/appservice/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 6add28965a0c..aea3985a5f48 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -95,7 +95,7 @@ def __init__( ): self.token = token self.url = ( - None if url is None else url.rstrip("/") + url.rstrip("/") if isinstance(url, str) else None ) # url must not end with a slash self.hs_token = hs_token self.sender = sender