element-hq / element-hq/synapse

event_match push rule condition doesn't work on booleans or integers

Open
#13,465 0 comments 0 reactions 0 assignees View on GitHub
A-Push O-Occasional S-Minor T-Enhancement Z-Spec-Blocked
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#13465](https://github.com/matrix-org/synapse/issues/13465).

---

### Description

The `event_match` condition is evaluated against a flattened variant of the event dictionary that drops all non-string values (see https://github.com/matrix-org/synapse/blob/develop/synapse/push/push_rule_evaluator.py#L345). As a result, it's not possible to match against any boolean or integer JSON values.

As an example, live location sharing uses events of type `beacon_info` with a `"live": true/false` value in `content` to signal whether location sharing was started or ended.

```
{
"content": {
"body": "Live location",
"live": true,
"org.matrix.msc3488.asset": {
"type": "m.self"
},
"org.matrix.msc3488.ts": 1659359067708,
"timeout": 900000
},
"origin_server_ts": 1659359069894,
"sender": "@...",
"state_key": "@...,
"type": "org.matrix.msc3672.beacon_info",
...
}
```

Since the value of `live` is boolean, it's not currently possible to define a push rule that only matches `"live": true` but not `"live": false`.

The [spec](https://spec.matrix.org/v1.3/client-server-api/#conditions-1) doesn't explicitly state that `event_match` should only work on strings. It just says the pattern is evaluated against "a field" on the event.

> This is a glob pattern match on a field of the event.

Therefore, I think `event_match` should work on the string-representation of boolean and integer values as well.

### Steps to reproduce

Define a push rule that matches on a boolean value, e.g.

```
{
"rule_id":"m.rule.live_location_start",
"default": true,
"enabled": true,
"conditions": [
{
"kind": "event_match",
"key": "type",
"pattern": "*beacon_info",
},
{
"kind": "event_match",
"key": "content.live",
"pattern": "true",
},
{
"kind": "event_match",
"key": "state_key",
"pattern": "*",
}
],
"actions": [
"notify"
]
}
```

Notice how it's not having any effect.

### Homeserver

n/a

### Synapse Version

Current develop

### Installation Method

_No response_

### Platform

n/a

### Relevant log output

n/a

### Anything else that would be useful to know?

n/a

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.