mautrix / facebook

A Matrix-Facebook Messenger puppeting bridge
https://matrix.to/#/#facebook:maunium.net
GNU Affero General Public License v3.0
389 stars 64 forks source link

"MForbidden: user does not belong to room" on messages, reactions, read receipts sent by Facebook user with custom nickname #234

Open rom4nik opened 2 years ago

rom4nik commented 2 years ago

I've observed that messages (of any type, apparently) from a Facebook user who has a custom nickname set aren't bridged to Matrix, claiming that the Matrix ghost user doesn't belong to room. However, those users are correctly shown in people list in Element.

Bridge version: 0.4.0 Homeserver: Dendrite 0.8.1

Logs from bridge on message:

[2022-04-14 11:32:42,520] [DEBUG@paho.mqtt.client] Received PUBLISH (d0, q1, r1, m12257), '59', ...  (186 bytes)                                                                  
[2022-04-14 11:32:42,520] [DEBUG@paho.mqtt.client] Sending PUBACK (Mid: 12257)                                                                                                                                                           
[2022-04-14 11:32:42,523] [DEBUG@mau.portal.2380936501983011] Handling Facebook event mid.$gAAh1cvpu9yOGWR4Y3mAJ9jH-DVBx (/6920332997007593585)                                                                                          
[2022-04-14 11:32:43,101] [ERROR@mau.portal.2380936501983011] Error handling Facebook message mid.$gAAh1cvpu9yOGWR4Y3mAJ9jH-DVBx                                                                                                         
Traceback (most recent call last):                                                                                                                                                                                                       
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/portal.py", line 1121, in handle_facebook_message                                                                                                                              
    await self._handle_facebook_message(source, sender, message, reply_to)                                                                                                                                                               
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/portal.py", line 1224, in _handle_facebook_message                                                                                                                             
    event_ids += await self._handle_mqtt_message(source, intent, message, reply_to)                                                                                                                                                      
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/portal.py", line 1297, in _handle_mqtt_message                                                                                                                                 
    await self._handle_facebook_text(                                                                                                                                                                                                    
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/portal.py", line 1585, in _handle_facebook_text                                                                                                                                
    return await self._send_message(intent, content, timestamp=timestamp)                                                                                                                                                                
  File "/usr/lib/python3.9/site-packages/mautrix/bridge/portal.py", line 424, in _send_message                                                                                                                                           
    return await intent.send_message_event(self.mxid, event_type, content, **kwargs)                                                                                                                                                     
  File "/usr/lib/python3.9/site-packages/mautrix/appservice/api/intent.py", line 135, in wrapper                                                                                                                                         
    return await __method(*args, **kwargs)                                                                                                                                                                                               
  File "/usr/lib/python3.9/site-packages/mautrix/appservice/api/intent.py", line 365, in send_message_event                                                                                                                              
    return await super().send_message_event(room_id, event_type, content, **kwargs)                                                                                                                                                      
  File "/usr/lib/python3.9/site-packages/mautrix/client/api/events.py", line 401, in send_message_event                                                                                                                                  
    resp = await self.api.request(                                                                                                                                                                                                       
  File "/usr/lib/python3.9/site-packages/mautrix/api.py", line 383, in request                                                                                                                                                           
    return await self._send(method, full_url, req_content, query_params, headers or {})                                                                                                                                                  
  File "/usr/lib/python3.9/site-packages/mautrix/api.py", line 258, in _send                                                                                                                                                             
    raise make_request_error(                                                                                                                                                                                                            
mautrix.errors.request.MForbidden: eventauth: sender "@facebook_100005788022580:matrix-bridges.rom4nik.pl" not in room

Read receipt:

[2022-04-14 11:33:35,083] [DEBUG@paho.mqtt.client] Received PUBLISH (d0, q0, r1, m0), '59', ...  (63 bytes)
[2022-04-14 11:33:35,092] [ERROR@mau.user.@przemek:matrix-bridges.rom4nik.pl.mqtt] Error in ReadReceipt handler
Traceback (most recent call last):
  File "/opt/mautrix-facebook/maufbapi/mqtt/conn.py", line 472, in _dispatch
    await handler(evt)
  File "/usr/lib/python3.9/site-packages/mautrix/util/opt_prometheus.py", line 59, in wrapper
    return await fn(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/user.py", line 891, in on_message_seen
    await portal.handle_facebook_seen(self, puppet, evt.read_to)
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/portal.py", line 1766, in handle_facebook_seen
    await sender.intent_for(self).mark_read(msg.mx_room, msg.mxid)
  File "/usr/lib/python3.9/site-packages/mautrix/appservice/api/intent.py", line 424, in mark_read 
    await self.set_fully_read_marker(
  File "/usr/lib/python3.9/site-packages/mautrix/appservice/api/intent.py", line 123, in wrapper
    return await __method(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/mautrix/client/api/modules/misc.py", line 113, in set_fully_read_marker
    await self.api.request(Method.POST, Path.v3.rooms[room_id].read_markers, content)
  File "/usr/lib/python3.9/site-packages/mautrix/api.py", line 383, in request
    return await self._send(method, full_url, req_content, query_params, headers or {})
  File "/usr/lib/python3.9/site-packages/mautrix/api.py", line 258, in _send
    raise make_request_error(
mautrix.errors.request.MForbidden: user does not belong to room

Reaction:

[2022-04-14 11:33:55,312] [DEBUG@paho.mqtt.client] Received PUBLISH (d0, q0, r1, m0), '59', ...  (126 bytes)
[2022-04-14 11:33:55,332] [ERROR@mau.user.@przemek:matrix-bridges.rom4nik.pl.mqtt] Error in Reaction handler
Traceback (most recent call last):
  File "/opt/mautrix-facebook/maufbapi/mqtt/conn.py", line 472, in _dispatch
    await handler(evt)
  File "/usr/lib/python3.9/site-packages/mautrix/util/opt_prometheus.py", line 59, in wrapper
    return await fn(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/user.py", line 920, in on_reaction
    await portal.handle_facebook_reaction_add(self, puppet, evt.message_id, evt.reaction)
  File "/usr/lib/python3.9/site-packages/mautrix_facebook/portal.py", line 1885, in handle_facebook_reaction_add
    mxid = await intent.react(
  File "/usr/lib/python3.9/site-packages/mautrix/appservice/api/intent.py", line 135, in wrapper
    return await __method(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/mautrix/appservice/api/intent.py", line 365, in send_message_event
    return await super().send_message_event(room_id, event_type, content, **kwargs)
  File "/usr/lib/python3.9/site-packages/mautrix/client/api/events.py", line 401, in send_message_event
    resp = await self.api.request(
  File "/usr/lib/python3.9/site-packages/mautrix/api.py", line 383, in request
    return await self._send(method, full_url, req_content, query_params, headers or {})
  File "/usr/lib/python3.9/site-packages/mautrix/api.py", line 258, in _send
    raise make_request_error(
mautrix.errors.request.MForbidden: eventauth: sender "@facebook_100005788022580:matrix-bridges.rom4nik.pl" not in room

There were no errors in homeserver logs.

rom4nik commented 2 years ago

A couple of observations: