diff --git a/changelog.d/2533.bugfix.md b/changelog.d/2533.bugfix.md new file mode 100644 index 000000000..39b0092fb --- /dev/null +++ b/changelog.d/2533.bugfix.md @@ -0,0 +1 @@ +Fixed the experiments implementation in #2517 not properly disabling some functionality when associated experiments weren't enabled. diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 8319443bf..6f723c83e 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -2666,6 +2666,26 @@ # and consequently know why you should enable them. +# MSC3814: Dehydrated devices with SSSS +# +# Enables server-side support for "dehydrated devices", which are +# server-side devices (created by supporting clients) that can collect +# encryption keys when there are no online devices, which supporting +# clients can then "hydrate" to download any encryption keys that were +# sent while they were offline. +# +# Important: this is NOT required to receive encrypted messages while you +# are offline. Devices can still receive encrypted messages while they are +# offline, but to share those keys with new devices, they have to be +# online. Dehydrated devices work around this by providing a "shared" +# device new sessions can bootstrap from, to receive keys from before they +# logged in that haven't been uploaded to the server-side key backup yet. +# +# https://github.com/matrix-org/matrix-spec-proposals/pull/3814 +# +# env: CONTINUWUITY_EXPERIMENTS__MSC3814 +#msc3814 = false + # MSC4155: Invite filtering # # Provides advanced invite filtering rules for users, allowing complex @@ -2690,6 +2710,24 @@ # env: CONTINUWUITY_EXPERIMENTS__MSC4174 #msc4174 = false +# MSC4406: `M_SENDER_IGNORED` error code +# +# Introduces a new error code that explicitly informs clients the reason +# they cannot access an event if it is sent by an ignored user. Without +# this proposal, clients will simply get a "not found" or "forbidden" +# error when requesting events sent by users that have been ignored, which +# leads to replies being shown as "this message could not be found". +# The new error code allows clients to distinguish unknown/forbidden +# events from ignored senders, allowing them to display an error message +# like "you have blocked this sender" instead. +# +# Requires a supporting client to be useful. +# +# https://github.com/matrix-org/matrix-spec-proposals/pull/4406 +# +# env: CONTINUWUITY_EXPERIMENTS__MSC4406 +#msc4406 = false + # MSC4484: Server Administration OAuth Scope # # Adds a new OAuth2 scope that explicitly grants a token temporary diff --git a/src/api/client/capabilities.rs b/src/api/client/capabilities.rs index d5d6e9f56..5851fb9bc 100644 --- a/src/api/client/capabilities.rs +++ b/src/api/client/capabilities.rs @@ -1,7 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use axum::extract::State; -use conduwuit::{Result, Server}; +use conduwuit::{Result, Server, config::experiments::ToggledExperiment}; use ruma::{ RoomVersionId, api::{ @@ -53,8 +53,11 @@ pub(crate) async fn get_capabilities_route( capabilities.account_moderation.lock = true; capabilities.account_moderation.suspend = true; - capabilities.admin = - AdminCapability::new(BTreeSet::from_iter([OAuthClientScope::ServerAdministration])); + if services.config.experiments.msc4484.is_enabled() { + capabilities.admin = AdminCapability::new(BTreeSet::from_iter([ + OAuthClientScope::ServerAdministration, + ])); + } } capabilities.profile_fields = Some( @@ -63,7 +66,10 @@ pub(crate) async fn get_capabilities_route( capabilities.set( "org.matrix.msc4174.webpush", - json!({ "enabled": true, "vapid": services.pusher.webpush_vapid_public_key() }), + json!({ + "enabled": services.config.experiments.msc4174.is_enabled(), + "vapid": services.pusher.webpush_vapid_public_key() + }), )?; Ok(get_capabilities::v3::Response::new(capabilities)) diff --git a/src/api/client/message.rs b/src/api/client/message.rs index bcaf7cfe9..2bb3cbbc0 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -1,6 +1,8 @@ use axum::extract::State; use conduwuit::{ - Err, Error, Result, at, debug_warn, + Err, Error, Result, at, + config::experiments::ToggledExperiment, + debug_warn, matrix::{ event::{Event, Matches}, pdu::PduCount, @@ -315,21 +317,29 @@ where if server_ignored { // the sender's server is ignored, so ignore this event - return Err(Error::BadRequest( - ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()), - "The sender's server is ignored by this server.", - )); + return if services.config.experiments.msc4406.is_enabled() { + Err(Error::BadRequest( + ErrorKind::SenderIgnored(SenderIgnoredErrorData::new()), + "The sender's server is ignored by this server.", + )) + } else { + Err!(Request(NotFound("This event's sender's homeserver is ignored by this server."))) + }; } if user_ignored && !services.config.send_messages_from_ignored_users_to_client { // the recipient of this PDU has the sender ignored, and we're not // configured to send ignored messages to clients - return Err(Error::BadRequest( - ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender( - event.sender().to_owned(), - )), - "You have ignored this sender.", - )); + return if services.config.experiments.msc4406.is_enabled() { + Err(Error::BadRequest( + ErrorKind::SenderIgnored(SenderIgnoredErrorData::with_sender( + event.sender().to_owned(), + )), + "You have ignored this sender.", + )) + } else { + Err!(Request(NotFound("You have ignored the sender of this event."))) + }; } Ok(false) diff --git a/src/api/router.rs b/src/api/router.rs index d666c0ba7..50f1ac254 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -10,7 +10,7 @@ use axum::{ response::{IntoResponse, Redirect}, routing::{any, get}, }; -use conduwuit::err; +use conduwuit::{config::experiments::ToggledExperiment, err}; pub(super) use conduwuit_service::state::State; use http::{Uri, uri}; @@ -162,10 +162,6 @@ pub fn build(router: Router, state: State) -> Router { .ruma_route(&client::update_device_route) .ruma_route(&client::delete_device_route) .ruma_route(&client::delete_devices_route) - .ruma_route(&client::put_dehydrated_device_route) - .ruma_route(&client::delete_dehydrated_device_route) - .ruma_route(&client::get_dehydrated_device_route) - .ruma_route(&client::get_dehydrated_events_route) .ruma_route(&client::get_tags_route) .ruma_route(&client::update_tag_route) .ruma_route(&client::delete_tag_route) @@ -184,7 +180,6 @@ pub fn build(router: Router, state: State) -> Router { .ruma_route(&client::get_mutual_rooms_unstable_route) .ruma_route(&client::get_mutual_rooms_route) .ruma_route(&client::get_room_summary) - .ruma_route(&client::get_stripped_state_route) .ruma_route(&client::get_suspended_status) .ruma_route(&client::put_suspended_status) .ruma_route(&client::get_lock_status) @@ -199,6 +194,16 @@ pub fn build(router: Router, state: State) -> Router { .route("/_continuwuity/server_version", get(client::continuwuity_server_version)) .ruma_route(&admin::rooms::ban::ban_room) .ruma_route(&admin::rooms::list::list_rooms); + if config.experiments.msc3814.is_enabled() { + router = router + .ruma_route(&client::put_dehydrated_device_route) + .ruma_route(&client::delete_dehydrated_device_route) + .ruma_route(&client::get_dehydrated_device_route) + .ruma_route(&client::get_dehydrated_events_route); + } + if config.experiments.msc4560.is_enabled() { + router = router.ruma_route(&client::get_stripped_state_route); + } if config.allow_prometheus_metrics { router = router.route("/_continuwuity/metrics", get(client::continuwuity_metrics)); @@ -233,11 +238,13 @@ pub fn build(router: Router, state: State) -> Router { .ruma_route(&server::get_keys_route) .ruma_route(&server::claim_keys_route) .ruma_route(&server::get_hierarchy_route) - .ruma_route(&server::get_stripped_state_route) .ruma_route(&server::well_known_server) .ruma_route(&server::get_content_route) .ruma_route(&server::get_content_thumbnail_route) .route("/_continuwuity/local_user_count", get(client::continuwuity_local_user_count)); + if config.experiments.msc4560.is_enabled() { + router = router.ruma_route(&server::get_stripped_state_route); + } } else { router = router .route("/_matrix/federation/{*path}", any(federation_disabled)) diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index 543910cba..0569ebfbf 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -5,7 +5,9 @@ use std::{ }; use conduwuit::{ - Err, Error, Result, err, + Err, Error, Result, + config::experiments::ToggledExperiment, + err, utils::{IterStream, millis_since_unix_epoch}, }; use http::StatusCode; @@ -338,17 +340,19 @@ async fn check_access_token( .map(Box::new); // Make sure the user has the right scopes to use the route - let user_scopes = if let Some(session_info) = &session_info { + let mut user_scopes = if let Some(session_info) = &session_info { session_info.scopes() } else { - let mut scopes = BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]); - - if services.admin.user_is_admin(&sender_user).await { - scopes.insert(OAuthClientScope::ServerAdministration); - } - - scopes + BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]) }; + if (!services.config.experiments.msc4484.is_enabled() || session_info.is_none()) + && services.admin.user_is_admin(&sender_user).await + { + // This is required to make sure admin APIs still work when msc4484 + // is disabled. + // https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2533#issuecomment-40042 + user_scopes.insert(OAuthClientScope::ServerAdministration); + } if !required_scopes .iter() diff --git a/src/core/config/experiments.rs b/src/core/config/experiments.rs index c19b19ad0..5d67ef994 100644 --- a/src/core/config/experiments.rs +++ b/src/core/config/experiments.rs @@ -24,6 +24,26 @@ pub struct Experiments { /// display: nested #[serde(default)] pub msc2815: Option, + /// MSC3814: Dehydrated devices with SSSS + /// + /// Enables server-side support for "dehydrated devices", which are + /// server-side devices (created by supporting clients) that can collect + /// encryption keys when there are no online devices, which supporting + /// clients can then "hydrate" to download any encryption keys that were + /// sent while they were offline. + /// + /// Important: this is NOT required to receive encrypted messages while you + /// are offline. Devices can still receive encrypted messages while they are + /// offline, but to share those keys with new devices, they have to be + /// online. Dehydrated devices work around this by providing a "shared" + /// device new sessions can bootstrap from, to receive keys from before they + /// logged in that haven't been uploaded to the server-side key backup yet. + /// + /// https://github.com/matrix-org/matrix-spec-proposals/pull/3814 + /// + /// default: false + #[serde(default)] + pub msc3814: SimpleExperiment, /// MSC4155: Invite filtering /// /// Provides advanced invite filtering rules for users, allowing complex @@ -48,6 +68,24 @@ pub struct Experiments { /// default: false #[serde(default)] pub msc4174: SimpleExperiment, + /// MSC4406: `M_SENDER_IGNORED` error code + /// + /// Introduces a new error code that explicitly informs clients the reason + /// they cannot access an event if it is sent by an ignored user. Without + /// this proposal, clients will simply get a "not found" or "forbidden" + /// error when requesting events sent by users that have been ignored, which + /// leads to replies being shown as "this message could not be found". + /// The new error code allows clients to distinguish unknown/forbidden + /// events from ignored senders, allowing them to display an error message + /// like "you have blocked this sender" instead. + /// + /// Requires a supporting client to be useful. + /// + /// https://github.com/matrix-org/matrix-spec-proposals/pull/4406 + /// + /// default: false + #[serde(default)] + pub msc4406: SimpleExperiment, /// MSC4484: Server Administration OAuth Scope /// /// Adds a new OAuth2 scope that explicitly grants a token temporary diff --git a/src/service/oauth/mod.rs b/src/service/oauth/mod.rs index bddad5f76..e0d118b2a 100644 --- a/src/service/oauth/mod.rs +++ b/src/service/oauth/mod.rs @@ -6,7 +6,9 @@ use std::{ use base64::Engine; use conduwuit::{ - Result, SyncMutex, info, + Result, SyncMutex, + config::experiments::ToggledExperiment, + info, utils::{self, hash::sha256}, }; use database::{Deserialized, Json, Map}; @@ -762,6 +764,7 @@ impl Service { scopes: &BTreeSet, ) -> Result<(), OAuthError> { if scopes.contains(&OAuthClientScope::ServerAdministration) + && self.services.config.experiments.msc4484.is_enabled() && !self.services.admin.user_is_admin(authorizing_user).await { return Err(OAuthError::new( diff --git a/src/service/pusher/mod.rs b/src/service/pusher/mod.rs index 778457f42..a7af1364c 100644 --- a/src/service/pusher/mod.rs +++ b/src/service/pusher/mod.rs @@ -3,7 +3,7 @@ mod webpush; use std::{fmt::Debug, mem, net::IpAddr, sync::Arc}; use bytes::BytesMut; -use conduwuit::utils::response::LimitReadExt; +use conduwuit::{config::experiments::ToggledExperiment, utils::response::LimitReadExt}; use conduwuit_core::{ Err, Event, Result, Server, debug_warn, err, trace, utils::{stream::TryIgnore, string_from_bytes}, @@ -133,7 +133,9 @@ impl Service { self.validate_push_url(&http.url, PUSH_GATEWAY_SCHEMES) .await?; }, - | PusherKind::WebPush(data) => { + | PusherKind::WebPush(data) + if self.services.config.experiments.msc4174.is_enabled() => + { self.validate_push_url(&data.url, WEBPUSH_SCHEMES).await?; webpush::decode_pushkey(pushkey)?; webpush::decode_auth(&data.auth)?; @@ -147,7 +149,7 @@ impl Service { } } }, - | PusherKind::Email(_) | PusherKind::Custom { .. } => (), + | _ => (), } let key = (sender, pushkey); @@ -547,7 +549,9 @@ impl Service { Ok(()) }, - | PusherKind::WebPush(data) => { + | PusherKind::WebPush(data) + if self.services.config.experiments.msc4174.is_enabled() => + { let notify = self .build_notification( user, @@ -562,7 +566,7 @@ impl Service { self.send_webpush_notice(user, pusher, data, notify).await }, - | PusherKind::Email(_) | PusherKind::Custom { .. } => Ok(()), + | _ => Ok(()), } } diff --git a/src/service/pusher/webpush/mod.rs b/src/service/pusher/webpush/mod.rs index 2a428d539..e8f9572ae 100644 --- a/src/service/pusher/webpush/mod.rs +++ b/src/service/pusher/webpush/mod.rs @@ -3,6 +3,7 @@ mod vapid; use std::time::{Duration, SystemTime}; +use conduwuit::config::experiments::ToggledExperiment; use conduwuit_core::{ Err, Result, debug, debug_warn, err, utils::{self, string::constant_time_eq}, @@ -85,6 +86,9 @@ impl Service { /// Reports whether a Web Push pusher has completed its activation /// handshake. pub async fn is_webpush_activated(&self, sender: &UserId, pushkey: &str) -> bool { + if !self.services.config.experiments.msc4174.is_enabled() { + return false; + } self.webpush_state(sender, pushkey).await.activated } @@ -109,6 +113,9 @@ impl Service { pusher: &Pusher, previous: Option<&Pusher>, ) -> bool { + if !self.services.config.experiments.msc4174.is_enabled() { + return false; + } let Some(data) = pusher.kind.as_webpush() else { return false; }; @@ -126,6 +133,13 @@ impl Service { } pub(super) fn begin_webpush_activation(&self, sender: &UserId, pusher: &Pusher) { + debug_assert!( + self.services.config.experiments.msc4174.is_enabled(), + "begin_webpush_activation should not be called with MSC4174 disabled" + ); + if !self.services.config.experiments.msc4174.is_enabled() { + return; + } // Send a one-time encrypted token before allowing notification // delivery. let token = utils::rand::string(ACK_TOKEN_LENGTH); diff --git a/src/service/users/account.rs b/src/service/users/account.rs index 9fc78d339..3c5f1486c 100644 --- a/src/service/users/account.rs +++ b/src/service/users/account.rs @@ -4,7 +4,9 @@ use std::{ }; use conduwuit::{ - Err, Result, debug, debug_error, debug_warn, err, error, info, trace, + Err, Result, + config::experiments::ToggledExperiment, + debug, debug_error, debug_warn, err, error, info, trace, utils::{self, stream::TryIgnore}, warn, }; @@ -107,6 +109,27 @@ impl super::Service { if stable.is_err() && unstable.is_err() { return FilterLevel::Default; } + let msc4494_enabled = self.services.config.experiments.msc4494.is_enabled(); + if !self.services.config.experiments.msc4155.is_enabled() { + // Only MSC4380 should be checked here, since it's in spec. + let Some(action) = stable.ok().and_then(|c| c.content.default_action) else { + return FilterLevel::Default; + }; + return match action { + | InvitePermissionAction::Block => FilterLevel::Block, + | InvitePermissionAction::DenyPublic if msc4494_enabled => { + if !self + .check_msc4494_mutual_room(sender_user, recipient_user) + .await + { + FilterLevel::Block + } else { + FilterLevel::Default + } + }, + | _ => FilterLevel::Allow, + }; + } let content = stable.unwrap_or_else(|_| unstable.unwrap()).content; let verdict = content.user_filter_level(sender_user); if verdict != FilterLevel::Default { @@ -114,7 +137,8 @@ impl super::Service { } // Apply other layers of invite blocking first, so that user/server // denies take priority over implicit allows. - if content.default_action == Some(InvitePermissionAction::DenyPublic) + if msc4494_enabled + && content.default_action == Some(InvitePermissionAction::DenyPublic) && !self .check_msc4494_mutual_room(sender_user, recipient_user) .await