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) <andrew@amorgan.xyz>
This commit is contained in:
Andrew Morgan 2018-02-27 03:42:10 -08:00 committed by Erik Johnston
parent 08274bab5a
commit dfcf31f293
2 changed files with 8 additions and 1 deletions

View File

@ -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,

View File

@ -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, "|")