-
Notifications
You must be signed in to change notification settings - Fork 356
feat(common): Partially protect against malicious origin_server_ts
#5648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CodSpeed Performance ReportMerging #5648 will not alter performanceComparing Summary
|
43029f5 to
31a0943
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5648 +/- ##
========================================
Coverage 88.35% 88.36%
========================================
Files 354 354
Lines 97059 97218 +159
Branches 97059 97218 +159
========================================
+ Hits 85752 85902 +150
- Misses 7261 7269 +8
- Partials 4046 4047 +1 ☔ View full report in Codecov by Sentry. |
31a0943 to
dae438b
Compare
This patch adds the `timestamp` field to `TimelineEvent`. It's a copy of the `origin_server_ts` value, parsed as an `Option<MilliSecondsSinceUnixEpoch>`. It's `None` if the parsing failed, or if the `TimelineEvent` was deserialised from a version before this new field was added. A new `extract_timestamp` function is added for this purpose. It protects against malicious `origin_server_ts` where the value can be set to year 2100 for example. The only protection we are adding here is to take the `min(origin_server_ts, now())`, so that the event can never been “in the future”. It doesn't protect against a malicious value like 0. It's non-trivial to define a minimum timestamp for an event. When a `TimelineEvent` is mapped from one kind to another kind, the `timestamp` is carried over. To achieve that, new `to_decrypted` and `to_utd` methods are added. The rest of the code is updated accordingly.
dae438b to
e89f368
Compare
…:timestamp` method. This patch updates `LatestEventValue::timestamp` to use the new `TimelineEvent::timestamp` method in case of a `LatestEventValue::Remote`.
e89f368 to
a4348d4
Compare
stefanceriu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sensible to me 👍
…::timestamp`. After the merge of matrix-org#5648, we want all events to get a `TimelineEvent::timestamp` value (extracted from `origin_server_ts`). To accomplish that, we are emptying the event cache. New synced events will be built correctly, with a valid `TimelineEvent::timestamp`, allowing a clear, stable situation.
…::timestamp`. After the merge of matrix-org#5648, we want all events to get a `TimelineEvent::timestamp` value (extracted from `origin_server_ts`). To accomplish that, we are emptying the event cache. New synced events will be built correctly, with a valid `TimelineEvent::timestamp`, allowing a clear, stable situation.
…::timestamp`. After the merge of #5648, we want all events to get a `TimelineEvent::timestamp` value (extracted from `origin_server_ts`). To accomplish that, we are emptying the event cache. New synced events will be built correctly, with a valid `TimelineEvent::timestamp`, allowing a clear, stable situation.
The first patch adds the
timestampfield toTimelineEvent. It's a copy of theorigin_server_tsvalue, parsed as anOption<MilliSecondsSinceUnixEpoch>. It'sNoneif the parsing failed, or if theTimelineEventwas deserialised from a version before this new field was added.A new
extract_timestampfunction is added for this purpose. It protects against maliciousorigin_server_tswhere the value can be set to year 2100 for example. The only protection we are adding here is to take themin(origin_server_ts, now()), so that the event can never been “in the future”.It doesn't protect against a malicious value like 0. It's non-trivial to define a minimum timestamp for an event.
When a
TimelineEventis mapped from one kind to another kind, thetimestampis carried over. To achieve that, newto_decryptedandto_utdmethods are added.The second patch updates
LatestEventValue::timestampto use the newTimelineEvent::timestampmethod in case of aLatestEventValue::Remote. As such, it fixes the comment in #5617 (comment).latest_eventroom list sorter, and update therecencysorter #5617