mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-28 19:37:32 +00:00
Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b72a90b6a | ||
|
|
6fd851ffd4 | ||
|
|
034435d2b1 | ||
|
|
1c05735db6 | ||
|
|
cded6d4c36 | ||
|
|
8ad4374274 | ||
|
|
f0198d6254 | ||
|
|
b85a4ce194 | ||
|
|
67332244b7 | ||
|
|
51a9ddb27b | ||
|
|
0d7fb27d0b | ||
|
|
dc7daefe5a | ||
|
|
eb9e09d53b | ||
|
|
ef24867786 | ||
|
|
6412a650a5 | ||
|
|
25464134d8 | ||
|
|
7bdfea0704 | ||
|
|
47828dd8c2 | ||
|
|
208a625163 | ||
|
|
f579859f22 |
No files matched your search
@@ -81,3 +81,13 @@ jobs:
|
||||
--expires 14 \
|
||||
--comment "${{ forgejo.sha }}" \
|
||||
--verbose
|
||||
|
||||
- name: Post comment to PR
|
||||
if: github.ref != 'refs/heads/main' && forgejo.event.name == 'pull_request'
|
||||
run: |
|
||||
if curl -s ${{ forgejo.api_url }}/repos/${{ forgejo.repository }}/issues/${{ forgejo.event.number }}/comments | grep -qv 'PR-PREVIEW-MARKER'; then
|
||||
echo -n 'Posting comment: '
|
||||
curl -s -X POST ${{ forgejo.api_url }}/repos/${{ forgejo.repository }}/issues/${{ forgejo.event.number }}/comments \
|
||||
-H 'Authorization: token ${{ forgejo.token }}' \
|
||||
--json '{"body":"<!--PR-PREVIEW-MARKER-->Preview ready: https://preview.continuwuity.org/@${{ forgejo.event.number }}/"}'
|
||||
fi
|
||||
+101
@@ -1,3 +1,104 @@
|
||||
# Continuwuity v26.11.0-rc.1 (2026-11-27)
|
||||
|
||||
## Features
|
||||
|
||||
- Added opt-in OpenTelemetry metrics, exported over OTLP or scraped by Prometheus from `/_continuwuity/metrics`, and a Grafana dashboard. Contributed by @eleboucher. (prometheus-metrics)
|
||||
- Add support for using custom DNS servers instead of using /etc/resolv.conf. Contributed by @s1lv3r. ([#2056](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2056))
|
||||
- Continuwuity now supports configuring additional trusted audience values for deployments using OIDC with an IDP that sends them. Contributed by @ginger ([#2226](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2226))
|
||||
- "!admin users list" now hides deactivated users by default, but can display them with the optional "--show-deactivated" flag. "--hide-suspended" and "--hide-locked" have been added as well, which stop suspended and locked users from being displayed respectively. Contributed by @Clubs. ([#2292](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2292))
|
||||
- Added support for [MSC4494: Membership-based invite blocking](https://github.com/matrix-org/matrix-spec-proposals/pull/4494) ([#2297](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2297))
|
||||
- Added support for acting as a trusted server, meaning the `trusted_servers` list can consist of servers that are either Synapse OR continuwuity. ([#2314](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2314))
|
||||
- Appservices now receive typing indicators and read receipts. Contributed by @Jade ([#2327](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2327))
|
||||
- Added support for servers returning 410 gone to indicate they are no longer serving a Matrix server ([MSC4188](https://github.com/matrix-org/matrix-spec-proposals/pull/4188)). Contributed by @nex and @silversys ([#2355](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2355))
|
||||
- Added support for [MSC4388](https://github.com/matrix-org/matrix-spec-proposals/pull/4388), allowing compatible Matrix clients to log in to Continuwuity by scanning a QR code on an already logged-in client. Contributed by @ginger. ([#2429](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2429))
|
||||
- Changed the policy on unstable features, disabling most by default and making them configurable in a tidy little `experiments` configuration. See also: #1884. ([#2517](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2517))
|
||||
- Dropped support for `hardened_malloc` and add support for `mimalloc` instead. Contributed by @nex and @jade. ([#2564](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2564))
|
||||
- Continuwuity will now request the `profile` OIDC scope from identity providers by default to improve compatibility with identity providers that require it to access users' profile claims, as recommended by the OIDC specification. Contributed by @ginger. ([#2588](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2588))
|
||||
- Advertise support for Matrix v1.6. Contributed by @jade ([#2593](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2593))
|
||||
- Added support for [MSC4363](https://github.com/matrix-org/matrix-spec-proposals/pull/4363) (OAuth step-up authentication). Contributed by @ginger.
|
||||
- Added support for [MSC2815](https://github.com/matrix-org/matrix-spec-proposals/pull/2815), allowing room moderators to fetch the original content of redacted events, behind the `allow_moderators_to_view_redacted_content` config option. Contributed by @eleboucher.
|
||||
- Added support for [MSC4484](https://github.com/matrix-org/matrix-spec-proposals/pull/4484). Clients which use the built-in Matrix server administration APIs will need to ask for the appropriate scope when signing in with OAuth. Contributed by @ginger.
|
||||
- Added support for the stable MatrixRTC transports discovery endpoint (`GET /_matrix/client/v1/rtc/transports`) from the accepted [MSC4143](https://github.com/matrix-org/matrix-spec-proposals/pull/4143), advertised via the `org.matrix.msc4143.stable` unstable feature. The unstable endpoint remains available. Contributed by @Henry-Hiles (QuadRadical).
|
||||
- Added the `GET /_matrix/client/v1/rooms/{roomId}/timestamp_to_event` endpoint as per [MSC3030](https://github.com/matrix-org/matrix-spec-proposals/pull/3030), letting clients find the event closest to a given timestamp. Contributed by @eleboucher.
|
||||
- Check content-type header on federation responses, ignoring any that don't match (spec compliance)
|
||||
- Implemented unstable support for [MSC4560] (Stripped state requests over federation). Contributed by @ginger.
|
||||
|
||||
[MSC4560]: https://github.com/matrix-org/matrix-spec-proposals/pull/4560
|
||||
- Profile banners are now treated as images when imported from OIDC claims, like avatars already were.
|
||||
- Remove support for legacy, unauthenticated media, including the `allow_legacy_media` and `freeze_legacy_media` options.
|
||||
- The first-run version of the web UI now includes a link to the registration page. Contributed by @ginger
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Fixed `/get_missing_events` rejecting requests with more `earliest_events` than the `limit`. Contributed by @eleboucher. (get-missing-events-earliest-limit)
|
||||
- Fix outgoing federation stalling after a sender worker panics. Contributed by @eleboucher. (sender-supervision)
|
||||
- Invitees are now added as room creators when creating a v12+ trusted private chat. Contributed by @ginger. ([#2162](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2162))
|
||||
- Fixed push gateway URLs containing the configured notification path outside of their suffix. Contributed by @eleboucher. ([#2261](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2261))
|
||||
- "!admin users change-email" now verifies a user exists before attempting to change their email. Contributed by @Clubs. ([#2298](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2298))
|
||||
- Fixed URL preview image MIME types and rejected failed downloads. Contributed by @eleboucher. ([#2308](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2308))
|
||||
- Correctly set RocksDB column options, including enabling block caches. Contributed by @Jade ([#2345](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2345))
|
||||
- Fix some possible deadlocks/freezes and reduce lock contention (improving performance). Contributed by @Jade ([#2351](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2351))
|
||||
- Fixed Prometheus accounting for in-flight requests, federation PDU lag, latency buckets, and thumbnail sizes. Contributed by @eleboucher. ([#2354](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2354))
|
||||
- Once again fixed how room extremities are handled, fixing a problem that made continuwuity gradually make rooms needlessly complex, which also caused more frequent state resets. ([#2356](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2356))
|
||||
- Requests waiting on `/_matrix/client/v3/sync` can now be interrupted by the server shutdown, unblocking the 30-second shutdown delay imposed on a quiet server. ([#2361](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2361))
|
||||
- The OAuth identity reset page is no longer linked from the account management UI to reduce confusion. Contributed by @ginger. ([#2383](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2383))
|
||||
- Fixed a worker panic when knocking on a room over federation. Contributed by @eleboucher. ([#2387](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2387))
|
||||
- Perform more validation on events received during atomic gapfill from remote servers, fixing a panic if bad data was persisted by another server and later lazily fetched by us. ([#2400](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2400))
|
||||
- Fix remote server key signature verification when extra fields exist. Contributed by @hexchen ([#2415](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2415))
|
||||
- Redirect URIs in OAuth clients' metadata are now properly validated to be on a subdomain of the OAuth issuer URL domain. Contributed by @ginger. ([#2421](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2421))
|
||||
- Fix v12 rooms created by the same user in the same millisecond ending up as the same room. Contributed by @eleboucher. ([#2424](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2424))
|
||||
- Client-server API endpoints are now properly ratelimited for unauthenticated requests. Contributed by @ginger. ([#2444](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2444))
|
||||
- URL previews no longer completely fail if downloading auxiliary content (images/videos/audio) fails. Contributed by @nex. ([#2448](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2448))
|
||||
- Setting a profile key longer than 255 bytes now returns 400 `M_KEY_TOO_LARGE` as required by the spec, instead of 413 `M_TOO_LARGE`. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- Setting profile data that would make the profile exceed 64 KiB now returns 400 `M_PROFILE_TOO_LARGE` as required by the spec, instead of a 500 error. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- Appservices masquerading as a device that does not exist now receive 400 `M_UNKNOWN_DEVICE` as required by the spec, instead of 403 `M_FORBIDDEN`. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- Setting `m.fully_read` via the account data endpoints now returns 405 `M_BAD_JSON` as required by the spec, instead of 400. ([#2451](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2451))
|
||||
- The `m.forget_forced_upon_leave` capability now reflects the `forget_forced_upon_leave` config option instead of always being advertised as enabled. ([#2452](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2452))
|
||||
- Fixed push notifications for membership events setting `user_is_target` based on the sender rather than the user being notified. ([#2454](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2454))
|
||||
- Ensure HTTP clients actually follow the `dns_servers` config option. Contributed by @silversys ([#2460](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2460))
|
||||
- `/_matrix/client/v3/sync` no longer waits 30 seconds if the `timeout` parameter is omitted or set to zero, correctly reflecting the specification's rule that such requests should return immediately, even if they are empty. ([#2462](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2462))
|
||||
- Reworked event relations to follow the spec more closely. Pagination of `/relations` now returns the correct pages and `next_batch` tokens, recursive relations are returned in the right order without duplicates, and bundled `m.reference` aggregations now include every reference. Contributed by @Henry-Hiles (QuadRadical). ([#2465](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2465))
|
||||
- Read receipts are now more spec compliant, will work better in threads and are less likely to end up causing loops with other software. Contributed by @Jade ([#2481](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2481))
|
||||
- Fix the DNS resolver failing to start without `/etc/resolv.conf` when `dns_servers` is configured. Contributed by @eleboucher. ([#2495](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2495))
|
||||
- Fixed OIDC logins failing after the identity provider rotates its signing keys. Contributed by @eleboucher. ([#2497](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2497))
|
||||
- Fixed the experiments implementation in #2517 not properly disabling some functionality when associated experiments weren't enabled. ([#2533](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2533))
|
||||
- The sticky events feature flag is correctly advertised in `/_matrix/client/versions` again after it was accidentally removed in #2517. ([#2542](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2542))
|
||||
- A message is now sent to the admin room when a user logs in for the first time through an OIDC provider, if admin room notices are enabled. Contributed by @ginger. ([#2561](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2561))
|
||||
- Fix soundness and correctness issues in the jemalloc interface, improving performance. Contributed by @Jade ([#2565](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2565))
|
||||
- Modernised the room knocking helper functions to make them match the behaviour of our room join helpers, which are safer and more efficient. This also fixes a bug that caused an error when knocking on rooms not local to the server. Contributed by @nex. ([#2572](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2572))
|
||||
- Network issues while refreshing an access token will no longer cause OAuth-compatible clients to be forcibly logged out. Contributed by @ginger. ([#2587](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2587))
|
||||
- Attempting to start a UIAA session on a homeserver with UIAA disabled will now return `403 M_UNAUTHORIZED` instead of `404 M_UNSUPPORTED`. Contributed by @ginger. ([#2589](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2589))
|
||||
- Creating a room with valid but non-canonical JSON now returns `400 M_BAD_JSON` instead of panicking the worker and returning `500 M_UNKNOWN`.
|
||||
- Fix account data updates sent at the same time leaving old copies behind, which every initial sync then returned. Existing copies are removed on startup. Contributed by @eleboucher.
|
||||
- Fix gap filling skipping outlier events that are missing their previous events. Contributed by @eleboucher.
|
||||
- Fix incoming federation events losing state changes when predecessors share the same state-before snapshot. Contributed by @eleboucher.
|
||||
- Fix new devices sometimes never reaching other users' device lists. Contributed by @eleboucher.
|
||||
- Fix state resolution applying events out of order, which could undo room joins. Contributed by @eleboucher.
|
||||
- Fix to-device messages, including room keys, sometimes being lost before delivery. Contributed by @eleboucher.
|
||||
- For deployments using OIDC with `profile_key_import_mode` set to `on_login`, users' avatars will no longer be clobbered if they didn't change their avatar since their last login.
|
||||
- Joining a local room the user is not allowed to join now returns `403 M_FORBIDDEN` instead of `500 M_UNKNOWN` when there are no other servers to try.
|
||||
- Legacy `/sync` now honours the `room.rooms`, `room.not_rooms`, `account_data.types` and `account_data.not_types` filter fields instead of returning every room and all account data. Contributed by @eleboucher.
|
||||
- Room summary visibility checks are no longer incorrectly applied for remote rooms. Contributed by @ginger.
|
||||
- The userinfo endpoint is now accessible even if federation is disabled, allowing LiveKit to be used on servers with federation disabled without using the server name whitelist.
|
||||
|
||||
## Improved Documentation
|
||||
|
||||
- Add the Authentication section to document available auth methods for Continuwuity. The "delegated authentication" guide has also been migrated to here. Contributed by @stratself. ([#2234](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2234))
|
||||
- Add a guide for push notifications, detailing how it works, push gateway specifics, troubleshooting common issues, and pointing to external guides for UnifiedPush backends. Contributed by @stratself ([#2244](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2244))
|
||||
- The deploying page now includes vital general information about installing Continuwuity: release tracks, update steps, and post-installation recommendations. Contributed by @stratself ([#2252](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2252))
|
||||
- Add some missing instructions on configuring Continuwuity on the RPM page. Users are encouraged to use the [generic deploying docs](https://continuwuity.org/deploying/generic) for the bulk of guidance anyhow. Contributed by @stratself ([#2275](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2275))
|
||||
- Better, more succinct [introduction page](https://continuwuity.org/introduction.html). Contributed by @stratself ([#2279](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2279))
|
||||
- Add a section on [troubleshooting Docker issues](https://continuwuity.org/troubleshooting#docker-issues). Contributed by @stratself. ([#2324](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2324))
|
||||
- Instructions for Authelia added to the [OIDC guide](https://continuwuity.org/authentication/oidc.html). Contributed by @fhoekstra ([#2341](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2341))
|
||||
- Docker compose examples now use bind mounts by default, instead of Docker volumes, as they are easier to work with esp. for backup/restore. Contributed by @stratself. ([#2353](https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2353))
|
||||
- The documentation now refers to the Continuwuity Docker service as `continuwuity` instead of `homeserver`.
|
||||
|
||||
## Misc
|
||||
|
||||
- #2423, #2556, #2595
|
||||
- Upgraded rocksdb from 11.1.1 to 11.12.0 and jemalloc to 5.4.0.
|
||||
|
||||
|
||||
# Continuwuity v26.11.0-alpha.2 (2026-11-14)
|
||||
|
||||
## Features
|
||||
|
||||
Generated
+12
-12
@@ -871,7 +871,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"conduwuit_build_metadata",
|
||||
@@ -903,7 +903,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_admin"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"conduwuit_api",
|
||||
@@ -927,7 +927,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_api"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"base64 0.23.1",
|
||||
@@ -960,7 +960,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_build_metadata"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"built",
|
||||
"cargo_metadata",
|
||||
@@ -968,7 +968,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_core"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"argon2",
|
||||
"arrayvec",
|
||||
@@ -1038,7 +1038,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_database"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"conduwuit_core",
|
||||
@@ -1058,7 +1058,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_macros"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"itertools 0.15.0",
|
||||
"proc-macro2",
|
||||
@@ -1068,7 +1068,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_router"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-server",
|
||||
@@ -1101,7 +1101,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_service"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"assign",
|
||||
@@ -1158,7 +1158,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "conduwuit_web"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"async-trait",
|
||||
@@ -5185,7 +5185,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruminuwuity"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"http",
|
||||
@@ -7368,7 +7368,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "xtask"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"cargo_metadata",
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ license = "Apache-2.0"
|
||||
# See also `rust-toolchain.toml`
|
||||
readme = "README.md"
|
||||
repository = "https://forgejo.ellis.link/continuwuation/continuwuity"
|
||||
version = "26.11.0-alpha.2"
|
||||
version = "26.11.0-rc.1"
|
||||
|
||||
[workspace.metadata.crane]
|
||||
name = "conduwuit"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Rejected events are no longer used as auth events during state resolution.
|
||||
@@ -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.
|
||||
@@ -0,0 +1 @@
|
||||
Fix minor Matrix state resolution bugs where some events were incorrectly prioritised. Contributed by @Jade
|
||||
@@ -44,6 +44,29 @@ appservice can send requests to the homeserver. You don't need to restart
|
||||
Continuwuity, but if it doesn't work, restarting while the appservice is running
|
||||
could help.
|
||||
|
||||
### Changing parts of the appservice configuration
|
||||
|
||||
If you want to change an option in the yaml configuration without
|
||||
re-registering, you can send the `!admin appservices register` command again,
|
||||
making sure that the `id` is the same.
|
||||
|
||||
For example, take this registration yaml:
|
||||
~~~txt
|
||||
!admin appservices register
|
||||
```
|
||||
id: meowlnir
|
||||
url: https://url-i-just-changed.com
|
||||
...other options below
|
||||
```
|
||||
~~~
|
||||
|
||||
This new configuration will be applied immediately. Note that this *replaces*
|
||||
the prior configuration. You must send the complete configuration, changing the
|
||||
fields you want to change.
|
||||
|
||||
You can see the current configuration using `!admin appservices
|
||||
show-appservice-config <id>`.
|
||||
|
||||
## Appservice-specific instructions
|
||||
|
||||
### Remove an appservice
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { normalizeImagePath } from '@rspress/core/runtime';
|
||||
|
||||
<div align="center">
|
||||
|
||||
<img src="/assets/logo.svg" width="150"/>
|
||||
<img src={normalizeImagePath("/assets/logo.svg")} width="150"/>
|
||||
|
||||
# Continuwuity
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ use ruma::{
|
||||
},
|
||||
assign,
|
||||
};
|
||||
use service::users::DeviceToken;
|
||||
use service::users::{DeviceToken, PreviousTokenAction};
|
||||
|
||||
use crate::{Ruma, client_ip::ClientIp};
|
||||
|
||||
@@ -205,7 +205,7 @@ pub(crate) async fn login_route(
|
||||
let device_id = if let Some(existing_device_id) = existing_device_id {
|
||||
services
|
||||
.users
|
||||
.set_token(&user_id, &existing_device_id, token.clone())
|
||||
.set_token(&user_id, &existing_device_id, token.clone(), PreviousTokenAction::Clear)
|
||||
.await?;
|
||||
|
||||
existing_device_id
|
||||
|
||||
+24
-6
@@ -319,6 +319,21 @@ async fn check_access_token(
|
||||
));
|
||||
}
|
||||
|
||||
let session_info = services
|
||||
.oauth
|
||||
.get_session_info_for_device(&sender_user, &sender_device)
|
||||
.await;
|
||||
|
||||
if session_info
|
||||
.as_ref()
|
||||
.is_some_and(service::oauth::SessionInfo::has_previous_refresh_token)
|
||||
{
|
||||
services
|
||||
.oauth
|
||||
.clear_previous_refresh_token(&sender_user, &sender_device)
|
||||
.await;
|
||||
}
|
||||
|
||||
// Locked users can only use /logout and /logout/all
|
||||
if services
|
||||
.users
|
||||
@@ -333,12 +348,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 +425,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()),
|
||||
|
||||
@@ -25,6 +25,7 @@ use serde_json::{
|
||||
value::{RawValue as RawJsonValue, to_raw_value as to_raw_json_value},
|
||||
};
|
||||
|
||||
use super::test_utils::not_rejected;
|
||||
use crate::{
|
||||
matrix::{Event, Pdu, pdu::EventHash},
|
||||
state_res::{self as state_res, Error, Result, StateMap},
|
||||
@@ -78,6 +79,7 @@ fn resolution_shallow_auth_chain(c: &mut test::Bencher) {
|
||||
&auth_chain_sets,
|
||||
&fetch,
|
||||
&exists,
|
||||
¬_rejected,
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -151,6 +153,7 @@ fn resolve_deeper_event_set(c: &mut test::Bencher) {
|
||||
&auth_chain_sets,
|
||||
&fetch,
|
||||
&exists,
|
||||
¬_rejected,
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -20,10 +20,13 @@ use std::{
|
||||
|
||||
use futures::{Future, FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, future};
|
||||
use ruma::{
|
||||
EventId, Int, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId,
|
||||
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId,
|
||||
events::{
|
||||
StateEventType, TimelineEventType,
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
room::{
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
power_levels::UserPowerLevel,
|
||||
},
|
||||
},
|
||||
int,
|
||||
room_version_rules::{RoomIdFormatVersion, RoomVersionRules, StateResolutionVersion},
|
||||
@@ -75,18 +78,33 @@ type Result<T, E = Error> = crate::Result<T, E>;
|
||||
//#[tracing::instrument(level = "debug", skip(state_sets, auth_chain_sets,
|
||||
//#[tracing::instrument(level event_fetch))]
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
pub async fn resolve<'a, Pdu, Sets, SetIter, Hasher, Fetch, FetchFut, Exists, ExistsFut>(
|
||||
pub async fn resolve<
|
||||
'a,
|
||||
Pdu,
|
||||
Sets,
|
||||
SetIter,
|
||||
Hasher,
|
||||
Fetch,
|
||||
FetchFut,
|
||||
Exists,
|
||||
ExistsFut,
|
||||
Rejected,
|
||||
RejectedFut,
|
||||
>(
|
||||
room_version: &RoomVersionRules,
|
||||
state_sets: Sets,
|
||||
auth_chain_sets: &'a [HashSet<OwnedEventId, Hasher>],
|
||||
event_fetch: &Fetch,
|
||||
event_exists: &Exists,
|
||||
is_rejected: &Rejected,
|
||||
) -> Result<StateMap<OwnedEventId>>
|
||||
where
|
||||
Fetch: Fn(OwnedEventId) -> FetchFut + Sync,
|
||||
FetchFut: Future<Output = Option<Pdu>> + Send,
|
||||
Exists: Fn(OwnedEventId) -> ExistsFut + Sync,
|
||||
ExistsFut: Future<Output = bool> + Send,
|
||||
Rejected: Fn(OwnedEventId) -> RejectedFut + Sync,
|
||||
RejectedFut: Future<Output = bool> + Send,
|
||||
Sets: IntoIterator<IntoIter = SetIter> + Send,
|
||||
SetIter: Iterator<Item = &'a StateMap<OwnedEventId>> + Clone + Send,
|
||||
Hasher: BuildHasher + Send + Sync,
|
||||
@@ -174,6 +192,7 @@ where
|
||||
sorted_control_levels.iter().stream().map(AsRef::as_ref),
|
||||
initial_state,
|
||||
&event_fetch,
|
||||
is_rejected,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -214,6 +233,7 @@ where
|
||||
sorted_left_events.iter().stream().map(AsRef::as_ref),
|
||||
resolved_control, // The control events are added to the final resolved state
|
||||
&event_fetch,
|
||||
is_rejected,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -394,7 +414,7 @@ where
|
||||
.inspect(|(event_id, pl)| {
|
||||
debug!(
|
||||
event_id = event_id.as_str(),
|
||||
power_level = i64::from(*pl),
|
||||
power_level = ?pl,
|
||||
"found the power level of an event's sender",
|
||||
);
|
||||
})
|
||||
@@ -422,27 +442,29 @@ where
|
||||
/// `key_fn` is used as to obtain the power level and age of an event for
|
||||
/// breaking ties (together with the event ID).
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
pub async fn lexicographical_topological_sort<Id, F, Fut, Hasher, S>(
|
||||
pub async fn lexicographical_topological_sort<Id, P, F, Fut, Hasher, S>(
|
||||
graph: &HashMap<Id, HashSet<Id, Hasher>, S>,
|
||||
key_fn: &F,
|
||||
) -> Result<Vec<Id>>
|
||||
where
|
||||
F: Fn(Id) -> Fut + Sync,
|
||||
Fut: Future<Output = Result<(Int, MilliSecondsSinceUnixEpoch)>> + Send,
|
||||
Fut: Future<Output = Result<(P, MilliSecondsSinceUnixEpoch)>> + Send,
|
||||
Id: Borrow<EventId> + Clone + Eq + Hash + Ord + Send + Sync,
|
||||
P: Ord + Send,
|
||||
Hasher: BuildHasher + Default + Clone + Send + Sync,
|
||||
S: BuildHasher + Clone + Send + Sync,
|
||||
{
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct TieBreaker<'a, Id> {
|
||||
power_level: Int,
|
||||
struct TieBreaker<'a, Id, P> {
|
||||
power_level: P,
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
event_id: &'a Id,
|
||||
}
|
||||
|
||||
impl<Id> Ord for TieBreaker<'_, Id>
|
||||
impl<Id, P> Ord for TieBreaker<'_, Id, P>
|
||||
where
|
||||
Id: Ord,
|
||||
P: Ord,
|
||||
{
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
// NOTE: the power level comparison is "backwards" intentionally.
|
||||
@@ -460,9 +482,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Id> PartialOrd for TieBreaker<'_, Id>
|
||||
impl<Id, P> PartialOrd for TieBreaker<'_, Id, P>
|
||||
where
|
||||
Id: Ord,
|
||||
P: Ord,
|
||||
{
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
|
||||
}
|
||||
@@ -552,7 +575,7 @@ async fn get_power_level_for_sender<E, F, Fut>(
|
||||
event_id: &EventId,
|
||||
room_version: &RoomVersionRules,
|
||||
fetch_event: &F,
|
||||
) -> serde_json::Result<Int>
|
||||
) -> serde_json::Result<UserPowerLevel>
|
||||
where
|
||||
F: Fn(OwnedEventId) -> Fut + Sync,
|
||||
Fut: Future<Output = Option<E>> + Send,
|
||||
@@ -561,7 +584,7 @@ where
|
||||
debug!("fetch event ({event_id}) senders power level");
|
||||
|
||||
let Some(event) = fetch_event(event_id.to_owned()).await else {
|
||||
return Ok(int!(0));
|
||||
return Ok(UserPowerLevel::Int(int!(0)));
|
||||
};
|
||||
|
||||
let auth_events: Vec<E> = event
|
||||
@@ -582,7 +605,7 @@ where
|
||||
.authorization
|
||||
.explicitly_privilege_room_creators
|
||||
{
|
||||
return Ok(Int::MAX);
|
||||
return Ok(UserPowerLevel::Infinite);
|
||||
}
|
||||
|
||||
let pl = auth_events
|
||||
@@ -592,16 +615,17 @@ where
|
||||
let content: PowerLevelsContentFields = match pl {
|
||||
// With no m.room.power_levels in scope the create event's defaults
|
||||
// apply, under which the room creator holds 100 and everyone else 0.
|
||||
| None => return Ok(if sender_is_creator { int!(100) } else { int!(0) }),
|
||||
| None =>
|
||||
return Ok(UserPowerLevel::Int(if sender_is_creator { int!(100) } else { int!(0) })),
|
||||
| Some(ev) => from_json_str(ev.content().get())?,
|
||||
};
|
||||
|
||||
if let Some(&user_level) = content.get_user_power(event.sender()) {
|
||||
debug!("found {} at power_level {user_level}", event.sender());
|
||||
return Ok(user_level);
|
||||
return Ok(UserPowerLevel::Int(user_level));
|
||||
}
|
||||
|
||||
Ok(content.users_default)
|
||||
Ok(UserPowerLevel::Int(content.users_default))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -689,15 +713,18 @@ where
|
||||
/// the the `fetch_event` closure and verify each event using the
|
||||
/// `event_auth::auth_check` function.
|
||||
#[tracing::instrument(level = "trace", skip_all)]
|
||||
async fn iterative_auth_check<'a, E, F, Fut, S>(
|
||||
async fn iterative_auth_check<'a, E, F, Fut, R, RFut, S>(
|
||||
room_version: &RoomVersionRules,
|
||||
events_to_check: S,
|
||||
unconflicted_state: StateMap<OwnedEventId>,
|
||||
fetch_event: &F,
|
||||
is_rejected: &R,
|
||||
) -> Result<StateMap<OwnedEventId>>
|
||||
where
|
||||
F: Fn(OwnedEventId) -> Fut + Sync,
|
||||
Fut: Future<Output = Option<E>> + Send,
|
||||
R: Fn(OwnedEventId) -> RFut + Sync,
|
||||
RFut: Future<Output = bool> + Send,
|
||||
S: Stream<Item = &'a EventId> + Send + 'a,
|
||||
E: Event + Clone + Send + Sync,
|
||||
for<'b> &'b E: Event + Send,
|
||||
@@ -727,18 +754,34 @@ where
|
||||
|
||||
trace!(set = ?auth_event_ids, "auth event IDs to fetch");
|
||||
|
||||
let auth_events: HashMap<OwnedEventId, E> = auth_event_ids
|
||||
let rejected_check_ids: HashSet<OwnedEventId> = auth_event_ids
|
||||
.iter()
|
||||
.chain(unconflicted_state.values())
|
||||
.cloned()
|
||||
.chain(events_to_check.iter().map(|e| e.event_id().to_owned()))
|
||||
.collect();
|
||||
|
||||
let auth_events_fut = auth_event_ids
|
||||
.into_iter()
|
||||
.stream()
|
||||
.broad_filter_map(fetch_event)
|
||||
.map(|auth_event| (auth_event.event_id().to_owned(), auth_event))
|
||||
.collect()
|
||||
.boxed()
|
||||
.await;
|
||||
.collect::<HashMap<OwnedEventId, E>>()
|
||||
.boxed();
|
||||
|
||||
let rejected_events_fut = rejected_check_ids
|
||||
.into_iter()
|
||||
.stream()
|
||||
.broad_filter_map(|id| async move { is_rejected(id.clone()).await.then_some(id) })
|
||||
.collect::<HashSet<OwnedEventId>>()
|
||||
.boxed();
|
||||
|
||||
let (auth_events, rejected_events) = future::join(auth_events_fut, rejected_events_fut).await;
|
||||
|
||||
trace!(map = ?auth_events.keys().collect::<Vec<_>>(), "fetched auth events");
|
||||
|
||||
let auth_events = &auth_events;
|
||||
let rejected_events = &rejected_events;
|
||||
// NOTE: in state resolution v2.1, auth checks should start with an empty
|
||||
// state map. It is the caller's job to do this. Previously, this function
|
||||
// would force an empty state map in this case, and this resulted in power
|
||||
@@ -747,6 +790,7 @@ where
|
||||
let mut resolved_state = unconflicted_state;
|
||||
for event in events_to_check {
|
||||
trace!(event_id = event.event_id().as_str(), "checking event");
|
||||
|
||||
let state_key = event
|
||||
.state_key()
|
||||
.ok_or_else(|| Error::InvalidPdu("State event had no state key".to_owned()))?;
|
||||
@@ -777,8 +821,9 @@ where
|
||||
}
|
||||
for aid in event.auth_events() {
|
||||
if let Some(ev) = auth_events.get(aid) {
|
||||
//TODO: synapse checks "rejected_reason" which is most likely
|
||||
// related to soft-failing
|
||||
if rejected_events.contains(aid) {
|
||||
continue;
|
||||
}
|
||||
trace!(event_id = aid.as_str(), "found auth event");
|
||||
auth_state.insert(
|
||||
ev.event_type()
|
||||
@@ -797,6 +842,9 @@ where
|
||||
.stream()
|
||||
.ready_filter_map(|key| Some((key, resolved_state.get(key)?)))
|
||||
.filter_map(|(key, ev_id)| async move {
|
||||
if rejected_events.contains(ev_id) {
|
||||
return None;
|
||||
}
|
||||
if let Some(event) = auth_events.get(ev_id) {
|
||||
Some((key, event.clone()))
|
||||
} else {
|
||||
@@ -804,7 +852,6 @@ where
|
||||
}
|
||||
})
|
||||
.ready_for_each(|(key, event)| {
|
||||
//TODO: synapse checks "rejected_reason" is None here
|
||||
auth_state.insert(key.to_owned(), event);
|
||||
})
|
||||
.await;
|
||||
@@ -926,11 +973,14 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// Reserve depth 0 for events with no mainline power-levels ancestor (spec
|
||||
// position ∞) so they always sort strictly before the oldest mainline
|
||||
// power-levels event (depth 1).
|
||||
let mainline_map: HashMap<_, _> = mainline
|
||||
.iter()
|
||||
.rev()
|
||||
.enumerate()
|
||||
.map(|(idx, eid)| ((*eid).clone(), idx))
|
||||
.map(|(idx, eid)| ((*eid).clone(), idx.saturating_add(1)))
|
||||
.collect();
|
||||
|
||||
let order_map: HashMap<_, _> = to_sort
|
||||
@@ -1095,7 +1145,10 @@ mod tests {
|
||||
MilliSecondsSinceUnixEpoch, OwnedEventId, RoomVersionId,
|
||||
events::{
|
||||
StateEventType, TimelineEventType,
|
||||
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
room::{
|
||||
join_rules::{JoinRule, RoomJoinRulesEventContent},
|
||||
power_levels::UserPowerLevel,
|
||||
},
|
||||
},
|
||||
int,
|
||||
room_version_rules::RoomVersionRules,
|
||||
@@ -1107,8 +1160,8 @@ mod tests {
|
||||
StateMap, is_power_event,
|
||||
test_utils::{
|
||||
INITIAL_EVENTS, TestStore, alice, bob, charlie, do_check, ella, event_id,
|
||||
member_content_ban, member_content_join, room_id, to_init_pdu_event, to_pdu_event,
|
||||
zara,
|
||||
member_content_ban, member_content_join, not_rejected, room_id, to_init_pdu_event,
|
||||
to_pdu_event, zara,
|
||||
},
|
||||
};
|
||||
use crate::{
|
||||
@@ -1169,6 +1222,7 @@ mod tests {
|
||||
ordered_events.iter().map(AsRef::as_ref).stream(),
|
||||
initial_state,
|
||||
&fetcher,
|
||||
¬_rejected,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -1179,6 +1233,213 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn iterative_auth_check_reauths_rejected_events() {
|
||||
let mut events = INITIAL_EVENTS();
|
||||
let initial_state = ["CREATE", "IPOWER", "IJR", "IMB"]
|
||||
.into_iter()
|
||||
.map(|id| {
|
||||
let event = &events[&event_id(id)];
|
||||
(
|
||||
event
|
||||
.event_type()
|
||||
.with_state_key(event.state_key().unwrap()),
|
||||
event.event_id.clone(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let leave = to_pdu_event(
|
||||
"LEAVE",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().as_str()),
|
||||
to_raw_json_value(&json!({ "membership": "leave" })).unwrap(),
|
||||
&["CREATE", "IPOWER", "IMB"],
|
||||
&["IMB"],
|
||||
);
|
||||
let rejoin = to_pdu_event(
|
||||
"REJOIN",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE", "IPOWER", "IJR", "LEAVE"],
|
||||
&["LEAVE"],
|
||||
);
|
||||
let ordered_events = [leave.event_id.clone(), rejoin.event_id.clone()];
|
||||
for event in [leave, rejoin] {
|
||||
events.insert(event.event_id.clone(), event);
|
||||
}
|
||||
let fetcher = |id: OwnedEventId| {
|
||||
let events = &events;
|
||||
async move { events.get(&id).cloned() }
|
||||
};
|
||||
let resolved = super::iterative_auth_check(
|
||||
&RoomVersionRules::V6,
|
||||
ordered_events.iter().map(AsRef::as_ref).stream(),
|
||||
initial_state,
|
||||
&fetcher,
|
||||
&|id| async move { id == event_id("REJOIN") },
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
resolved[&StateEventType::RoomMember.with_state_key(bob().as_str())],
|
||||
event_id("REJOIN"),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn iterative_auth_check_ignores_rejected_auth_events() {
|
||||
let mut events = INITIAL_EVENTS();
|
||||
let initial_state = ["CREATE", "IPOWER"]
|
||||
.into_iter()
|
||||
.map(|id| {
|
||||
let event = &events[&event_id(id)];
|
||||
(
|
||||
event
|
||||
.event_type()
|
||||
.with_state_key(event.state_key().unwrap()),
|
||||
event.event_id.clone(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
// Bob tries to join relying on IJR in auth_events, which is not in
|
||||
// initial_state and is marked rejected.
|
||||
let join = to_pdu_event(
|
||||
"BOB_JOIN",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().as_str()),
|
||||
member_content_join(),
|
||||
&["CREATE", "IPOWER", "IJR"],
|
||||
&["IJR"],
|
||||
);
|
||||
let ordered_events = [join.event_id.clone()];
|
||||
events.insert(join.event_id.clone(), join);
|
||||
|
||||
let fetcher = |id: OwnedEventId| {
|
||||
let events = &events;
|
||||
async move { events.get(&id).cloned() }
|
||||
};
|
||||
let resolved = super::iterative_auth_check(
|
||||
&RoomVersionRules::V6,
|
||||
ordered_events.iter().map(AsRef::as_ref).stream(),
|
||||
initial_state,
|
||||
&fetcher,
|
||||
&|id| async move { id == event_id("IJR") },
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
!resolved.contains_key(&StateEventType::RoomMember.with_state_key(bob().as_str()))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn iterative_auth_check_ignores_rejected_resolved_state() {
|
||||
let mut events = INITIAL_EVENTS();
|
||||
let ban_bob = to_pdu_event(
|
||||
"BAN_BOB",
|
||||
alice(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().as_str()),
|
||||
member_content_ban(),
|
||||
&["CREATE", "IPOWER", "IMA", "IMB"],
|
||||
&["IMB"],
|
||||
);
|
||||
let bob_leave = to_pdu_event(
|
||||
"BOB_LEAVE",
|
||||
bob(),
|
||||
TimelineEventType::RoomMember,
|
||||
Some(bob().as_str()),
|
||||
to_raw_json_value(&json!({ "membership": "leave" })).unwrap(),
|
||||
&["CREATE", "IPOWER", "IMB"],
|
||||
&["IMB"],
|
||||
);
|
||||
let ordered_events = [bob_leave.event_id.clone()];
|
||||
for event in [ban_bob, bob_leave] {
|
||||
events.insert(event.event_id.clone(), event);
|
||||
}
|
||||
// initial_state has BAN_BOB for Bob's membership, but BAN_BOB is
|
||||
// rejected, so Bob's auth check should fall back to IMB from
|
||||
// BOB_LEAVE's auth_events and succeed.
|
||||
let initial_state = ["CREATE", "IPOWER", "BAN_BOB"]
|
||||
.into_iter()
|
||||
.map(|id| {
|
||||
let event = &events[&event_id(id)];
|
||||
(
|
||||
event
|
||||
.event_type()
|
||||
.with_state_key(event.state_key().unwrap()),
|
||||
event.event_id.clone(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let fetcher = |id: OwnedEventId| {
|
||||
let events = &events;
|
||||
async move { events.get(&id).cloned() }
|
||||
};
|
||||
let resolved = super::iterative_auth_check(
|
||||
&RoomVersionRules::V6,
|
||||
ordered_events.iter().map(AsRef::as_ref).stream(),
|
||||
initial_state,
|
||||
&fetcher,
|
||||
&|id| async move { id == event_id("BAN_BOB") },
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
resolved.get(&StateEventType::RoomMember.with_state_key(bob().as_str())),
|
||||
Some(&event_id("BOB_LEAVE")),
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mainline_sort_orders_no_ancestor_before_oldest_power_level() {
|
||||
let mut events = INITIAL_EVENTS();
|
||||
let mut with_pl = to_pdu_event(
|
||||
"WITH_PL",
|
||||
alice(),
|
||||
TimelineEventType::RoomTopic,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "topic": "with pl" })).unwrap(),
|
||||
&["CREATE", "IPOWER", "IMA"],
|
||||
&["IMA"],
|
||||
);
|
||||
with_pl.origin_server_ts = uint!(50);
|
||||
|
||||
let mut no_pl = to_pdu_event(
|
||||
"NO_PL",
|
||||
alice(),
|
||||
TimelineEventType::RoomTopic,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "topic": "no pl" })).unwrap(),
|
||||
&["CREATE", "IMA"],
|
||||
&["IMA"],
|
||||
);
|
||||
no_pl.origin_server_ts = uint!(100);
|
||||
|
||||
let to_sort = [with_pl.event_id.clone(), no_pl.event_id.clone()];
|
||||
for event in [with_pl, no_pl] {
|
||||
events.insert(event.event_id.clone(), event);
|
||||
}
|
||||
let fetcher = |id: OwnedEventId| {
|
||||
let events = &events;
|
||||
async move { events.get(&id).cloned() }
|
||||
};
|
||||
|
||||
let sorted = super::mainline_sort(&to_sort, Some(event_id("IPOWER")), &fetcher)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(sorted, vec![event_id("NO_PL"), event_id("WITH_PL")]);
|
||||
}
|
||||
|
||||
/// Events at the start of a room have no `m.room.power_levels` in their
|
||||
/// auth events, so the sender's power for sort ordering comes from the
|
||||
/// create event instead.
|
||||
@@ -1219,7 +1480,11 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(power_level, int!(100), "the creator should sort with their default power");
|
||||
assert_eq!(
|
||||
power_level,
|
||||
UserPowerLevel::Int(int!(100)),
|
||||
"the creator should sort with their default power"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1269,14 +1534,83 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(alice_power, int!(100), "the content creator should sort with creator power");
|
||||
assert_eq!(
|
||||
alice_power,
|
||||
UserPowerLevel::Int(int!(100)),
|
||||
"the content creator should sort with creator power"
|
||||
);
|
||||
|
||||
let bob_power =
|
||||
super::get_power_level_for_sender(&event_id("IMB"), &RoomVersionRules::V6, &fetcher)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(bob_power, int!(0), "the create event's sender is not the creator");
|
||||
assert_eq!(
|
||||
bob_power,
|
||||
UserPowerLevel::Int(int!(0)),
|
||||
"the create event's sender is not the creator"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn v12_creator_outranks_max_int_power_level() {
|
||||
use futures::future::ready;
|
||||
use ruma::Int;
|
||||
|
||||
let mut events = INITIAL_EVENTS();
|
||||
let max_pl = to_pdu_event(
|
||||
"MAX_PL",
|
||||
alice(),
|
||||
TimelineEventType::RoomPowerLevels,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({
|
||||
"users": {
|
||||
bob(): Int::MAX,
|
||||
},
|
||||
}))
|
||||
.unwrap(),
|
||||
&["CREATE", "IMA"],
|
||||
&["IMA"],
|
||||
);
|
||||
let mut bob_event = to_pdu_event(
|
||||
"BOB_EV",
|
||||
bob(),
|
||||
TimelineEventType::RoomJoinRules,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "join_rule": "invite" })).unwrap(),
|
||||
&["CREATE", "MAX_PL", "IMB"],
|
||||
&["MAX_PL"],
|
||||
);
|
||||
bob_event.origin_server_ts = uint!(50);
|
||||
|
||||
let mut alice_event = to_pdu_event(
|
||||
"ALICE_EV",
|
||||
alice(),
|
||||
TimelineEventType::RoomJoinRules,
|
||||
Some(""),
|
||||
to_raw_json_value(&json!({ "join_rule": "public" })).unwrap(),
|
||||
&["CREATE", "MAX_PL", "IMA"],
|
||||
&["MAX_PL"],
|
||||
);
|
||||
alice_event.origin_server_ts = uint!(100);
|
||||
|
||||
let conflicted = hashset![bob_event.event_id.clone(), alice_event.event_id.clone()];
|
||||
let to_sort = vec![bob_event.event_id.clone(), alice_event.event_id.clone()];
|
||||
for event in [max_pl, bob_event, alice_event] {
|
||||
events.insert(event.event_id.clone(), event);
|
||||
}
|
||||
let fetcher = |id: OwnedEventId| ready(events.get(&id).cloned());
|
||||
|
||||
let sorted = super::reverse_topological_power_sort(
|
||||
to_sort,
|
||||
&conflicted,
|
||||
&RoomVersionRules::V12,
|
||||
&fetcher,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(sorted, vec![event_id("ALICE_EV"), event_id("BOB_EV")]);
|
||||
}
|
||||
|
||||
async fn test_event_sort() {
|
||||
@@ -1315,6 +1649,7 @@ mod tests {
|
||||
sorted_power_events.iter().map(AsRef::as_ref).stream(),
|
||||
HashMap::new(), // unconflicted events
|
||||
&fetcher,
|
||||
¬_rejected,
|
||||
)
|
||||
.await
|
||||
.expect("iterative auth check failed on resolved events");
|
||||
@@ -1717,6 +2052,7 @@ mod tests {
|
||||
&auth_chain,
|
||||
&fetcher,
|
||||
&exists,
|
||||
¬_rejected,
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -1835,6 +2171,7 @@ mod tests {
|
||||
&auth_chain,
|
||||
&fetcher,
|
||||
&exists,
|
||||
¬_rejected,
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -141,6 +141,7 @@ pub(crate) async fn do_check(
|
||||
&auth_chain_sets,
|
||||
&fetch,
|
||||
&exists,
|
||||
¬_rejected,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -363,6 +364,8 @@ impl TestStore<Pdu> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn not_rejected(_: OwnedEventId) -> bool { false }
|
||||
|
||||
pub(crate) fn event_id(id: &str) -> OwnedEventId {
|
||||
if id.contains('$') {
|
||||
return id.try_into().unwrap();
|
||||
|
||||
@@ -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
|
||||
|
||||
+139
-18
@@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
collections::{BTreeSet, HashMap},
|
||||
fmt::Write,
|
||||
sync::Arc,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
@@ -8,8 +9,9 @@ use base64::Engine;
|
||||
use conduwuit::{
|
||||
Result, SyncMutex,
|
||||
config::experiments::ToggledExperiment,
|
||||
info,
|
||||
utils::{self, hash::sha256},
|
||||
error, info,
|
||||
utils::{self, MutexMap, hash::sha256},
|
||||
warn,
|
||||
};
|
||||
use database::{Deserialized, Json, Map};
|
||||
use itertools::Itertools;
|
||||
@@ -29,15 +31,25 @@ use crate::{
|
||||
ResponseMode, TokenRequest, TokenRequestType, TokenResponse, TokenType,
|
||||
},
|
||||
},
|
||||
users::{self, DeviceToken},
|
||||
users::{self, DeviceToken, PreviousTokenAction},
|
||||
};
|
||||
|
||||
pub mod client_metadata;
|
||||
pub mod grant;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
struct SessionLockKey(OwnedUserId, OwnedDeviceId);
|
||||
|
||||
impl From<&(&UserId, &DeviceId)> for SessionLockKey {
|
||||
fn from((user_id, device_id): &(&UserId, &DeviceId)) -> Self {
|
||||
Self((*user_id).to_owned(), (*device_id).to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Service {
|
||||
services: Services,
|
||||
db: Data,
|
||||
session_mutex: MutexMap<SessionLockKey, ()>,
|
||||
tickets: SyncMutex<HashMap<String, HashMap<OAuthTicket, SystemTime>>>,
|
||||
pending_auth_code_grants: SyncMutex<LruCache<String, PendingAuthCodeGrant>>,
|
||||
pending_device_code_grants: SyncMutex<LruCache<String, PendingDeviceCodeGrant>>,
|
||||
@@ -55,7 +67,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 +76,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 +85,18 @@ impl SessionInfo {
|
||||
pub fn scopes(&self) -> BTreeSet<OAuthClientScope> {
|
||||
self.scopes.union(&self.temporary_scopes).cloned().collect()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn has_previous_refresh_token(&self) -> bool { self.previous_refresh_token.is_some() }
|
||||
|
||||
#[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)]
|
||||
@@ -171,6 +197,7 @@ impl crate::Service for Service {
|
||||
userdeviceid_oauthsessioninfo: args.db["userdeviceid_oauthsessioninfo"].clone(),
|
||||
refreshtoken_refreshtokeninfo: args.db["refreshtoken_refreshtokeninfo"].clone(),
|
||||
},
|
||||
session_mutex: MutexMap::new(),
|
||||
tickets: SyncMutex::default(),
|
||||
pending_auth_code_grants: SyncMutex::new(LruCache::new(Self::MAX_PENDING_GRANTS)),
|
||||
pending_device_code_grants: SyncMutex::new(LruCache::new(Self::MAX_PENDING_GRANTS)),
|
||||
@@ -246,6 +273,26 @@ impl Service {
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Clear a session's previous refresh token, if it has one.
|
||||
pub async fn clear_previous_refresh_token(&self, user_id: &UserId, device_id: &DeviceId) {
|
||||
let _lock = self.session_mutex.lock(&(user_id, device_id)).await;
|
||||
|
||||
let Some(mut session_info) = self.get_session_info_for_device(user_id, device_id).await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(previous_refresh_token) = session_info.previous_refresh_token.take() {
|
||||
self.db
|
||||
.refreshtoken_refreshtokeninfo
|
||||
.remove(&previous_refresh_token);
|
||||
|
||||
self.db
|
||||
.userdeviceid_oauthsessioninfo
|
||||
.put((user_id, device_id), Json(session_info));
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn request_authorization_code(
|
||||
&self,
|
||||
authorizing_user: OwnedUserId,
|
||||
@@ -573,6 +620,11 @@ impl Service {
|
||||
.device_id
|
||||
.ok_or_else(|| OAuthError::invalid_grant("No device ID scope supplied"))?;
|
||||
|
||||
let _lock = self
|
||||
.session_mutex
|
||||
.lock(&(&*authorizing_user, &*device_id))
|
||||
.await;
|
||||
|
||||
let session_info = if self
|
||||
.services
|
||||
.users
|
||||
@@ -606,7 +658,12 @@ impl Service {
|
||||
|
||||
self.services
|
||||
.users
|
||||
.set_token(&authorizing_user, &device_id, access_token.clone())
|
||||
.set_token(
|
||||
&authorizing_user,
|
||||
&device_id,
|
||||
access_token.clone(),
|
||||
PreviousTokenAction::Replace,
|
||||
)
|
||||
.await
|
||||
.expect("should be able to set access token");
|
||||
|
||||
@@ -645,6 +702,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(),
|
||||
}
|
||||
@@ -692,25 +750,85 @@ impl Service {
|
||||
|
||||
assert_eq!(&client_id, &refresh_token_info.client_id, "refresh token client id mismatch");
|
||||
|
||||
let mut session_info = self
|
||||
let _lock = self
|
||||
.session_mutex
|
||||
.lock(&(&*refresh_token_info.user_id, &*refresh_token_info.device_id))
|
||||
.await;
|
||||
|
||||
let Some(mut session_info) = self
|
||||
.get_session_info_for_device(
|
||||
&refresh_token_info.user_id,
|
||||
&refresh_token_info.device_id,
|
||||
)
|
||||
.await
|
||||
.expect("session info should exist");
|
||||
else {
|
||||
warn!(
|
||||
user_id = ?refresh_token_info.user_id,
|
||||
device_id = ?refresh_token_info.device_id,
|
||||
"Refresh token exists for a missing OAuth session"
|
||||
);
|
||||
self.db.refreshtoken_refreshtokeninfo.remove(&refresh_token);
|
||||
return Err(OAuthError::invalid_grant("Invalid refresh token"));
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
let previous_token_action = 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);
|
||||
PreviousTokenAction::Replace
|
||||
} 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);
|
||||
PreviousTokenAction::Preserve
|
||||
} 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. Clean up the stale entry and reject the grant.
|
||||
error!(
|
||||
user_id = ?refresh_token_info.user_id,
|
||||
device_id = ?refresh_token_info.device_id,
|
||||
"Refresh token is neither current nor previous for its session"
|
||||
);
|
||||
self.db.refreshtoken_refreshtokeninfo.remove(&refresh_token);
|
||||
return Err(OAuthError::invalid_grant("Invalid refresh token"));
|
||||
};
|
||||
|
||||
session_info.temporary_scopes.clear();
|
||||
|
||||
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
|
||||
@@ -718,19 +836,16 @@ impl Service {
|
||||
&refresh_token_info.user_id,
|
||||
&refresh_token_info.device_id,
|
||||
new_access_token.clone(),
|
||||
previous_token_action,
|
||||
)
|
||||
.await
|
||||
.expect("should be able to set token");
|
||||
|
||||
session_info.temporary_scopes.clear();
|
||||
|
||||
self.db.userdeviceid_oauthsessioninfo.put(
|
||||
(&refresh_token_info.user_id, &refresh_token_info.device_id),
|
||||
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));
|
||||
@@ -745,12 +860,18 @@ impl Service {
|
||||
}
|
||||
|
||||
pub async fn remove_session(&self, user_id: &UserId, device_id: &DeviceId) {
|
||||
let _lock = self.session_mutex.lock(&(user_id, device_id)).await;
|
||||
let session_info = self.get_session_info_for_device(user_id, device_id).await;
|
||||
|
||||
if let Some(session_info) = session_info {
|
||||
self.db
|
||||
.refreshtoken_refreshtokeninfo
|
||||
.remove(&session_info.current_refresh_token);
|
||||
if let Some(previous_refresh_token) = session_info.previous_refresh_token {
|
||||
self.db
|
||||
.refreshtoken_refreshtokeninfo
|
||||
.remove(&previous_refresh_token);
|
||||
}
|
||||
self.db
|
||||
.userdeviceid_oauthsessioninfo
|
||||
.del((user_id, device_id));
|
||||
|
||||
@@ -109,12 +109,19 @@ impl super::Service {
|
||||
{
|
||||
let event_fetch = |event_id| self.event_fetch(event_id);
|
||||
let event_exists = |event_id| self.event_exists(event_id);
|
||||
let is_rejected = |event_id: OwnedEventId| async move {
|
||||
self.services
|
||||
.pdu_metadata
|
||||
.is_event_rejected(&event_id)
|
||||
.await
|
||||
};
|
||||
state_res::resolve(
|
||||
room_version_rules,
|
||||
state_sets,
|
||||
auth_chain_sets,
|
||||
&event_fetch,
|
||||
&event_exists,
|
||||
&is_rejected,
|
||||
)
|
||||
.map_err(|e| err!(error!("State resolution failed: {e:?}")))
|
||||
.await
|
||||
|
||||
@@ -28,8 +28,8 @@ use ruma::{
|
||||
serde::Raw,
|
||||
signatures::{Ed25519KeyPair, PublicKeyMap, PublicKeySet},
|
||||
};
|
||||
use verify::IncomingServerKeys;
|
||||
use serde_json::value::to_raw_value;
|
||||
use verify::IncomingServerKeys;
|
||||
pub use verify::strip_extraneous_signatures;
|
||||
|
||||
use crate::{Dep, globals, sending, server_keys::util::required_keys};
|
||||
|
||||
@@ -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,6 +17,18 @@ use serde_json::json;
|
||||
|
||||
use crate::users::increment;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum PreviousTokenAction {
|
||||
/// Discard any previously saved access token for this device.
|
||||
Clear,
|
||||
/// Save the replaced access token as the previous token, overwriting any
|
||||
/// existing one.
|
||||
Replace,
|
||||
/// Keep an existing previous access token if one is already saved;
|
||||
/// otherwise save the replaced access token.
|
||||
Preserve,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[derive(Clone)]
|
||||
pub struct DeviceToken {
|
||||
@@ -71,7 +83,8 @@ impl super::Service {
|
||||
self.db.userdeviceid_metadata.put(key, Json(device));
|
||||
|
||||
if let Some(token) = token {
|
||||
self.set_token(user_id, &device_id, token).await?;
|
||||
self.set_token(user_id, &device_id, token, PreviousTokenAction::Clear)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(device_id)
|
||||
@@ -92,6 +105,7 @@ impl super::Service {
|
||||
self.db.token_userdeviceid.remove(&old_token);
|
||||
self.db.userdeviceid_tokenexpires.del(userdeviceid);
|
||||
}
|
||||
self.db.userdeviceid_previoustoken.del(userdeviceid);
|
||||
|
||||
// Remove todevice events
|
||||
let prefix = (user_id, device_id, Interfix);
|
||||
@@ -164,6 +178,7 @@ impl super::Service {
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
DeviceToken { token, max_age }: DeviceToken,
|
||||
previous_token_action: PreviousTokenAction,
|
||||
) -> Result<()> {
|
||||
let key = (user_id, device_id);
|
||||
if self.db.userdeviceid_metadata.qry(&key).await.is_err() {
|
||||
@@ -184,8 +199,23 @@ 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
|
||||
|
||||
match previous_token_action {
|
||||
| PreviousTokenAction::Clear => {
|
||||
self.db.userdeviceid_previoustoken.del(key);
|
||||
},
|
||||
| PreviousTokenAction::Replace => {
|
||||
self.db.userdeviceid_previoustoken.put_raw(key, &old_token);
|
||||
},
|
||||
| PreviousTokenAction::Preserve => {
|
||||
if !self.db.userdeviceid_previoustoken.contains(&key).await {
|
||||
self.db.userdeviceid_previoustoken.put_raw(key, &old_token);
|
||||
}
|
||||
},
|
||||
}
|
||||
} else if matches!(previous_token_action, PreviousTokenAction::Clear) {
|
||||
self.db.userdeviceid_previoustoken.del(key);
|
||||
}
|
||||
|
||||
// Assign token to user device combination
|
||||
@@ -207,6 +237,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,
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::{mem, sync::Arc};
|
||||
pub use account::{AccessTokenStatus, AccountStatus};
|
||||
use conduwuit::{Err, Error, Result, err, utils};
|
||||
use database::Map;
|
||||
pub use device::DeviceToken;
|
||||
pub use device::{DeviceToken, PreviousTokenAction};
|
||||
pub use profile::ProfileFieldChange;
|
||||
use ruma::{UserId, api::error::ErrorKind, encryption::CrossSigningKey, serde::Raw};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -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(),
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
--card-bg: oklch(from var(--panel-bg) var(--background-lightness) c h);
|
||||
|
||||
--rp-home-background-bg: radial-gradient(42.12% 56.13% at 100% 0%, oklch(from var(--c2) var(--background-lightness) c h) 0%, #fff0 100%), radial-gradient(42.01% 79.63% at 52.86% 0%, #d9ff5333 0%, #fff0 100%), radial-gradient(79.67% 58.09% at 0% 0%, oklch(from var(--c1) var(--background-lightness) c h) 0%, #fff0 100%), var(--rp-c-bg);
|
||||
--rp-banner-background: linear-gradient(279deg, var(--rp-c-brand-dark) 35.21%, var(--rp-c-brand-light) 63.34%);
|
||||
|
||||
--rp-c-divider: rgba(0, 0, 0, 0.2);
|
||||
--rp-c-divider-light: rgba(0, 0, 0, 0.1);
|
||||
|
||||
+22
-4
@@ -1,10 +1,28 @@
|
||||
import { HomeLayout as BasicHomeLayout, DocContent } from "@rspress/core/theme-original";
|
||||
|
||||
import { useFrontmatter } from '@rspress/core/runtime';
|
||||
import { Banner, HomeLayout as BasicHomeLayout, Layout as BasicLayout, DocContent } from "@rspress/core/theme-original";
|
||||
import { useFrontmatter, useSite } from '@rspress/core/runtime';
|
||||
interface HomeLayoutProps {
|
||||
components?: Record<string, React.FC>;
|
||||
}
|
||||
|
||||
const Layout = () => {
|
||||
const { site } = useSite();
|
||||
const sitePath: string = site.base;
|
||||
const prNumber: string = sitePath.substring(sitePath.indexOf("@") + 1, sitePath.lastIndexOf("/"));
|
||||
|
||||
return (
|
||||
<BasicLayout
|
||||
beforeNav={
|
||||
sitePath != "/" ? (
|
||||
<Banner
|
||||
href={`https://forgejo.ellis.link/continuwuation/continuwuity/pulls/${prNumber}`}
|
||||
message={`Documentation preview for PR #${prNumber}`}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
function HomeLayout(props: HomeLayoutProps) {
|
||||
console.log(props)
|
||||
|
||||
@@ -41,6 +59,6 @@ function HomeLayout(props: HomeLayoutProps) {
|
||||
/>
|
||||
);
|
||||
}
|
||||
export { HomeLayout };
|
||||
export { HomeLayout, Layout };
|
||||
export * from "@rspress/core/theme-original";
|
||||
import "./index.css";
|
||||
Reference in new issue
Block a user