Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e746f80

Browse files
authored
Do not accept pattern_type from user input in push rules. (#15088)
Internally the push rules module uses a `pattern_type` property for `event_match` conditions (and `related_event_match`) to mark the condition as matching the current user's Matrix ID or localpart. This is leaky to the Client-Server API where a user can successfully set a condition which provides `pattern_type` instead of `pattern` (note that there's no benefit to doing this -- the user can just use their own Matrix ID or localpart instead). When serializing back to the client the `pattern_type` property is converted into a proper `pattern`. The following changes are made to avoid this: * Separate the `KnownCondition::EventMatch` enum value into `EventMatch` and `EventMatchType`, each with their own expected properties. (Note that a similar change is made for `RelatedEventMatch`.) * Make it such that the `pattern_type` variants serialize to the same condition kind, but cannot be deserialized (since they're only provided by base rules). * As a final tweak, convert `user_id` vs. `user_localpart` values into an enum.
1 parent 5210268 commit e746f80

File tree

6 files changed

+244
-186
lines changed

6 files changed

+244
-186
lines changed

changelog.d/15088.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug where Synapse handled an unspecced field on push rules.

rust/benches/evaluator.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ fn bench_match_exact(b: &mut Bencher) {
6060
let condition = Condition::Known(synapse::push::KnownCondition::EventMatch(
6161
EventMatchCondition {
6262
key: "room_id".into(),
63-
pattern: Some("!room:server".into()),
64-
pattern_type: None,
63+
pattern: "!room:server".into(),
6564
},
6665
));
6766

@@ -109,8 +108,7 @@ fn bench_match_word(b: &mut Bencher) {
109108
let condition = Condition::Known(synapse::push::KnownCondition::EventMatch(
110109
EventMatchCondition {
111110
key: "content.body".into(),
112-
pattern: Some("test".into()),
113-
pattern_type: None,
111+
pattern: "test".into(),
114112
},
115113
));
116114

@@ -158,8 +156,7 @@ fn bench_match_word_miss(b: &mut Bencher) {
158156
let condition = Condition::Known(synapse::push::KnownCondition::EventMatch(
159157
EventMatchCondition {
160158
key: "content.body".into(),
161-
pattern: Some("foobar".into()),
162-
pattern_type: None,
159+
pattern: "foobar".into(),
163160
},
164161
));
165162

0 commit comments

Comments
 (0)