synapse icon indicating copy to clipboard operation
synapse copied to clipboard

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

Open Johennes opened this issue 3 years ago • 0 comments

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 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

Johennes avatar Aug 05 '22 07:08 Johennes