From ea7ba3e9696af2a894eeafb2dcbdb9caacbe5453 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Mar 2020 14:35:00 +0000 Subject: [PATCH 1/3] 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( From de8a1aa5dac5cff9575fda39b82c5cc7e0abb715 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Mar 2020 16:09:15 +0000 Subject: [PATCH 2/3] Revert "Turn the chosen username to lowercase" This reverts commit ea7ba3e9696af2a894eeafb2dcbdb9caacbe5453. --- matrix_synapse_saml_mozilla/res/script.js | 4 +--- matrix_synapse_saml_mozilla/username_picker.py | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/matrix_synapse_saml_mozilla/res/script.js b/matrix_synapse_saml_mozilla/res/script.js index 7704ecf..1fa4e39 100644 --- a/matrix_synapse_saml_mozilla/res/script.js +++ b/matrix_synapse_saml_mozilla/res/script.js @@ -65,9 +65,7 @@ let submitUsername = function(username) { return; } - // 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()}); + let check_uri = 'check?' + buildQueryString({"username": username}); 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 36f7854..7990d4b 100644 --- a/matrix_synapse_saml_mozilla/username_picker.py +++ b/matrix_synapse_saml_mozilla/username_picker.py @@ -155,8 +155,6 @@ 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( From 5764c5361cb808c956ec0f5dd5837803870edfaa Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Mar 2020 16:09:46 +0000 Subject: [PATCH 3/3] Remove uppercase from allowed chars and prettify the error message --- matrix_synapse_saml_mozilla/res/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matrix_synapse_saml_mozilla/res/script.js b/matrix_synapse_saml_mozilla/res/script.js index 1fa4e39..ab97438 100644 --- a/matrix_synapse_saml_mozilla/res/script.js +++ b/matrix_synapse_saml_mozilla/res/script.js @@ -36,13 +36,13 @@ let onResponse = function(response, success) { }; // We allow upper case characters here, but then lowercase before sending to the server -let allowedUsernameCharacters = RegExp("[^a-zA-Z0-9\\.\\_\\=\\-\\/]"); +let allowedUsernameCharacters = RegExp("[^a-z0-9\\.\\_\\=\\-\\/]"); let usernameIsValid = function(username) { return !allowedUsernameCharacters.test(username); } let allowedCharactersString = "" + -"a-z, " + -"0-9, " + +"lowercase letters, " + +"digits, " + "., " + "_, " + "-, " +