From 203d55d2f72f5ff9df6be9870effdd80d008c6df Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 26 Mar 2026 10:48:35 -0400 Subject: [PATCH] refactor: Remove workarounds for matrix-appservice-irc --- src/api/client/account/mod.rs | 40 ++++++------------------------ src/api/client/account/register.rs | 23 +++-------------- 2 files changed, 11 insertions(+), 52 deletions(-) diff --git a/src/api/client/account/mod.rs b/src/api/client/account/mod.rs index dad027c5b..88181fac5 100644 --- a/src/api/client/account/mod.rs +++ b/src/api/client/account/mod.rs @@ -51,49 +51,23 @@ pub(crate) async fn get_register_available_route( InsecureClientIp(client): InsecureClientIp, body: Ruma, ) -> Result { - // workaround for https://github.com/matrix-org/matrix-appservice-irc/issues/1780 due to inactivity of fixing the issue - let is_matrix_appservice_irc = body.appservice_info.as_ref().is_some_and(|appservice| { - appservice.registration.id == "irc" - || appservice.registration.id.contains("matrix-appservice-irc") - || appservice.registration.id.contains("matrix_appservice_irc") - }); - - if services - .globals - .forbidden_usernames() - .is_match(&body.username) - { - return Err!(Request(Forbidden("Username is forbidden"))); - } - - // don't force the username lowercase if it's from matrix-appservice-irc - let body_username = if is_matrix_appservice_irc { - body.username.clone() - } else { - body.username.to_lowercase() - }; - // Validate user id let user_id = - match UserId::parse_with_server_name(&body_username, services.globals.server_name()) { + match UserId::parse_with_server_name(&body.username, services.globals.server_name()) { | Ok(user_id) => { if let Err(e) = user_id.validate_strict() { - // unless the username is from the broken matrix appservice IRC bridge, we - // should follow synapse's behaviour on not allowing things like spaces - // and UTF-8 characters in usernames - if !is_matrix_appservice_irc { - return Err!(Request(InvalidUsername(debug_warn!( - "Username {body_username} contains disallowed characters or spaces: \ - {e}" - )))); - } + return Err!(Request(InvalidUsername(debug_warn!( + "Username {} contains disallowed characters or spaces: {e}", + body.username + )))); } user_id }, | Err(e) => { return Err!(Request(InvalidUsername(debug_warn!( - "Username {body_username} is not valid: {e}" + "Username {} is not valid: {e}", + body.username )))); }, }; diff --git a/src/api/client/account/register.rs b/src/api/client/account/register.rs index 6aa034018..4d445f036 100644 --- a/src/api/client/account/register.rs +++ b/src/api/client/account/register.rs @@ -125,7 +125,6 @@ pub(crate) async fn register_route( let user_id = determine_registration_user_id( &services, body.username.clone(), - body.appservice_info.as_ref(), is_guest, emergency_mode_enabled, ) @@ -478,11 +477,10 @@ async fn create_registration_uiaa_session( async fn determine_registration_user_id( services: &Services, supplied_username: Option, - appservice_info: Option<&service::appservice::RegistrationInfo>, is_guest: bool, emergency_mode_enabled: bool, ) -> Result { - if let Some(mut supplied_username) = supplied_username + if let Some(supplied_username) = supplied_username && !is_guest { // The user gets to pick their username. Do some validation to make sure it's @@ -498,18 +496,6 @@ async fn determine_registration_user_id( return Err!(Request(Forbidden("Username is forbidden"))); } - // Workaround for https://github.com/matrix-org/matrix-appservice-irc/issues/1780 due to inactivity of fixing the issue - let is_matrix_appservice_irc = appservice_info.is_some_and(|appservice| { - appservice.registration.id == "irc" - || appservice.registration.id.contains("matrix-appservice-irc") - || appservice.registration.id.contains("matrix_appservice_irc") - }); - - // Don't force the username lowercase if it's from matrix-appservice-irc. - if !is_matrix_appservice_irc { - supplied_username = supplied_username.to_lowercase(); - } - // Create and validate the user ID let user_id = match UserId::parse_with_server_name( &supplied_username, @@ -517,10 +503,9 @@ async fn determine_registration_user_id( ) { | Ok(user_id) => { if let Err(e) = user_id.validate_strict() { - // unless the username is from the broken matrix appservice IRC bridge, or - // we are in emergency mode, we should follow synapse's behaviour on + // Unless we are in emergency mode, we should follow synapse's behaviour on // not allowing things like spaces and UTF-8 characters in usernames - if !is_matrix_appservice_irc && !emergency_mode_enabled { + if !emergency_mode_enabled { return Err!(Request(InvalidUsername(debug_warn!( "Username {supplied_username} contains disallowed characters or \ spaces: {e}" @@ -550,7 +535,7 @@ async fn determine_registration_user_id( Ok(user_id) } else { - // The user is a guest or is lacking in creativity. Generate a username for + // The user is a guest or didn't specify a username. Generate a username for // them. loop {