Compare commits

..
20 changed files with 239 additions and 187 deletions

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ jobs:
name: Renovate
runs-on: ubuntu-latest
container:
image: ghcr.io/renovatebot/renovate:44.241.0@sha256:22d22b4ca7d768b5b469309d34379783bf91cd94a58faecf1cd0f4528a65d21c
image: ghcr.io/renovatebot/renovate:44.257.9@sha256:578179439fceea89646662dd583b27efdad8d1429e0cbd90681c40dde068589e
options: --tmpfs /tmp:exec
steps:
- name: Checkout
+1 -1
View File
@@ -51,7 +51,7 @@ repos:
hooks:
- id: cargo-clippy
name: cargo clippy
entry: cargo clippy --
entry: cargo clippy -- -D warnings
language: system
pass_filenames: false
types: [ rust ]
Generated
+26 -59
View File
@@ -485,19 +485,18 @@ dependencies = [
[[package]]
name = "bindgen"
version = "0.72.1"
version = "0.73.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
checksum = "787ef8ef523575546b106a58213d6e6b06198a05c2f757258c68a74273670cfa"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"itertools 0.13.0",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex 1.3.0",
"shlex",
"syn 2.0.119",
]
@@ -684,7 +683,7 @@ dependencies = [
"find-msvc-tools",
"jobserver",
"libc",
"shlex 2.0.1",
"shlex",
]
[[package]]
@@ -874,13 +873,9 @@ dependencies = [
name = "conduwuit"
version = "26.11.0-alpha.2"
dependencies = [
"aws-lc-rs",
"clap",
"conduwuit_admin",
"conduwuit_api",
"conduwuit_build_metadata",
"conduwuit_core",
"conduwuit_database",
"conduwuit_macros",
"conduwuit_router",
"conduwuit_service",
@@ -888,7 +883,6 @@ dependencies = [
"const-str",
"ctor",
"dtor",
"log",
"opentelemetry",
"opentelemetry-otlp",
"opentelemetry-prometheus",
@@ -896,13 +890,10 @@ dependencies = [
"opentelemetry_sdk",
"parking_lot",
"prometheus",
"reqwest 0.13.5",
"rustls",
"sentry",
"sentry-tower",
"sentry-tracing",
"tokio",
"tokio-metrics",
"tracing",
"tracing-flame",
"tracing-journald",
@@ -1143,6 +1134,7 @@ dependencies = [
"p256 0.14.0",
"rand 0.10.4",
"regex",
"reqwest 0.12.28",
"reqwest 0.13.5",
"resolvematrix",
"ruma",
@@ -2720,10 +2712,10 @@ dependencies = [
"hyper",
"hyper-util",
"rustls",
"rustls-native-certs",
"tokio",
"tokio-rustls",
"tower-service",
"webpki-roots",
]
[[package]]
@@ -2997,15 +2989,6 @@ dependencies = [
"serde",
]
[[package]]
name = "itertools"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.14.0"
@@ -3276,9 +3259,9 @@ dependencies = [
[[package]]
name = "libz-sys"
version = "1.1.29"
version = "1.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85bc9657773828b90eeb625adff10eeac83cc21bbfd8e23a03eaa8a33c9e28d9"
checksum = "69965d2409bff8c8cea3829009fff66a86f05a0570656552ef70f616e8e4bd85"
dependencies = [
"cc",
"pkg-config",
@@ -4197,12 +4180,6 @@ dependencies = [
"phc",
]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "pear"
version = "0.2.9"
@@ -4866,8 +4843,8 @@ dependencies = [
"log",
"percent-encoding",
"pin-project-lite",
"quinn",
"rustls",
"rustls-native-certs",
"rustls-pki-types",
"serde",
"serde_json",
@@ -4882,7 +4859,6 @@ dependencies = [
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"webpki-roots",
]
[[package]]
@@ -5221,8 +5197,8 @@ dependencies = [
[[package]]
name = "rust-librocksdb-sys"
version = "0.45.1+11.1.1"
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=0a25ff92f7c09b55eec496b9c192c7d5136ab2b8#0a25ff92f7c09b55eec496b9c192c7d5136ab2b8"
version = "0.49.0+11.12.0"
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=85ded20348e3dab902c239967075795e9c6d101b#85ded20348e3dab902c239967075795e9c6d101b"
dependencies = [
"bindgen",
"bzip2-sys",
@@ -5232,14 +5208,15 @@ dependencies = [
"libz-sys",
"lz4-sys",
"pkg-config",
"rustflags",
"tikv-jemalloc-sys",
"zstd-sys",
]
[[package]]
name = "rust-rocksdb"
version = "0.49.1"
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=0a25ff92f7c09b55eec496b9c192c7d5136ab2b8#0a25ff92f7c09b55eec496b9c192c7d5136ab2b8"
version = "0.54.0"
source = "git+https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1?rev=85ded20348e3dab902c239967075795e9c6d101b#85ded20348e3dab902c239967075795e9c6d101b"
dependencies = [
"libc",
"parking_lot",
@@ -5267,6 +5244,12 @@ dependencies = [
"semver",
]
[[package]]
name = "rustflags"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a39e0e9135d7a7208ee80aa4e3e4b88f0f5ad7be92153ed70686c38a03db2e63"
[[package]]
name = "rustix"
version = "1.1.6"
@@ -5894,12 +5877,6 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "shlex"
version = "2.0.1"
@@ -6259,18 +6236,17 @@ dependencies = [
[[package]]
name = "tikv-jemalloc-ctl"
version = "0.6.1"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554#df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
version = "0.7.0"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
dependencies = [
"libc",
"paste",
"tikv-jemalloc-sys",
]
[[package]]
name = "tikv-jemalloc-sys"
version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554#df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
version = "0.7.0+5.4.0-0-g7a34f18502e7b222724097cdcd499b437d189acc"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
dependencies = [
"cc",
"libc",
@@ -6278,8 +6254,8 @@ dependencies = [
[[package]]
name = "tikv-jemallocator"
version = "0.6.1"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554#df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
version = "0.7.0"
source = "git+https://forgejo.ellis.link/continuwuation/jemallocator?rev=46e7821917b06636cdb5b203d312799970eaea92#46e7821917b06636cdb5b203d312799970eaea92"
dependencies = [
"libc",
"tikv-jemalloc-sys",
@@ -7137,15 +7113,6 @@ dependencies = [
"rustls-pki-types",
]
[[package]]
name = "webpki-roots"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171"
dependencies = [
"rustls-pki-types",
]
[[package]]
name = "weezl"
version = "0.1.12"
+15 -4
View File
@@ -166,6 +166,15 @@ features = [
"form",
]
# Needed for as long as openidconnect is on an outdated reqwest
[workspace.dependencies.reqwest_0_12]
package = "reqwest"
version = "0.12"
default-features = false
features = [
"rustls-tls-native-roots-no-provider",
]
[workspace.dependencies.serde]
version = "1.0.229"
default-features = false
@@ -395,7 +404,7 @@ features = [
[workspace.dependencies.rust-rocksdb]
git = "https://forgejo.ellis.link/continuwuation/rust-rocksdb-zaidoon1"
rev = "0a25ff92f7c09b55eec496b9c192c7d5136ab2b8"
rev = "85ded20348e3dab902c239967075795e9c6d101b"
default-features = false
features = [
"multi-threaded-cf",
@@ -415,6 +424,8 @@ default-features = false
[workspace.dependencies.openidconnect]
version = "4.1.0"
default-features = false
features = ["reqwest"]
# optional opentelemetry, performance measurements, flamegraphs, etc for performance measurements and monitoring
[workspace.dependencies.opentelemetry]
@@ -477,7 +488,7 @@ version = "0.49.5"
# jemalloc usage
[workspace.dependencies.tikv-jemalloc-sys]
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
rev = "df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
rev = "46e7821917b06636cdb5b203d312799970eaea92"
default-features = false
features = [
"background_threads_runtime_support",
@@ -485,7 +496,7 @@ features = [
]
[workspace.dependencies.tikv-jemallocator]
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
rev = "df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
rev = "46e7821917b06636cdb5b203d312799970eaea92"
default-features = false
features = [
"background_threads_runtime_support",
@@ -493,7 +504,7 @@ features = [
]
[workspace.dependencies.tikv-jemalloc-ctl]
git = "https://forgejo.ellis.link/continuwuation/jemallocator"
rev = "df86ff89d4b1e223b9f7d2dd2fbb7f202da7f554"
rev = "46e7821917b06636cdb5b203d312799970eaea92"
default-features = false
features = ["use_std"]
+1
View File
@@ -0,0 +1 @@
Network issues while refreshing an access token will no longer cause OAuth-compatible clients to be forcibly logged out. Contributed by @ginger.
+12
View File
@@ -813,6 +813,18 @@
# env: CONTINUWUITY_FORGET_FORCED_UPON_LEAVE
#forget_forced_upon_leave = false
# Set this to true to require authentication when looking up user profiles
# through this server.
#
# By default this is false, allowing tools such as matrix.to to access
# profiles of users on this server and on other servers.
# Setting this to true will block those tools, and may block automated
# crawlers from scraping users' profiles, although it will not block
# other homeservers from accessing users' profiles.
#
# env: CONTINUWUITY_REQUIRE_AUTH_FOR_PROFILE_REQUESTS
#require_auth_for_profile_requests = false
# Set this to true to require authentication to create a rendezvous
# session. Rendezvous sessions are used for QR code login.
#
-46
View File
@@ -1,46 +0,0 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
#################################################################################
# WARNING: Do not store sensitive information in this file, #
# as its contents will be included in the Qodana report. #
#################################################################################
version: "1.0"
#Specify inspection profile for code analysis
profile:
name: qodana.starter
#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>
#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
# Quality gate. Will fail the CI/CD pipeline if any condition is not met
# severityThresholds - configures maximum thresholds for different problem severities
# testCoverageThresholds - configures minimum code coverage on a whole project and newly added code
# Code Coverage is available in Ultimate and Ultimate Plus plans
#failureConditions:
# severityThresholds:
# any: 15
# critical: 5
# testCoverageThresholds:
# fresh: 70
# total: 50
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-<linter>:2026.2
+2 -2
View File
@@ -29,7 +29,7 @@ pub(crate) async fn get_profile_route(
State(services): State<crate::State>,
body: Ruma<get_profile::v3::Request>,
) -> Result<get_profile::v3::Response> {
if body.identity.is_none() {
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
return Err!(Request(Unauthorized(
"This server requires authentication to access user profiles."
)));
@@ -46,7 +46,7 @@ pub(crate) async fn get_profile_field_route(
State(services): State<crate::State>,
body: Ruma<get_profile_field::v3::Request>,
) -> Result<get_profile_field::v3::Response> {
if body.identity.is_none() {
if services.config.require_auth_for_profile_requests && body.identity.is_none() {
return Err!(Request(Unauthorized(
"This server requires authentication to access user profiles."
)));
+22 -6
View File
@@ -319,6 +319,19 @@ async fn check_access_token(
));
}
let session_info = services
.oauth
.get_session_info_for_device(&sender_user, &sender_device)
.await;
if let Some(session_info) = &session_info {
services.oauth.clear_previous_refresh_token(
&sender_user,
&sender_device,
session_info,
);
}
// Locked users can only use /logout and /logout/all
if services
.users
@@ -333,12 +346,6 @@ async fn check_access_token(
}
}
let session_info = services
.oauth
.get_session_info_for_device(&sender_user, &sender_device)
.await
.map(Box::new);
// Make sure the user has the right scopes to use the route
let mut user_scopes = if let Some(session_info) = &session_info {
session_info.scopes()
@@ -416,6 +423,15 @@ async fn check_access_token(
sender_device,
appservice_info: Box::new(appservice_info),
})
} else if services.users.is_previous_token(token).await {
// Return a soft-logout for previous tokens. This is necessary
// to make token refreshing idempotent.
Err(Error::Request(
ErrorKind::UnknownToken(assign!(UnknownTokenErrorData::new(), { soft_logout: true })),
"This token has expired".into(),
StatusCode::UNAUTHORIZED,
))
} else {
Err(Error::Request(
ErrorKind::UnknownToken(UnknownTokenErrorData::new()),
+28 -21
View File
@@ -920,6 +920,19 @@ pub struct Config {
#[serde(default)]
pub forget_forced_upon_leave: bool,
/// Set this to true to require authentication when looking up user profiles
/// through this server.
///
/// By default this is false, allowing tools such as matrix.to to access
/// profiles of users on this server and on other servers.
/// Setting this to true will block those tools, and may block automated
/// crawlers from scraping users' profiles, although it will not block
/// other homeservers from accessing users' profiles.
///
/// default: false
#[serde(default)]
pub require_auth_for_profile_requests: bool,
/// Set this to true to require authentication to create a rendezvous
/// session. Rendezvous sessions are used for QR code login.
///
@@ -2989,7 +3002,6 @@ const DEPRECATED_KEYS: &[&str] = &[
"max_concurrent_requests",
"otlp_protocol",
"request_ip_source",
"require_auth_for_profile_requests",
"roomid_spacehierarchy_cache_capacity",
"unredacted_content_max_age_secs",
"well_known_client",
@@ -3129,41 +3141,41 @@ fn default_database_backups_to_keep() -> i16 { 1 }
fn default_db_write_buffer_capacity_mb() -> f64 { 48.0 + parallelism_scaled_f64(4.0) }
fn default_db_cache_capacity_mb() -> f64 { 512.0 + parallelism_scaled_f64(512.0) }
fn default_db_cache_capacity_mb() -> f64 { 128.0 + parallelism_scaled_f64(64.0) }
fn default_pdu_cache_capacity() -> u32 { parallelism_scaled_u32(50_000).saturating_add(100_000) }
fn default_pdu_cache_capacity() -> u32 { parallelism_scaled_u32(10_000).saturating_add(100_000) }
fn default_cache_capacity_modifier() -> f64 { 1.0 }
fn default_auth_chain_cache_capacity() -> u32 {
parallelism_scaled_u32(50_000).saturating_add(100_000)
parallelism_scaled_u32(10_000).saturating_add(100_000)
}
fn default_shorteventid_cache_capacity() -> u32 {
parallelism_scaled_u32(100_000).saturating_add(100_000)
parallelism_scaled_u32(50_000).saturating_add(100_000)
}
fn default_eventidshort_cache_capacity() -> u32 {
parallelism_scaled_u32(50_000).saturating_add(100_000)
parallelism_scaled_u32(25_000).saturating_add(100_000)
}
fn default_eventid_pdu_cache_capacity() -> u32 {
parallelism_scaled_u32(50_000).saturating_add(100_000)
parallelism_scaled_u32(25_000).saturating_add(100_000)
}
fn default_shortstatekey_cache_capacity() -> u32 {
parallelism_scaled_u32(100_000).saturating_add(100_000)
parallelism_scaled_u32(10_000).saturating_add(100_000)
}
fn default_statekeyshort_cache_capacity() -> u32 {
parallelism_scaled_u32(50_000).saturating_add(100_000)
parallelism_scaled_u32(10_000).saturating_add(100_000)
}
fn default_servernameevent_data_cache_capacity() -> u32 {
parallelism_scaled_u32(100_000).saturating_add(100_000)
parallelism_scaled_u32(100_000).saturating_add(500_000)
}
fn default_stateinfo_cache_capacity() -> u32 { parallelism_scaled_u32(500).clamp(100, 12000) }
fn default_stateinfo_cache_capacity() -> u32 { parallelism_scaled_u32(100) }
fn default_dns_cache_entries() -> u32 { 32768 }
@@ -3386,20 +3398,15 @@ fn default_admin_log_capture() -> String {
fn default_admin_room_tag() -> String { "m.server_notice".to_owned() }
#[must_use]
#[allow(clippy::as_conversions, clippy::cast_precision_loss)]
pub fn parallelism_scaled_f64(val: f64) -> f64 { val * (sys::available_parallelism() as f64) }
fn parallelism_scaled_f64(val: f64) -> f64 { val * (sys::available_parallelism() as f64) }
#[must_use]
#[allow(clippy::as_conversions, clippy::cast_possible_truncation)]
pub fn parallelism_scaled_u32(val: u32) -> u32 {
val.saturating_mul(sys::available_parallelism() as u32)
fn parallelism_scaled_u32(val: u32) -> u32 {
let val = val.try_into().expect("failed to cast u32 to usize");
parallelism_scaled(val).try_into().unwrap_or(u32::MAX)
}
#[must_use]
pub fn parallelism_scaled(val: usize) -> usize {
val.saturating_mul(sys::available_parallelism())
}
fn parallelism_scaled(val: usize) -> usize { val.saturating_mul(sys::available_parallelism()) }
fn default_db_pool_workers() -> usize {
sys::available_parallelism()
-3
View File
@@ -5,7 +5,6 @@ pub type DigestOut = [u8; 256 / 8];
/// Sha256 hash (input gather joined by 0xFF bytes)
#[must_use]
#[tracing::instrument(skip(inputs), level = "trace")]
#[allow(clippy::unnecessary_fallible_conversions)]
pub fn delimited<'a, T, I>(mut inputs: I) -> DigestOut
where
I: Iterator<Item = T> + 'a,
@@ -26,7 +25,6 @@ where
/// Sha256 hash (input gather)
#[must_use]
#[tracing::instrument(skip(inputs), level = "trace")]
#[allow(clippy::unnecessary_fallible_conversions)]
pub fn concat<'a, T, I>(inputs: I) -> DigestOut
where
I: Iterator<Item = T> + 'a,
@@ -45,7 +43,6 @@ where
#[inline]
#[must_use]
#[tracing::instrument(skip(input), level = "trace")]
#[allow(clippy::unnecessary_fallible_conversions)]
pub fn hash<T>(input: T) -> DigestOut
where
T: AsRef<[u8]>,
+1 -1
View File
@@ -29,7 +29,7 @@ fn descriptor_cf_options(
let mut opts = set_table_options(opts, &desc, cache)?;
opts.set_min_write_buffer_number(1);
opts.set_max_write_buffer_number(3);
opts.set_max_write_buffer_number(2);
opts.set_write_buffer_size(desc.write_size);
opts.set_target_file_size_base(desc.file_size);
+4
View File
@@ -407,6 +407,10 @@ pub(super) static MAPS: &[Descriptor] = &[
name: "userdeviceid_token",
..descriptor::RANDOM_SMALL
},
Descriptor {
name: "userdeviceid_previoustoken",
..descriptor::RANDOM_SMALL
},
Descriptor {
name: "userdevicesessionid_uiaainfo",
..descriptor::RANDOM_SMALL
+8 -28
View File
@@ -76,7 +76,6 @@ full = [
]
brotli_compression = [
"conduwuit-api/brotli_compression",
"conduwuit-core/brotli_compression",
"conduwuit-router/brotli_compression",
"conduwuit-service/brotli_compression",
@@ -88,31 +87,30 @@ direct_tls = [
"conduwuit-router/direct_tls"
]
element_hacks = [
"conduwuit-api/element_hacks",
"conduwuit-service/element_hacks",
"conduwuit-router/element_hacks",
]
gzip_compression = [
"conduwuit-api/gzip_compression",
"conduwuit-core/gzip_compression",
"conduwuit-router/gzip_compression",
"conduwuit-service/gzip_compression",
]
http3 = [
"reqwest/http3"
"conduwuit-service/http3"
]
ring = [
"rustls/ring"
"rustls/ring",
]
aws_lc_rs = [
"rustls/aws_lc_rs",
"dep:aws-lc-rs"
]
io_uring = [
"conduwuit-database/io_uring",
"conduwuit-service/io_uring",
]
jemalloc = [
"conduwuit-core/jemalloc",
"conduwuit-database/jemalloc",
"conduwuit-service/jemalloc",
]
mimalloc = [
"conduwuit-core/mimalloc",
@@ -144,19 +142,13 @@ perf_measurements = [
release_max_log_level = [
"tracing/max_level_trace",
"tracing/release_max_level_info",
"log/max_level_trace",
"log/release_max_level_info",
"conduwuit-admin/release_max_log_level",
"conduwuit-api/release_max_log_level",
"conduwuit-core/release_max_log_level",
"conduwuit-database/release_max_log_level",
"conduwuit-router/release_max_log_level",
"conduwuit-service/release_max_log_level",
]
sentry_telemetry = [
"dep:sentry",
"dep:sentry-tracing",
"dep:sentry-tower",
"conduwuit-core/sentry_telemetry",
"conduwuit-router/sentry_telemetry",
]
@@ -179,19 +171,17 @@ url_preview = [
"conduwuit-service/url_preview",
]
zstd_compression = [
"conduwuit-api/zstd_compression",
"conduwuit-core/zstd_compression",
"conduwuit-database/zstd_compression",
"conduwuit-router/zstd_compression",
"conduwuit-service/zstd_compression",
]
bindgen-static = [
# "bindgen/static"
# "clang-sys/static"
"conduwuit-database/bindgen-static"
"conduwuit-service/bindgen-static"
]
bindgen-runtime = [
"conduwuit-database/bindgen-runtime"
"conduwuit-service/bindgen-runtime"
]
[build-dependencies]
@@ -199,10 +189,7 @@ bindgen-runtime = [
# clang-sys = {version = "1", default-features = false}
[dependencies]
conduwuit-admin.workspace = true
conduwuit-api.workspace = true
conduwuit-core.workspace = true
conduwuit-database.workspace = true
conduwuit-router.workspace = true
conduwuit-service.workspace = true
conduwuit-build-metadata.workspace = true
@@ -214,7 +201,6 @@ dtor.workspace = true
console-subscriber.optional = true
console-subscriber.workspace = true
const-str.workspace = true
log.workspace = true
opentelemetry.workspace = true
opentelemetry-otlp.optional = true
opentelemetry-otlp.workspace = true
@@ -222,14 +208,10 @@ opentelemetry-prometheus.workspace = true
opentelemetry-semantic-conventions.workspace = true
opentelemetry_sdk.workspace = true
prometheus.workspace = true
sentry-tower.optional = true
sentry-tower.workspace = true
sentry-tracing.optional = true
sentry-tracing.workspace = true
sentry.optional = true
sentry.workspace = true
tokio-metrics.optional = true
tokio-metrics.workspace = true
tokio.workspace = true
tracing-flame.optional = true
tracing-flame.workspace = true
@@ -239,9 +221,7 @@ tracing-subscriber.workspace = true
tracing.workspace = true
tracing-journald = { workspace = true, optional = true }
parking_lot.workspace = true
reqwest = { workspace = true, default-features = false }
rustls = { workspace = true, default-features = false }
aws-lc-rs = { version = "1.19.0", default-features = false, optional = true }
[lints]
workspace = true
+4 -4
View File
@@ -8,7 +8,7 @@ use axum::{
extract::State,
response::{IntoResponse, Response},
};
use conduwuit::{Result, debug_warn, err, error, info, trace};
use conduwuit::{Result, debug, debug_error, debug_warn, err, error, trace};
use conduwuit_service::Services;
use futures::FutureExt;
use http::{Method, StatusCode, Uri};
@@ -106,11 +106,11 @@ fn handle_result(method: &Method, uri: &Uri, result: Response) -> Result<Respons
let reason = status.canonical_reason().unwrap_or("Unknown Reason");
if status.is_server_error() {
info!(%method, %uri, "{code} {reason}");
error!(%method, %uri, "{code} {reason}");
} else if status.is_client_error() {
info!(%method, %uri, "{code} {reason}");
debug_error!(%method, %uri, "{code} {reason}");
} else if status.is_redirection() {
trace!(%method, %uri, "{code} {reason}");
debug!(%method, %uri, "{code} {reason}");
} else {
trace!(%method, %uri, "{code} {reason}");
}
+12
View File
@@ -16,6 +16,12 @@ crate-type = [
]
[features]
bindgen-runtime = [
"conduwuit-database/bindgen-runtime"
]
bindgen-static = [
"conduwuit-database/bindgen-static"
]
brotli_compression = [
"conduwuit-core/brotli_compression",
"reqwest/brotli",
@@ -29,6 +35,9 @@ gzip_compression = [
"conduwuit-core/gzip_compression",
"reqwest/gzip",
]
http3 = [
"reqwest/http3"
]
io_uring = [
"conduwuit-database/io_uring",
]
@@ -123,6 +132,9 @@ lettre.workspace = true
resolvematrix.workspace = true
serde_urlencoded.workspace = true
openidconnect.workspace = true
# We use this to set TLS backend features on the outdated reqwest bundled by openidconnect,
# which is necessary to call `danger_accept_invalid_certs`.
reqwest_0_12.workspace = true
rand.workspace = true
[target.'cfg(all(unix, target_os = "linux"))'.dependencies]
+77 -10
View File
@@ -1,5 +1,6 @@
use std::{
collections::{BTreeSet, HashMap},
fmt::Write,
sync::Arc,
time::{Duration, SystemTime},
};
@@ -55,7 +56,7 @@ struct Services {
config: Dep<config::Service>,
}
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SessionInfo {
pub client_id: String,
#[serde(deserialize_with = "client_metadata::btreeset_skip_err")]
@@ -64,6 +65,8 @@ pub struct SessionInfo {
temporary_scopes: BTreeSet<OAuthClientScope>,
#[serde(default)]
current_refresh_token: String,
#[serde(default)]
previous_refresh_token: Option<String>,
}
impl SessionInfo {
@@ -71,6 +74,15 @@ impl SessionInfo {
pub fn scopes(&self) -> BTreeSet<OAuthClientScope> {
self.scopes.union(&self.temporary_scopes).cloned().collect()
}
#[must_use]
pub fn scope_string(&self, device_id: &DeviceId) -> String {
let mut scopes = self.scopes().iter().join(" ");
let _ = write!(scopes, " urn:matrix:client:device:{device_id}");
scopes
}
}
#[derive(Debug, Deserialize, Serialize)]
@@ -246,6 +258,24 @@ impl Service {
.ok()
}
/// Clear a session's previous refresh token, if it has one.
pub fn clear_previous_refresh_token(
&self,
user_id: &UserId,
device_id: &DeviceId,
session_info: &SessionInfo,
) {
if session_info.previous_refresh_token.is_some() {
let mut session_info = session_info.clone();
session_info.previous_refresh_token = None;
self.db
.userdeviceid_oauthsessioninfo
.put((user_id, device_id), Json(session_info));
}
}
pub async fn request_authorization_code(
&self,
authorizing_user: OwnedUserId,
@@ -645,6 +675,7 @@ impl Service {
SessionInfo {
client_id: client_id.clone(),
current_refresh_token: Self::generate_token(),
previous_refresh_token: None,
scopes: requested_scopes.scopes,
temporary_scopes: BTreeSet::new(),
}
@@ -702,15 +733,53 @@ impl Service {
assert_eq!(&client_id, &session_info.client_id, "session info client id mismatch");
// TODO: this doesn't include the device ID "scope", do any clients rely
// on that?
let scope = session_info.scopes.iter().join(" ");
let new_refresh_token = Self::generate_token();
if refresh_token == session_info.current_refresh_token {
// The client is refreshing with their current refresh token.
// We need to generate a new refresh token and save this token as
// the previous one.
session_info
.current_refresh_token
.clone_from(&new_refresh_token);
// Remove the old previous token if it's set. This can only happen
// if the client decides to refresh twice in a row without using its
// new access token, since we'll also do this when the new access
// token is used for the first time.
if let Some(previous_refresh_token) = session_info.previous_refresh_token {
self.db
.refreshtoken_refreshtokeninfo
.remove(&previous_refresh_token);
}
session_info.previous_refresh_token = Some(refresh_token);
} else if Some(&refresh_token) == session_info.previous_refresh_token.as_ref() {
// The client is refreshing with their previous refresh token,
// probably because they didn't get the new one we made for them. We
// need to make a second new one, but we don't touch the existing
// previous one in case they don't get the second new one either.
// Wipe the current token, we're going to make a new one.
self.db
.refreshtoken_refreshtokeninfo
.remove(&session_info.current_refresh_token);
session_info
.current_refresh_token
.clone_from(&new_refresh_token);
} else {
// The client is trying to use a refresh token that isn't their
// current or previous one, but still has information in the
// database. This is definitely not a legal state, so we need to
// bail out.
panic!("refresh token is not current or previous for its session");
}
let scope = session_info.scope_string(&refresh_token_info.device_id);
let new_access_token = DeviceToken::new_random().with_max_age(Self::ACCESS_TOKEN_MAX_AGE);
let new_refresh_token = Self::generate_token();
session_info
.current_refresh_token
.clone_from(&new_refresh_token);
self.services
.users
@@ -729,8 +798,6 @@ impl Service {
Json(session_info),
);
self.db.refreshtoken_refreshtokeninfo.remove(&refresh_token);
drop(refresh_token);
self.db
.refreshtoken_refreshtokeninfo
.raw_put(&new_refresh_token, Json(refresh_token_info));
+6
View File
@@ -632,6 +632,12 @@ impl super::Service {
}
}
// Discard this device's previous token entry if the current token
// isn't expired.
self.db
.userdeviceid_previoustoken
.del((&user_id, &device_id));
Some((user_id, device_id, AccessTokenStatus::Valid))
}
+17 -1
View File
@@ -184,8 +184,13 @@ impl super::Service {
// Remove old token
if let Ok(old_token) = self.db.userdeviceid_token.qry(&key).await {
self.db.token_userdeviceid.remove(&old_token);
self.db.userdeviceid_tokenexpires.remove(&old_token);
// It will be removed from userdeviceid_token by the insert later
// Save the previous token only if we don't already have one saved
// for this device.
if !self.db.userdeviceid_previoustoken.contains(&key).await {
self.db.userdeviceid_previoustoken.put_raw(key, &old_token);
}
}
// Assign token to user device combination
@@ -207,6 +212,17 @@ impl super::Service {
Ok(())
}
/// Returns whether the provided token was previously used by a device
/// before a token refresh, and therefore should cause a soft-logout.
pub async fn is_previous_token(&self, token: &str) -> bool {
self.db
.userdeviceid_previoustoken
.stream::<Ignore, String>()
.ignore_err()
.ready_any(|(_, previous_token)| previous_token == token)
.await
}
/// Pushes a new to-device event into a device's inbox.
pub async fn add_to_device_event(
&self,
+2
View File
@@ -83,6 +83,7 @@ struct Data {
userdeviceid_tokenexpires: Arc<Map>,
userdeviceid_metadata: Arc<Map>,
userdeviceid_token: Arc<Map>,
userdeviceid_previoustoken: Arc<Map>,
userfilterid_filter: Arc<Map>,
userid_avatarurl: Arc<Map>,
userid_deactivated: Arc<Map>,
@@ -134,6 +135,7 @@ impl crate::Service for Service {
remoteuserid_remoteuser: args.db["remoteuserid_remoteuser"].clone(),
userdeviceid_metadata: args.db["userdeviceid_metadata"].clone(),
userdeviceid_token: args.db["userdeviceid_token"].clone(),
userdeviceid_previoustoken: args.db["userdeviceid_previoustoken"].clone(),
userfilterid_filter: args.db["userfilterid_filter"].clone(),
userid_avatarurl: args.db["userid_avatarurl"].clone(),
userid_deactivated: args.db["userid_deactivated"].clone(),