From ba19d407d0024d4194eb6cb8c6d90da68ba47b5a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 9 Sep 2025 04:44:02 +0000 Subject: [PATCH] Add config to control `m.federate` in room create events. (fixes #151) Signed-off-by: Jason Volk --- src/api/client/room/create.rs | 20 ++++++++++++++++++++ src/core/config/mod.rs | 13 ++++++++++++- tuwunel-example.toml | 13 ++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/api/client/room/create.rs b/src/api/client/room/create.rs index 752917c3..ea634e50 100644 --- a/src/api/client/room/create.rs +++ b/src/api/client/room/create.rs @@ -413,6 +413,12 @@ async fn create_create_event( )))) })?; + if !services.config.federate_created_rooms { + if !services.config.allow_federation || !content.contains_key("m.federate") { + content.insert("m.federate".into(), json!(false).try_into()?); + } + } + content.insert( "room_version".into(), json!(room_version.as_str()) @@ -428,6 +434,10 @@ async fn create_create_event( let mut content = serde_json::from_str::(to_raw_value(&content)?.get())?; + if !services.config.federate_created_rooms { + content.insert("m.federate".into(), json!(false).try_into()?); + } + content.insert("room_version".into(), json!(room_version.as_str()).try_into()?); content }, @@ -535,6 +545,12 @@ async fn create_create_event_legacy( }, } + if !services.config.federate_created_rooms { + if !services.config.allow_federation || !content.contains_key("m.federate") { + content.insert("m.federate".into(), json!(false).try_into()?); + } + } + content.insert( "room_version".into(), json!(room_version.as_str()) @@ -556,6 +572,10 @@ async fn create_create_event_legacy( let mut content = serde_json::from_str::(to_raw_value(&content)?.get())?; + if !services.config.federate_created_rooms { + content.insert("m.federate".into(), json!(false).try_into()?); + } + content.insert("room_version".into(), json!(room_version.as_str()).try_into()?); content }, diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 1a1035d9..b565d786 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -560,10 +560,21 @@ pub struct Config { pub allow_encryption: bool, /// Controls whether federation is allowed or not. It is not recommended to - /// disable this after the fact due to potential federation breakage. + /// disable this after installation due to potential federation breakage but + /// this is technically not a permanent setting. #[serde(default = "true_fn")] pub allow_federation: bool, + /// Sets the default `m.federate` property for newly created rooms when the + /// client does not request one. If `allow_federation` is set to false at + /// the same this value is set to false it then always overrides the client + /// requested `m.federate` value to false. + /// + /// Rooms are fixed to the setting at the time of their creation and can + /// never be changed; changing this value only affects new rooms. + #[serde(default = "true_fn")] + pub federate_created_rooms: bool, + /// Allows federation requests to be made to itself /// /// This isn't intended and is very likely a bug if federation requests are diff --git a/tuwunel-example.toml b/tuwunel-example.toml index 6c709665..56129211 100644 --- a/tuwunel-example.toml +++ b/tuwunel-example.toml @@ -435,10 +435,21 @@ #allow_encryption = true # Controls whether federation is allowed or not. It is not recommended to -# disable this after the fact due to potential federation breakage. +# disable this after installation due to potential federation breakage but +# this is technically not a permanent setting. # #allow_federation = true +# Sets the default `m.federate` property for newly created rooms when the +# client does not request one. If `allow_federation` is set to false at +# the same this value is set to false it then always overrides the client +# requested `m.federate` value to false. +# +# Rooms are fixed to the setting at the time of their creation and can +# never be changed; changing this value only affects new rooms. +# +#federate_created_rooms = true + # Allows federation requests to be made to itself # # This isn't intended and is very likely a bug if federation requests are