This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Do not accept pattern_type from user input in push rules #15088
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
da01885
Add a (failing) test.
clokep 4ce3786
Separate the pattern vs. pattern_type for event_match.
clokep e8b9709
Share some duplicated code.
clokep 12cf8be
Separate pattern vs. pattern_type for related_event_match.
clokep 828c1e5
Use an enum instead of magic values.
clokep 546acb9
Newsfragment
clokep c150670
Remove unneeded clones.
clokep e9e1a87
Reformat return type of match_related_event_match.
clokep e47d971
Merge remote-tracking branch 'origin/develop' into clokep/push-rule-p…
clokep 6f23bbb
Remove print statement.
clokep d9d927a
Add more tests.
clokep b03ee1f
Merge remote-tracking branch 'origin/develop' into clokep/push-rule-p…
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a long-standing bug where Synapse handled an unspecced field on push rules. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,10 +328,16 @@ pub enum Condition { | |
#[serde(tag = "kind")] | ||
pub enum KnownCondition { | ||
EventMatch(EventMatchCondition), | ||
// Identical to event_match but gives predefined patterns. Cannot be added by users. | ||
#[serde(skip_deserializing, rename = "event_match")] | ||
EventMatchType(EventMatchTypeCondition), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test that this serializes correctly, for paranoia. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! I added deserialization ones too. |
||
#[serde(rename = "com.beeper.msc3758.exact_event_match")] | ||
ExactEventMatch(ExactEventMatchCondition), | ||
#[serde(rename = "im.nheko.msc3664.related_event_match")] | ||
RelatedEventMatch(RelatedEventMatchCondition), | ||
// Identical to related_event_match but gives predefined patterns. Cannot be added by users. | ||
#[serde(skip_deserializing, rename = "im.nheko.msc3664.related_event_match")] | ||
RelatedEventMatchType(RelatedEventMatchTypeCondition), | ||
#[serde(rename = "org.matrix.msc3966.exact_event_property_contains")] | ||
ExactEventPropertyContains(ExactEventMatchCondition), | ||
#[serde(rename = "org.matrix.msc3952.is_user_mention")] | ||
|
@@ -362,14 +368,27 @@ impl<'source> FromPyObject<'source> for Condition { | |
} | ||
} | ||
|
||
/// The body of a [`Condition::EventMatch`] | ||
/// The body of a [`Condition::EventMatch`] with a pattern. | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct EventMatchCondition { | ||
pub key: Cow<'static, str>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub pattern: Option<Cow<'static, str>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub pattern_type: Option<Cow<'static, str>>, | ||
pub pattern: Cow<'static, str>, | ||
} | ||
|
||
#[derive(Serialize, Debug, Clone)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum EventMatchPatternType { | ||
UserId, | ||
UserLocalpart, | ||
} | ||
|
||
/// The body of a [`Condition::EventMatch`] that uses user_id or user_localpart as a pattern. | ||
#[derive(Serialize, Debug, Clone)] | ||
pub struct EventMatchTypeCondition { | ||
pub key: Cow<'static, str>, | ||
// During serialization, the pattern_type property gets replaced with a | ||
// pattern property of the correct value in synapse.push.clientformat.format_push_rules_for_user. | ||
pub pattern_type: Cow<'static, EventMatchPatternType>, | ||
} | ||
|
||
/// The body of a [`Condition::ExactEventMatch`] | ||
|
@@ -386,8 +405,18 @@ pub struct RelatedEventMatchCondition { | |
pub key: Option<Cow<'static, str>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub pattern: Option<Cow<'static, str>>, | ||
pub rel_type: Cow<'static, str>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub pattern_type: Option<Cow<'static, str>>, | ||
pub include_fallbacks: Option<bool>, | ||
} | ||
|
||
/// The body of a [`Condition::RelatedEventMatch`] that uses user_id or user_localpart as a pattern. | ||
#[derive(Serialize, Debug, Clone)] | ||
pub struct RelatedEventMatchTypeCondition { | ||
// This is only used if pattern_type exists (and thus key must exist), so is | ||
// a bit simpler than RelatedEventMatchCondition. | ||
pub key: Cow<'static, str>, | ||
pub pattern_type: Cow<'static, EventMatchPatternType>, | ||
pub rel_type: Cow<'static, str>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub include_fallbacks: Option<bool>, | ||
|
@@ -571,8 +600,7 @@ impl FilteredPushRules { | |
fn test_serialize_condition() { | ||
let condition = Condition::Known(KnownCondition::EventMatch(EventMatchCondition { | ||
key: "content.body".into(), | ||
pattern: Some("coffee".into()), | ||
pattern_type: None, | ||
pattern: "coffee".into(), | ||
})); | ||
|
||
let json = serde_json::to_string(&condition).unwrap(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.