From 935f3fac8e7c55de34c5320719cb00be9a53eb83 Mon Sep 17 00:00:00 2001 From: reaster Date: Wed, 18 Mar 2026 01:43:47 +0100 Subject: [PATCH] fix(matrix): make auto_accept_invites configurable, default to false MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MatrixAdapter hardcoded `auto_accept_invites: true`, meaning any Matrix-connected instance would blindly join every room it was invited to. This is a security concern for public-facing homeservers — a malicious user could invite the bot into an arbitrary room and interact with the agent without the operator's consent. Changes: - Add `auto_accept_invites: bool` to `MatrixConfig` in openfang-types, with `#[serde(default)]` defaulting to `false`. - Thread the field through `MatrixAdapter::new()` instead of hardcoding. - Wire it in `channel_bridge.rs` from `mx_config.auto_accept_invites`. - Update tests to pass the new parameter. Operators who want the old behaviour can set: ```toml [channels.matrix] auto_accept_invites = true ``` Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/openfang-api/src/channel_bridge.rs | 1 + crates/openfang-channels/src/matrix.rs | 6 +++++- crates/openfang-types/src/config.rs | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/openfang-api/src/channel_bridge.rs b/crates/openfang-api/src/channel_bridge.rs index 938eea68..16bb2ea5 100644 --- a/crates/openfang-api/src/channel_bridge.rs +++ b/crates/openfang-api/src/channel_bridge.rs @@ -1218,6 +1218,7 @@ pub async fn start_channel_bridge_with_config( mx_config.user_id.clone(), token, mx_config.allowed_rooms.clone(), + mx_config.auto_accept_invites, )); adapters.push((adapter, mx_config.default_agent.clone())); } diff --git a/crates/openfang-channels/src/matrix.rs b/crates/openfang-channels/src/matrix.rs index be758e68..cc6cea21 100644 --- a/crates/openfang-channels/src/matrix.rs +++ b/crates/openfang-channels/src/matrix.rs @@ -46,6 +46,7 @@ impl MatrixAdapter { user_id: String, access_token: String, allowed_rooms: Vec, + auto_accept_invites: bool, ) -> Self { let (shutdown_tx, shutdown_rx) = watch::channel(false); Self { @@ -57,7 +58,7 @@ impl MatrixAdapter { shutdown_tx: Arc::new(shutdown_tx), shutdown_rx, since_token: Arc::new(RwLock::new(None)), - auto_accept_invites: true, + auto_accept_invites, } } @@ -461,6 +462,7 @@ mod tests { "@bot:matrix.org".to_string(), "access_token".to_string(), vec![], + false, ); assert_eq!(adapter.name(), "matrix"); } @@ -472,6 +474,7 @@ mod tests { "@bot:matrix.org".to_string(), "token".to_string(), vec!["!room1:matrix.org".to_string()], + false, ); assert!(adapter.is_allowed_room("!room1:matrix.org")); assert!(!adapter.is_allowed_room("!room2:matrix.org")); @@ -481,6 +484,7 @@ mod tests { "@bot:matrix.org".to_string(), "token".to_string(), vec![], + false, ); assert!(open.is_allowed_room("!any:matrix.org")); } diff --git a/crates/openfang-types/src/config.rs b/crates/openfang-types/src/config.rs index 71748eb0..c4373721 100644 --- a/crates/openfang-types/src/config.rs +++ b/crates/openfang-types/src/config.rs @@ -1861,6 +1861,9 @@ pub struct MatrixConfig { pub allowed_rooms: Vec, /// Default agent name to route messages to. pub default_agent: Option, + /// Whether to auto-accept room invites (default: false). + #[serde(default)] + pub auto_accept_invites: bool, /// Per-channel behavior overrides. #[serde(default)] pub overrides: ChannelOverrides, @@ -1874,6 +1877,7 @@ impl Default for MatrixConfig { access_token_env: "MATRIX_ACCESS_TOKEN".to_string(), allowed_rooms: vec![], default_agent: None, + auto_accept_invites: false, overrides: ChannelOverrides::default(), } }