Skip to main content

mas_data_model/
site_config.rs

1// Copyright 2025, 2026 Element Creations Ltd.
2// Copyright 2024, 2025 New Vector Ltd.
3// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
4//
5// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
6// Please see LICENSE files in the repository root for full details.
7
8use std::num::NonZeroU64;
9
10use chrono::Duration;
11use serde::Serialize;
12use url::Url;
13
14/// Which Captcha service is being used
15#[derive(Debug, Clone, Copy)]
16pub enum CaptchaService {
17    RecaptchaV2,
18    CloudflareTurnstile,
19    HCaptcha,
20}
21
22/// Captcha configuration
23#[derive(Debug, Clone)]
24pub struct CaptchaConfig {
25    /// Which Captcha service is being used
26    pub service: CaptchaService,
27
28    /// The site key used by the instance
29    pub site_key: String,
30
31    /// The secret key used by the instance
32    pub secret_key: String,
33}
34
35/// Automatic session expiration configuration
36#[derive(Debug, Clone)]
37pub struct SessionExpirationConfig {
38    pub user_session_inactivity_ttl: Option<Duration>,
39    pub oauth_session_inactivity_ttl: Option<Duration>,
40    pub compat_session_inactivity_ttl: Option<Duration>,
41}
42
43/// See [`mas_config::ExperimentalSessionLimitConfig`]
44#[derive(Serialize, Debug, Clone)]
45pub struct SessionLimitConfig {
46    pub soft_limit: NonZeroU64,
47    pub hard_limit: NonZeroU64,
48    pub max_session_threshold: Option<NonZeroU64>,
49    pub dangerous_hard_limit_eviction: bool,
50}
51
52/// Random site configuration we want accessible in various places.
53#[expect(clippy::struct_excessive_bools)]
54#[derive(Debug, Clone)]
55pub struct SiteConfig {
56    /// Time-to-live of access tokens.
57    pub access_token_ttl: Duration,
58
59    /// Time-to-live of compatibility access tokens.
60    pub compat_token_ttl: Duration,
61
62    /// The server name, e.g. "matrix.org".
63    pub server_name: String,
64
65    /// The URL to the privacy policy.
66    pub policy_uri: Option<Url>,
67
68    /// The URL to the terms of service.
69    pub tos_uri: Option<Url>,
70
71    /// Imprint to show in the footer.
72    pub imprint: Option<String>,
73
74    /// Whether password login is enabled.
75    pub password_login_enabled: bool,
76
77    /// Whether password registration is enabled.
78    pub password_registration_enabled: bool,
79
80    /// Whether a valid email address is required for password registrations.
81    pub password_registration_email_required: bool,
82
83    /// Whether registration tokens are required for password registrations.
84    pub password_registration_token_required: bool,
85
86    /// Whether registration tokens are required globally for password
87    /// registrations. Deprecated in favor of
88    /// `password_registration_token_required`
89    pub registration_token_required: bool,
90
91    /// Whether users can change their email.
92    pub email_change_allowed: bool,
93
94    /// Whether users can change their display name.
95    pub displayname_change_allowed: bool,
96
97    /// Whether users can change their password.
98    pub password_change_allowed: bool,
99
100    /// Whether users can recover their account via email.
101    pub account_recovery_allowed: bool,
102
103    /// Whether users can delete their own account.
104    pub account_deactivation_allowed: bool,
105
106    /// Captcha configuration
107    pub captcha: Option<CaptchaConfig>,
108
109    /// Minimum password complexity, between 0 and 4.
110    /// This is a score from zxcvbn.
111    pub minimum_password_complexity: u8,
112
113    pub session_expiration: Option<SessionExpirationConfig>,
114
115    /// Whether users can log in with their email address.
116    pub login_with_email_allowed: bool,
117
118    /// The iframe URL to show in the plan tab of the UI
119    pub plan_management_iframe_uri: Option<String>,
120
121    /// Limits on the number of application sessions that each user can have
122    pub session_limit: Option<SessionLimitConfig>,
123
124    /// Whether the Device Authorization Grant (RFC 8628) is enabled.
125    pub device_code_grant_enabled: bool,
126
127    /// Whether the device authorization endpoint advertises a
128    /// `verification_uri_complete` and whether `/link` accepts a `code`
129    /// query parameter to auto-fill the user code.
130    pub device_code_user_code_auto_fill_enabled: bool,
131
132    /// The client URL to send invitees to, with `{room_id}` standing for the
133    /// room ID.
134    pub room_invites_client_room_url: Option<String>,
135}