Repository: matrix-org/synapse

Issue:
"'NoneType' object has no attribute 'find'" prevents backfill
### Description

This happened while joining `#mozilla_#rust-wasm:matrix.org`

### Version information

- **Homeserver**: v1.20.1

- **Install method**: Docker

- **Platform**: Debian 10

### Tracebacks

```
synapse_1  | 2020-09-24 18:15:54,480 - synapse.handlers.federation - 1146 - ERROR - GET-3753 - Failed to backfill from t2bot.io because FirstError[#0, [Failure instance: Traceback: <class 'AttributeError'>: 'NoneType' object has no attribute 'find'
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:460:callback
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:568:_startRunCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:654:_runCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1475:gotResult
synapse_1  | --- <exception caught here> ---
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1418:_inlineCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py:1984:prep
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py:2134:_prep_event
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py:2322:do_auth
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/event_auth.py:190:check
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/event_auth.py:449:check_redaction
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/types.py:152:get_domain_from_id
synapse_1  | ]]
synapse_1  | Traceback (most recent call last):
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1115, in try_backfill
synapse_1  |     dom, room_id, limit=100, extremities=extremities
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 926, in backfill
synapse_1  |     await self._handle_new_events(dest, ev_infos, backfilled=True)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1991, in _handle_new_events
synapse_1  |     consumeErrors=True,
synapse_1  | twisted.internet.defer.FirstError: FirstError[#0, [Failure instance: Traceback: <class 'AttributeError'>: 'NoneType' object has no attribute 'find'
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:460:callback
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:568:_startRunCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:654:_runCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1475:gotResult
synapse_1  | --- <exception caught here> ---
synapse_1  | /usr/local/lib/python3.7/site-packages/twisted/internet/defer.py:1418:_inlineCallbacks
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py:1984:prep
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py:2134:_prep_event
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py:2322:do_auth
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/event_auth.py:190:check
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/event_auth.py:449:check_redaction
synapse_1  | /usr/local/lib/python3.7/site-packages/synapse/types.py:152:get_domain_from_id
synapse_1  | ]]
```

```
synapse_1  | 2020-09-24 18:18:02,246 - synapse.handlers.federation - 2447 - INFO - GET-5780 - auth_events refers to events which are not in our calculated auth chain: {'$1581352745107458UyAnB:matrix.org', '$1497378526321306TaXjR:matrix.org', '$1497378526321301jdEhI:matrix.org', '$1497378526321303RmPNp:matrix.org'}
synapse_1  | 2020-09-24 18:18:02,247 - synapse.state - 444 - INFO - GET-5780 - Resolving state for !GdiIIqaoZoTDvNtURf:matrix.org with 2 groups
synapse_1  | 2020-09-24 18:18:02,248 - synapse.state.v1 - 84 - INFO - GET-5780 - Asking for 0/0 conflicted events
synapse_1  | 2020-09-24 18:18:02,249 - synapse.state.v1 - 114 - INFO - GET-5780 - Asking for 0/0 auth events
synapse_1  | 2020-09-24 18:18:02,250 - synapse.handlers.federation - 2487 - INFO - GET-5780 - After state res: updating auth_events with new state {('m.room.member', '@mozilla_sebk:matrix.org'): '$1581352745107458UyAnB:matrix.org', ('m.room.join_rules', ''): '$1497378526321306TaXjR:matrix.org', ('m.room.create', ''): '$1497378526321301jdEhI:matrix.org', ('m.room.power_levels', ''): '$1497378526321303RmPNp:matrix.org'}
synapse_1  | 2020-09-24 18:18:02,992 - synapse.handlers.federation - 1146 - ERROR - GET-5780 - Failed to backfill from matrix.org because 'NoneType' object has no attribute 'find'
synapse_1  | Traceback (most recent call last):
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1115, in try_backfill
synapse_1  |     dom, room_id, limit=100, extremities=extremities
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 942, in backfill
synapse_1  |     await self._handle_new_event(dest, event, backfilled=True)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1938, in _handle_new_event
synapse_1  |     origin, event, state=state, auth_events=auth_events, backfilled=backfilled
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2134, in _prep_event
synapse_1  |     context = await self.do_auth(origin, event, context, auth_events=auth_events)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2322, in do_auth
synapse_1  |     event_auth.check(room_version_obj, event, auth_events=auth_events)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/event_auth.py", line 190, in check
synapse_1  |     check_redaction(room_version_obj, event, auth_events)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/event_auth.py", line 449, in check_redaction
synapse_1  |     redactee_domain = get_domain_from_id(event.redacts)
synapse_1  |   File "/usr/local/lib/python3.7/site-packages/synapse/types.py", line 152, in get_domain_from_id
synapse_1  |     idx = string.find(":")
synapse_1  | AttributeError: 'NoneType' object has no attribute 'find'
```



Discussion:
Sounds like a similar fix to https://github.com/matrix-org/synapse/pull/6771 needs to happen here as well.

Note this particular code path only affects v1 rooms.

Resolving patch:
diff --git a/synapse/event_auth.py b/synapse/event_auth.py
--- a/synapse/event_auth.py
+++ b/synapse/event_auth.py
@@ -446,6 +446,8 @@ def check_redaction(
 
     if room_version_obj.event_format == EventFormatVersions.V1:
         redacter_domain = get_domain_from_id(event.event_id)
+        if not isinstance(event.redacts, str):
+            return False
         redactee_domain = get_domain_from_id(event.redacts)
         if redacter_domain == redactee_domain:
             return True


Test patch: