summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan de Jong <jonathandejong02@gmail.com>2020-09-17 12:54:56 +0200
committerGitHub <noreply@github.com>2020-09-17 11:54:56 +0100
commit53284c425e219fbd9ae445bbe4a8628883a3631d (patch)
treeb3f920c760fe967bc9367ce45fb184af1b2eea9f
parentSwitch metaclass initialization to python 3-compatible syntax (#8326) (diff)
downloadsynapse-53284c425e219fbd9ae445bbe4a8628883a3631d.tar.xz
Fix a potential bug of UnboundLocalError (#8329)
Replaced with less buggier control flow
-rw-r--r--changelog.d/8329.bugfix1
-rw-r--r--synapse/rest/client/v2_alpha/register.py13
2 files changed, 9 insertions, 5 deletions
diff --git a/changelog.d/8329.bugfix b/changelog.d/8329.bugfix
new file mode 100644
index 0000000000..2f71f1f4b9
--- /dev/null
+++ b/changelog.d/8329.bugfix
@@ -0,0 +1 @@
+Fix UnboundLocalError from occuring when appservices send malformed register request.
\ No newline at end of file
diff --git a/synapse/rest/client/v2_alpha/register.py b/synapse/rest/client/v2_alpha/register.py
index b6b90a8b30..0705718d00 100644
--- a/synapse/rest/client/v2_alpha/register.py
+++ b/synapse/rest/client/v2_alpha/register.py
@@ -431,11 +431,14 @@ class RegisterRestServlet(RestServlet):
 
             access_token = self.auth.get_access_token_from_request(request)
 
-            if isinstance(desired_username, str):
-                result = await self._do_appservice_registration(
-                    desired_username, access_token, body
-                )
-            return 200, result  # we throw for non 200 responses
+            if not isinstance(desired_username, str):
+                raise SynapseError(400, "Desired Username is missing or not a string")
+
+            result = await self._do_appservice_registration(
+                desired_username, access_token, body
+            )
+
+            return 200, result
 
         # == Normal User Registration == (everyone else)
         if not self._registration_enabled: