Repository: matrix-org/synapse

Issue:
Failing to join / send_join rooms: FrozenEventV3 has no 'origin' property
I tried to `/join #TWIM:matrix.org` in Element/Web on librepush.net (Synapse 1.20.0rc3) and was told 'Failed to send_join via any server'.

Here are the logs (updated).

```
2020-09-15 17:51:47,587 - synapse.http.matrixfederationclient - 196 - INFO - POST-557 - {GET-O-1723} [matrix.org] Completed request: 200 OK in 0.06 secs - GET matrix://matrix.org/_matrix/federation/v1/query/directory?room_alias=%23TWIM%3Amatrix.org
2020-09-15 17:51:47,685 - synapse.http.matrixfederationclient - 196 - INFO - POST-557 - {GET-O-1724} [matrix.org] Completed request: 200 OK in 0.08 secs - GET matrix://matrix.org/_matrix/federation/v1/make_join/%21xYvNcQPhnkrdUmYczI%3Amatrix.org/%40reivilibre%3Alibrepush.net?ver=1&ver=2&ver=3&ver=4&ver=5&ver=6
2020-09-15 17:51:48,521 - synapse.http.matrixfederationclient - 196 - INFO - POST-557 - {PUT-O-1725} [matrix.org] Completed request: 200 OK in 0.83 secs - PUT matrix://matrix.org/_matrix/federation/v2/send_join/%21xYvNcQPhnkrdUmYczI%3Amatrix.org/%24iasc50lvuNw0_TsCn2zWwnqW6LKwquJYuwKhVJyhsNY
2020-09-15 17:51:49,129 - synapse.federation.federation_base - 121 - WARNING - POST-557 - Signature check failed for $62cZDuP7cawWQVbqhEDp_9P2g08xvEKyWTUobNazqNw: 403: event id $62cZDuP7cawWQVbqhEDp_9P2g08xvEKyWTUobNazqNw: unable to verify signature for sender conduit.rs: 401: Invalid signature for server conduit.rs with key ed25519:key1: Unable to verify signature for conduit.rs: <class 'nacl.exceptions.BadSignatureError'> Signature was forged or corrupt
2020-09-15 17:51:49,145 - synapse.federation.federation_base - 96 - INFO - POST-557 - Event $hVYde2o6n8YYGRAQyvCmmxEJkWoegt_urDoL-06bTIE seems to have been redacted; using our redacted copy
2020-09-15 17:51:49,147 - synapse.federation.federation_base - 96 - INFO - POST-557 - Event $yP27CCaJF-4WIQN1n8RgS1mOZ6z6w56XHovQWm0Mpj4 seems to have been redacted; using our redacted copy
2020-09-15 17:51:49,375 - synapse.federation.federation_base - 96 - INFO - POST-557 - Event $JTORXmqhGwDBhW5xjvPwaLpVg2iRQ5D5-WVS0nf3pC8 seems to have been redacted; using our redacted copy
2020-09-15 17:51:49,710 - synapse.federation.federation_base - 96 - INFO - POST-557 - Event $PMN2t0o-y0V5AuloNWAMRBV-5rfLVvaZZfB_uXPgLVU seems to have been redacted; using our redacted copy
2020-09-15 17:51:49,824 - synapse.federation.federation_client - 492 - WARNING - POST-557 - Failed to send_join via matrix.org
Traceback (most recent call last):
  File "/home/synapse/venv/lib/python3.8/site-packages/synapse/federation/federation_client.py", line 474, in _try_destination_list
    res = await callback(destination)
  File "/home/synapse/venv/lib/python3.8/site-packages/synapse/federation/federation_client.py", line 654, in send_request
    valid_pdus = await self._check_sigs_and_hash_and_fetch(
  File "/home/synapse/venv/lib/python3.8/site-packages/synapse/federation/federation_client.py", line 411, in _check_sigs_and_hash_and_fetch
    valid_pdus = await make_deferred_yieldable(
  File "/home/synapse/venv/lib/python3.8/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
  File "/home/synapse/venv/lib/python3.8/site-packages/synapse/federation/federation_client.py", line 389, in handle_check_result
    if not res and pdu.origin != origin:
  File "/home/synapse/venv/lib/python3.8/site-packages/synapse/events/__init__.py", line 64, in __get__
    raise AttributeError(
AttributeError: '<class 'synapse.events.FrozenEventV3'>' has no 'origin' property
2020-09-15 17:51:49,827 - synapse.http.server - 76 - INFO - POST-557 - <XForwardedForRequest at 0x7f5a87447c10 method='POST' uri='/_matrix/client/r0/join/%23TWIM%3Amatrix.org' clientproto='HTTP/1.0' site=8008> SynapseError: 502 - Failed to send_join via any server
2020-09-15 17:51:49,828 - synapse.access.http.8008 - 290 - INFO - POST-557 - 84.92.98.201 - 8008 - {@reivilibre:librepush.net} Processed request: 2.297sec/-0.000sec (0.973sec, 0.010sec) (0.008sec/0.188sec/5) 68B 502 "POST /_matrix/client/r0/join/%23TWIM%3Amatrix.org HTTP/1.0" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36" [1 dbevts]

```
<!--

**THIS IS NOT A SUPPORT CHANNEL!**
**IF YOU HAVE SUPPORT QUESTIONS ABOUT RUNNING OR CONFIGURING YOUR OWN HOME SERVER**,
please ask in **#synapse:matrix.org** (using a matrix.org account if necessary)

If you want to report a security issue, please see https://matrix.org/security-disclosure-policy/

This is a bug report template. By following the instructions below and
filling out the sections with your information, you will help the us to get all
the necessary data to fix your issue.

You can also preview your report before submitting it. You may remove sections
that aren't relevant to your particular case.

Text between <!-- and --​> marks will be invisible in the report.

-->

### Description

<!-- Describe here the problem that you are experiencing -->

### Steps to reproduce

- try to join an alias like `#TWIM:matrix.org` using Element/Web
- receive error instead

<!--
Describe how what happens differs from what you expected.

If you can identify any relevant log snippets from _homeserver.log_, please include
those (please be careful to remove any personal or private data). Please surround them with
``` (three backticks, on a line on their own), so that they are formatted legibly.
-->

### Version information

<!-- IMPORTANT: please answer the following questions, to help us narrow down the problem -->

<!-- Was this issue identified on matrix.org or another homeserver? -->
- **Homeserver**: librepush.net

<!--
 What version of Synapse is running?

You can find the Synapse version with this command:

$ curl http://localhost:8008/_synapse/admin/v1/server_version

(You may need to replace `localhost:8008` if Synapse is not configured to
listen on that port.)
-->
- **Version**: 1.20.0rc3

- **Install method**: pip
<!-- examples: package manager/git clone/pip  -->

- **Platform**: Ubuntu 20.04 on amd64 VPS
<!--
Tell us about the environment in which your homeserver is operating
distro, hardware, if it's running in a vm/container, etc.
-->



Discussion:
Conduit seems to send events without the required `origin` field. Apparently Synapse incorrectly accepts the event normally, but joining the room via another server breaks it (reivilibre was the first librepush.net user to try to join #twim)
Relevant: https://github.com/matrix-org/synapse/issues/3816

Resolving patch:
diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py
--- a/synapse/federation/federation_client.py
+++ b/synapse/federation/federation_client.py
@@ -54,7 +54,7 @@
 from synapse.federation.federation_base import FederationBase, event_from_pdu_json
 from synapse.logging.context import make_deferred_yieldable, preserve_fn
 from synapse.logging.utils import log_function
-from synapse.types import JsonDict
+from synapse.types import JsonDict, get_domain_from_id
 from synapse.util import unwrapFirstError
 from synapse.util.caches.expiringcache import ExpiringCache
 from synapse.util.retryutils import NotRetryingDestination
@@ -386,10 +386,11 @@ async def handle_check_result(pdu: EventBase, deferred: Deferred):
                     pdu.event_id, allow_rejected=True, allow_none=True
                 )
 
-            if not res and pdu.origin != origin:
+            pdu_origin = get_domain_from_id(pdu.sender)
+            if not res and pdu_origin != origin:
                 try:
                     res = await self.get_pdu(
-                        destinations=[pdu.origin],
+                        destinations=[pdu_origin],
                         event_id=pdu.event_id,
                         room_version=room_version,
                         outlier=outlier,


Test patch: