From dfcf31f293a319830e2b8a188413db776930a5e5 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Tue, 27 Feb 2018 03:42:10 -0800 Subject: [PATCH] Prevent AS user check if no AS registered (#392) When a user registered on a homeserver with no application services registered, registration would check if the meta-regexp object matched the proposed user's new username. Apparently "" is a regex that matches everything, so every user was then barred from registering as they were supposedly registering inside an AS' exclusive namespace. This change prevents that check from happening by setting the exclusive regex to ^$ instead, preventing any matches from occurring. We also prevent the check for exclusivity if there are no namespaces registered for performance. Signed-off-by: Andrew Morgan (https://amorgan.xyz) --- .../matrix-org/dendrite/clientapi/routing/register.go | 3 ++- .../matrix-org/dendrite/common/config/appservice.go | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go index 107344c3..77e875ec 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go @@ -381,8 +381,9 @@ func Register( } // Make sure normal user isn't registering under an exclusive application - // service namespace + // service namespace. Skip this check if no app services are registered. if r.Auth.Type != "m.login.application_service" && + len(cfg.Derived.ApplicationServices) != 0 && cfg.Derived.ExclusiveApplicationServicesUsernameRegexp.MatchString(r.Username) { return util.JSONResponse{ Code: 400, diff --git a/src/github.com/matrix-org/dendrite/common/config/appservice.go b/src/github.com/matrix-org/dendrite/common/config/appservice.go index 72efafac..b57e9d06 100644 --- a/src/github.com/matrix-org/dendrite/common/config/appservice.go +++ b/src/github.com/matrix-org/dendrite/common/config/appservice.go @@ -113,6 +113,12 @@ func setupRegexps(cfg *Dendrite) { // regex and deny access if it isn't from an application service exclusiveUsernames := strings.Join(exclusiveUsernameStrings, "|") + // If there are no exclusive username regexes, compile string so that it + // will not match any valid usernames + if exclusiveUsernames == "" { + exclusiveUsernames = "^$" + } + // TODO: Aliases and rooms. Needed? //exclusiveAliases := strings.Join(exclusiveAliasStrings, "|") //exclusiveRooms := strings.Join(exclusiveRoomStrings, "|")