fix(matrix): make auto_accept_invites configurable, default to false

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) <noreply@anthropic.com>
This commit is contained in:
reaster
2026-03-18 01:43:47 +01:00
co-authored by Claude Opus 4.6
parent f1ca52714d
commit 935f3fac8e
3 changed files with 10 additions and 1 deletions
@@ -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()));
}
+5 -1
View File
@@ -46,6 +46,7 @@ impl MatrixAdapter {
user_id: String,
access_token: String,
allowed_rooms: Vec<String>,
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"));
}
+4
View File
@@ -1861,6 +1861,9 @@ pub struct MatrixConfig {
pub allowed_rooms: Vec<String>,
/// Default agent name to route messages to.
pub default_agent: Option<String>,
/// 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(),
}
}