diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 52217e96e..9b405d5f6 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -2778,6 +2778,22 @@ # env: CONTINUWUITY_EXPERIMENTS__MSC4494 #msc4494 = false +# MSC4556: Notary request limits +# +# Creates a new key notary server route that has stricter limits on how +# many signing keys can be requested in one query, to avoid a resource +# exhaustion exploit vector in the existing key notary endpoint. +# +# Continuwuity mitigates the exploit vector in the old notary endpoint +# anyway, so you do not need to enable this to be protected. +# +# Requires that remote servers support this MSC before it does anything. +# +# https://github.com/matrix-org/matrix-spec-proposals/pull/4556 +# +# env: CONTINUWUITY_EXPERIMENTS__MSC4556 +#msc4556 = false + # MSC4560: Stripped state requests over federation # # Implements a more efficient way for servers to acquire and serve diff --git a/src/api/router.rs b/src/api/router.rs index e966939ba..d5f8805d1 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -220,7 +220,6 @@ pub fn build(router: Router, state: State) -> Router { .ruma_route(&server::get_server_version_route) .ruma_route(&server::get_server_keys_route) .ruma_route(&server::get_remote_server_keys_batch_route) - .ruma_route(&server::get_remote_server_keys_batch_v3_unstable_route) .ruma_route(&server::get_remote_server_keys_route) .ruma_route(&server::get_public_rooms_route) .ruma_route(&server::get_public_rooms_filtered_route) @@ -248,6 +247,9 @@ pub fn build(router: Router, state: State) -> Router { .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.msc4556.is_enabled() { + router = router.ruma_route(&server::get_remote_server_keys_batch_v3_unstable_route); + } if config.experiments.msc4560.is_enabled() { router = router.ruma_route(&server::get_stripped_state_route); } diff --git a/src/api/server/key.rs b/src/api/server/key.rs index e1dc536f1..a997b05a7 100644 --- a/src/api/server/key.rs +++ b/src/api/server/key.rs @@ -7,7 +7,9 @@ use std::{ use axum::extract::State; use conduwuit::{ - Err, Result, debug, debug_info, error, + Err, Result, + config::experiments::ToggledExperiment, + debug, debug_info, error, utils::{ ReadyExt, stream::{BroadbandExt, automatic_width}, @@ -103,7 +105,7 @@ async fn query_inner( .values() .fold(0_usize, |acc, q| acc.saturating_add(q.len().max(1))); - if !v2 { + if !v2 && services.config.experiments.msc4556.is_enabled() { // If we're on the v3 endpoint, we can apply these limits explicitly. if total_queried_servers > MAX_SERVERS_PER_QUERY { return Err!(Request(TooLarge( diff --git a/src/core/config/experiments.rs b/src/core/config/experiments.rs index 5d67ef994..86be61339 100644 --- a/src/core/config/experiments.rs +++ b/src/core/config/experiments.rs @@ -118,6 +118,22 @@ pub struct Experiments { /// default: false #[serde(default)] pub msc4494: SimpleExperiment, + /// MSC4556: Notary request limits + /// + /// Creates a new key notary server route that has stricter limits on how + /// many signing keys can be requested in one query, to avoid a resource + /// exhaustion exploit vector in the existing key notary endpoint. + /// + /// Continuwuity mitigates the exploit vector in the old notary endpoint + /// anyway, so you do not need to enable this to be protected. + /// + /// Requires that remote servers support this MSC before it does anything. + /// + /// https://github.com/matrix-org/matrix-spec-proposals/pull/4556 + /// + /// default: false + #[serde(default)] + pub msc4556: SimpleExperiment, /// MSC4560: Stripped state requests over federation /// /// Implements a more efficient way for servers to acquire and serve