Commit graph

2486 commits

Author SHA1 Message Date
Benjamin Lee
d2fab35868
implement more robust (not_)rooms filter for search
The previous code only handled the rooms field, and ignored not_rooms.
2024-06-05 00:07:07 -07:00
Benjamin Lee
fe5626e93a
implement per-event filtering for /context
'end_token' and 'start_token' have been refactored a bit because we need
to take the bounds of the examined events *before* filtering, otherwise
we'll send a pagination token to the client that is inside the set of
events we examined on this call. In extreme situations, this may leave a
client unable to make progress at all, because the first event that
matches if filter is more than 'load_limit' away from the base event.

This bug was present before the filtering implementation, but was less
significant because we only dropped events when they were not visible to
the user.
2024-06-05 00:07:07 -07:00
Benjamin Lee
fa86a8701d
implement filter.limit in /context
This seems to be completely redundant with the 'limit' body parameter,
with the only difference being:

> The filter may be applied before or/and after the limit parameter -
filter> whichever the homeserver prefers.

This sentence seems to apply to the 'limit' body parameter, but not to
the 'limit' field on the filter. This was probably unintentional on the
part of the spec authors, but I've switched to using same 'load_limit'
pattern we're using elsewhere anyway.
2024-06-05 00:07:07 -07:00
Benjamin Lee
1c0ead0339
implement (not_)rooms filter on /context 2024-06-05 00:07:07 -07:00
Benjamin Lee
832b41c930
implement filter limit for ephemeral events on /sync 2024-06-05 00:07:07 -07:00
Benjamin Lee
1114b66670
implement filter limit for timeline events on /sync 2024-06-05 00:07:07 -07:00
Benjamin Lee
738acd2b35
fixup: rename filter to compiled_filter in load_joined_room
Need to split this into a bunch of different fixup commits...
2024-06-05 00:07:07 -07:00
Benjamin Lee
1410b6f409
implement per-event filtering for per-room account_data on /sync 2024-06-05 00:07:06 -07:00
Benjamin Lee
7a0b8c986f
implement global account_data filtering in /sync
TODO docs on raw_event_allowed, and figure out how we want to organize
it with CompiledRoomEventFilter::raw_event_allowed
2024-06-05 00:07:06 -07:00
Benjamin Lee
c3cf97df7a
implement filter.room.include_leave for /sync 2024-06-05 00:07:06 -07:00
Benjamin Lee
d69b88566a
implement per-event filtering for ephemeral events in /sync
I've asked a few times for clarification on whether the `senders` field
in the filter applies to userids mentioned in the typing/receipt ephemeral
events, and never got a response. Synapse does not filter these userids by
sender, so we're gonna go with that.
2024-06-05 00:07:06 -07:00
Benjamin Lee
98d93da3a8
implement per-event state filtering for joined rooms in /sync 2024-06-05 00:07:06 -07:00
Benjamin Lee
f4f3be8c30
implement per-event state filtering for left rooms in /sync 2024-06-05 00:07:06 -07:00
Benjamin Lee
b85110a292
implement per-event state filtering for invited rooms on /sync
This one is a little weird, because the stripped invite state events are
not deserialized.
2024-06-05 00:07:06 -07:00
Benjamin Lee
4c9728cbad
implement per-event timeline filtering on /sync
This is the filter.room.timeline.{senders,types,contains_url} fields, and
their associated not_* pairs.

I decided not to change the `prev_batch` calculation for sliding-sync to
use the new `oldest_event_count` value, because I'm not confident in the
correct behavior. The current sliding-sync behavior is gives `prev_batch
= oldest_event_count` except when there are no new events. In this
case, `oldest_event_count` is `None`, but the current sliding-sync
implementation uses `prev_batch = since`. This is definitely wrong,
because both `since` and `prev_batch` are exclusive bounds. If the
correct thing to do is to return the lower exclusive bound of the range
of events that may have been included in the timeline, then we would
want `since - 1`. The other option would be to return `prev_batch =
None`, like we have in sync v3. I don't know which of these is correct,
so I'm just gonna keep the current (definitely incorrect) behavior to
avoid making things worse.
2024-06-05 00:07:06 -07:00
Benjamin Lee
745eaa9b48
implement room.account_data.(not_)rooms filter on /sync 2024-06-04 20:02:43 -07:00
Benjamin Lee
84f356e67b
implement room.ephemeral.(not_)rooms filter on /sync 2024-06-04 20:02:43 -07:00
Benjamin Lee
4e1d091bbc
skip left/invited rooms with no updates in /sync
Before this change we were just returning an empty object for left or
invited rooms that don't have any updates. This is valid coloredding to
the spec, but it's a nicer to debug if they are omitted it and results in
a little less network traffic. For joined rooms, we are already skipping
empty updates.

With filtering support, it's much more common to have sync responses where
many rooms are empty, because all of the state/timeline events may be
filtered out.
2024-06-04 20:02:43 -07:00
Benjamin Lee
e6f2b6c9ad
implement room.state.(not_)rooms filter on /sync 2024-06-04 20:02:43 -07:00
Benjamin Lee
c48abf9f13
implement room.timeline.(not_)rooms filter on /sync
I asked in #matrix-spec:matrix.org and go clarification that we should be
omitting the timeline field completely for rooms that are filtered out
by the timeline.(not_)rooms filter. Ruma's skip_serializing_if attribute
on the timeline field will currently cause it to be omitted when events is
empty. If [this fix][1] is merged, it will be omitted only when events is
empty, prev_batch is None, and limited is false.

[1]: https://github.com/ruma/ruma/pull/1796

TODO: maybe do something about clippy::too_many_arguments
2024-06-04 20:02:43 -07:00
Benjamin Lee
458d6842fb
implement top-level (not_)rooms filter on /sync
These are the fields at filter.room.{rooms,not_rooms}, that apply to all
categories. The category-specific room filters are in
filter.room.{state,timeline,ephemeral}.{rooms,not_rooms}.
2024-06-04 20:02:42 -07:00
Benjamin Lee
5d4aa35463
implement types and not_types filters on /message
One thing I'm a little worried about with this implementation is that
it's possible for some wildcard expressions to result in a
regex::Error::CompiledTooBig error. It seems like rejecting patterns that
would result in a ReDOS is a good idea, but the matrix spec doesn't say
anything about it.
2024-06-04 20:02:42 -07:00
Benjamin Lee
75523fa3e0
implement senders and not_senders filters on /messages 2024-06-04 20:02:42 -07:00
Benjamin Lee
0e2694a6c4
implement contains_url filter for /message
The plan is to move all of the per-event checks into the
pdu_event_allowed function.

TODO: split the `visibility_filter` function into it's own commit. I
think this one was inherited from an earlier conduwuit commit.
2024-06-04 20:02:42 -07:00
Benjamin Lee
2bcd357db2
limit total events examined in /messages 2024-06-04 20:02:42 -07:00
Benjamin Lee
93ad93a36b
respect filter.limit in the /messages endpoint
As far as I can tell, 'filter.limit' and the 'limit' query parameter are
completely redundant. I've moved the 'take(limit)' call until after
filtering, to ensure that we can return up to 'limit' events even when
some are rejected by the filter. In a future commit, I will add a global
limit on loaded events to avoid DoS.
2024-06-04 20:02:42 -07:00
Benjamin Lee
404d5fae6c
implement rooms and not_rooms filters on /message
I really doubt anybody is sending /message requests with a filter that
rejects the entire request, but it's the first step in the filter
implementation.
2024-06-04 20:02:42 -07:00
Charles Hall
a5e7ce6c33
improve "Leave event has no state" event
Now it includes the user, room, and event ID. As a bonus, the sync
function is now slightly less gigantic.

TODO: put this in a separate MR, and include a similar change for
invited rooms
2024-06-04 20:02:42 -07:00
Charles Hall
71f3d84115
rename password-related utils functions 2024-06-04 19:35:25 -07:00
Charles Hall
aa4cd8b1e1
switch to RustCrypto's argon2 crate 2024-06-04 19:35:21 -07:00
Lambda
60d32ddf48
Fix tracing in fetch_signing_keys() 2024-06-04 13:32:32 -07:00
Lambda
7dbae9ac2b
Fix tracing in send_request() 2024-06-04 13:32:32 -07:00
Lambda
c6f75a1b93
Add tracing span for Ar::from_request()
The fact that this is called for every request is somewhat obscured, it
should be obvious in tracing at least.
2024-06-04 13:32:32 -07:00
Lambda
dd6cda4519
Useful span names for incoming HTTP requests
Usually it's not possible to make span names dynamic, but the magic
otel.name attribute changes the span name in the OpenTelemetry tracing
backend.
2024-06-04 13:32:32 -07:00
Lambda
0b9e43cbdd
Record authentication info in incoming requests 2024-06-04 13:32:32 -07:00
Lambda
f7a0e3012b
server_server: log ignored signing key updates 2024-06-04 13:32:32 -07:00
Lambda
88bb2ea600
Remove redundant span attributes
There's no need to record attributes that are already present in all
callers.
2024-06-04 13:32:31 -07:00
Lambda
f35cbfd89e
More tracing spans 2024-06-04 13:32:31 -07:00
Lambda
2e34241465
tracing: add span for globals.watch()
This spawns a ton of futures which are otherwise all flat in the parent.
2024-06-04 13:32:31 -07:00
Lambda
3365608101
tracing: record HTTP request method 2024-06-04 13:32:31 -07:00
Lambda
148df18989
Stop debug-logging every incoming request 2024-06-04 13:32:31 -07:00
Benjamin Lee
3551a6ef7a
fix dropped events in search
The previous code would drop some events entirely if any events between
`skip` and `skip + limit` were not visible to the user. This would cause
the set of events skipped by the `skip(skip)` method to extend past
`skip` in the raw result set, because `skip(skip)` was being called
*after* filtering out invisible events.

This bug will become much more severe with a full filtering
implementation, because it will be more likely for events to be filtered
out. Currently, it is only possible to trigger with rooms that have
history visibility set to "invited" or "joined".
2024-06-04 01:12:53 -07:00
Benjamin Lee
0cdf03288a
fix missing next_batch for search
The previous code would fail to return next_batch if any of the events
in the window were not visible to the user. It would also return an
unnecessary next_batch when no more results are available if the total
number of results is exactly `skip + limit`.

This bug will become much more severe with a full filtering
implementation, because we will be more likely to trigger it by
filtering out events in a search call. Currently, it is only possible to
trigger with rooms that have history visibility set to "invited" or
"joined".
2024-06-04 01:12:53 -07:00
Charles Hall
c1ec1111ae
improve route-not-found tracing event 2024-06-03 18:18:44 -07:00
Charles Hall
04ecf4972e
record histogram of http requests 2024-06-03 18:18:44 -07:00
Charles Hall
a0b92c82e8
set up opentelemetry for metrics
Also adds an `allow_prometheus` option (disabled by default) to expose
a `/metrics` endpoint that returns Prometheus data.
2024-06-03 18:18:44 -07:00
Charles Hall
94fda7c875
improve usage of Resource
* Extract into reusable function (we'll need this later)
* Merge the values we want to override over the defaults, instead of
  dropping the defaults completely
* Don't unnecessarily allocate (the `vec![]` usage is gone)
2024-06-03 18:18:44 -07:00
Benjamin Lee
c64a474954
workaround to fix search in element
We inherited a similar workaround from conduit, but removed it in
71c48f66c4. At the time, it was not clear
that this had broken search.

Fixes: !26
2024-06-03 18:02:41 -07:00
Lambda
5c39c7c5ff Use destination field in X-Matrix Authorization header
Both validating and sending it is a MUST since Matrix v1.3.
2024-06-03 20:50:49 +00:00
Lambda
62dd097f49 Use Ruma XMatrix type instead of rolling our own
Both the hand-rolled parser and serialization were wrong in countless
ways. The current Ruma parser is much better, and the Ruma serialization
will be fixed by https://github.com/ruma/ruma/pull/1830.
2024-06-03 20:50:49 +00:00