From ea7ba3e9696af2a894eeafb2dcbdb9caacbe5453 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Mar 2020 14:35:00 +0000 Subject: [PATCH] Turn the chosen username to lowercase So that the user doesn't get dumped to a CSS-less error page telling them that the localpart doesn't match the regexp. --- matrix_synapse_saml_mozilla/res/script.js | 4 +++- matrix_synapse_saml_mozilla/username_picker.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/matrix_synapse_saml_mozilla/res/script.js b/matrix_synapse_saml_mozilla/res/script.js index 1fa4e39..7704ecf 100644 --- a/matrix_synapse_saml_mozilla/res/script.js +++ b/matrix_synapse_saml_mozilla/res/script.js @@ -65,7 +65,9 @@ let submitUsername = function(username) { return; } - let check_uri = 'check?' + buildQueryString({"username": username}); + // Since we're trying to register the username converted to lower case, check the + // availability with the right case. + let check_uri = 'check?' + buildQueryString({"username": username.toLowerCase()}); fetch(check_uri, { "credentials": "include", }).then((response) => { diff --git a/matrix_synapse_saml_mozilla/username_picker.py b/matrix_synapse_saml_mozilla/username_picker.py index 7990d4b..36f7854 100644 --- a/matrix_synapse_saml_mozilla/username_picker.py +++ b/matrix_synapse_saml_mozilla/username_picker.py @@ -155,6 +155,8 @@ class SubmitResource(AsyncResource): _return_html_error(400, "missing username", request) return localpart = request.args[b"username"][0].decode("utf-8", errors="replace") + # Convert the username to lower case. + localpart = localpart.lower() logger.info("Registering username %s", localpart) try: registered_user_id = await self._module_api.register_user(