summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2021-12-20 11:00:13 -0500
committerGitHub <noreply@github.com>2021-12-20 16:00:13 +0000
commit3e0cfd447e17658a937fe62555db9e968f00b15b (patch)
tree130630430c28cddc5a41fb8ec4c1a0ddd4cdf496
parentUse mock from standard library (#11588) (diff)
downloadsynapse-3e0cfd447e17658a937fe62555db9e968f00b15b.tar.xz
Return JSON errors for unknown resources under /matrix/client. (#11602)
Instead of returning 404 errors with HTML bodies when an unknown
prefix was requested (e.g. /matrix/client/v1 before Synapse v1.49.0).
-rw-r--r--changelog.d/11602.bugfix1
-rw-r--r--synapse/app/homeserver.py9
-rw-r--r--synapse/http/server.py6
3 files changed, 6 insertions, 10 deletions
diff --git a/changelog.d/11602.bugfix b/changelog.d/11602.bugfix
new file mode 100644
index 0000000000..e0dfbf1a15
--- /dev/null
+++ b/changelog.d/11602.bugfix
@@ -0,0 +1 @@
+Fix a long-standing bug that some unknown endpoints would return HTML error pages instead of JSON `M_UNRECOGNIZED` errors.
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index dd76e07321..177ce040e8 100644
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -27,6 +27,7 @@ import synapse
 import synapse.config.logger
 from synapse import events
 from synapse.api.urls import (
+    CLIENT_API_PREFIX,
     FEDERATION_PREFIX,
     LEGACY_MEDIA_PREFIX,
     MEDIA_R0_PREFIX,
@@ -192,13 +193,7 @@ class SynapseHomeServer(HomeServer):
 
             resources.update(
                 {
-                    "/_matrix/client/api/v1": client_resource,
-                    "/_matrix/client/r0": client_resource,
-                    "/_matrix/client/v1": client_resource,
-                    "/_matrix/client/v3": client_resource,
-                    "/_matrix/client/unstable": client_resource,
-                    "/_matrix/client/v2_alpha": client_resource,
-                    "/_matrix/client/versions": client_resource,
+                    CLIENT_API_PREFIX: client_resource,
                     "/.well-known": well_known_resource(self),
                     "/_synapse/admin": AdminRestResource(self),
                     **build_synapse_client_resource_tree(self),
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 4fd5660a08..7bbbe7648b 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -530,7 +530,7 @@ class RootRedirect(resource.Resource):
     """Redirects the root '/' path to another path."""
 
     def __init__(self, path: str):
-        resource.Resource.__init__(self)
+        super().__init__()
         self.url = path
 
     def render_GET(self, request: Request) -> bytes:
@@ -539,7 +539,7 @@ class RootRedirect(resource.Resource):
     def getChild(self, name: str, request: Request) -> resource.Resource:
         if len(name) == 0:
             return self  # select ourselves as the child to render
-        return resource.Resource.getChild(self, name, request)
+        return super().getChild(name, request)
 
 
 class OptionsResource(resource.Resource):
@@ -556,7 +556,7 @@ class OptionsResource(resource.Resource):
     def getChildWithDefault(self, path: str, request: Request) -> resource.Resource:
         if request.method == b"OPTIONS":
             return self  # select ourselves as the child to render
-        return resource.Resource.getChildWithDefault(self, path, request)
+        return super().getChildWithDefault(path, request)
 
 
 class RootOptionsRedirectResource(OptionsResource, RootRedirect):