Skip to content

Commit 2918800

Browse files
anoadragon453sandhoseMadLittleMods
authored
Stop sending or processing the origin field in PDUs (#18418)
Co-authored-by: Quentin Gliech <quenting@element.io> Co-authored-by: Eric Eastwood <erice@element.io>
1 parent a2bee2f commit 2918800

File tree

11 files changed

+18
-32
lines changed

11 files changed

+18
-32
lines changed

changelog.d/18418.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stop adding the "origin" field to newly-created events (PDUs).

contrib/graph/graph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def make_graph(pdus: List[dict], filename_prefix: str) -> None:
4545
colors = {"red", "green", "blue", "yellow", "purple"}
4646

4747
for pdu in pdus:
48+
# TODO: The "origin" field has since been removed from events generated
49+
# by Synapse. We should consider removing it here as well but since this
50+
# is part of `contrib/`, it is left for the community to revise and ensure things
51+
# still work correctly.
4852
origins.add(pdu.get("origin"))
4953

5054
color_map = {color: color for color in colors if color in origins}

docs/admin_api/event_reports.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ It returns a JSON body like the following:
117117
"hashes": {
118118
"sha256": "xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw"
119119
},
120-
"origin": "matrix.org",
121120
"origin_server_ts": 1592291711430,
122121
"prev_events": [
123122
"$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M"

synapse/events/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ def __init__(
208208
depth: DictProperty[int] = DictProperty("depth")
209209
content: DictProperty[JsonDict] = DictProperty("content")
210210
hashes: DictProperty[Dict[str, str]] = DictProperty("hashes")
211-
origin: DictProperty[str] = DictProperty("origin")
212211
origin_server_ts: DictProperty[int] = DictProperty("origin_server_ts")
213212
room_id: DictProperty[str] = DictProperty("room_id")
214213
sender: DictProperty[str] = DictProperty("sender")

synapse/events/builder.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ def create_local_event_from_event_dict(
302302
event_dict: JsonDict,
303303
internal_metadata_dict: Optional[JsonDict] = None,
304304
) -> EventBase:
305-
"""Takes a fully formed event dict, ensuring that fields like `origin`
306-
and `origin_server_ts` have correct values for a locally produced event,
305+
"""Takes a fully formed event dict, ensuring that fields like
306+
`origin_server_ts` have correct values for a locally produced event,
307307
then signs and hashes it.
308308
"""
309309

@@ -319,7 +319,6 @@ def create_local_event_from_event_dict(
319319
if format_version == EventFormatVersions.ROOM_V1_V2:
320320
event_dict["event_id"] = _create_event_id(clock, hostname)
321321

322-
event_dict["origin"] = hostname
323322
event_dict.setdefault("origin_server_ts", time_now)
324323

325324
event_dict.setdefault("unsigned", {})

synapse/events/validator.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def validate_new(self, event: EventBase, config: HomeServerConfig) -> None:
6767
"auth_events",
6868
"content",
6969
"hashes",
70-
"origin",
7170
"prev_events",
7271
"sender",
7372
"type",
@@ -77,13 +76,6 @@ def validate_new(self, event: EventBase, config: HomeServerConfig) -> None:
7776
if k not in event:
7877
raise SynapseError(400, "Event does not have key %s" % (k,))
7978

80-
# Check that the following keys have string values
81-
event_strings = ["origin"]
82-
83-
for s in event_strings:
84-
if not isinstance(getattr(event, s), str):
85-
raise SynapseError(400, "'%s' not a string type" % (s,))
86-
8779
# Depending on the room version, ensure the data is spec compliant JSON.
8880
if event.room_version.strict_canonicaljson:
8981
validate_canonicaljson(event.get_pdu_json())

synapse/federation/federation_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ def event_from_pdu_json(pdu_json: JsonDict, room_version: RoomVersion) -> EventB
322322
SynapseError: if the pdu is missing required fields or is otherwise
323323
not a valid matrix event
324324
"""
325-
# we could probably enforce a bunch of other fields here (room_id, sender,
326-
# origin, etc etc)
325+
# we could probably enforce a bunch of other fields here (room_id, sender, etc.)
327326
assert_params_in_dict(pdu_json, ("type", "depth"))
328327

329328
# Strip any unauthorized values from "unsigned" if they exist

synapse/util/caches/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def register_cache(
225225
"depth",
226226
"event_id",
227227
"hashes",
228-
"origin",
228+
"origin", # old events were created with an origin field.
229229
"origin_server_ts",
230230
"prev_events",
231231
"room_id",

tests/crypto/test_event_signing.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def setUp(self) -> None:
4848
def test_sign_minimal(self) -> None:
4949
event_dict = {
5050
"event_id": "$0:domain",
51-
"origin": "domain",
5251
"origin_server_ts": 1000000,
5352
"signatures": {},
5453
"type": "X",
@@ -64,23 +63,22 @@ def test_sign_minimal(self) -> None:
6463
self.assertTrue(hasattr(event, "hashes"))
6564
self.assertIn("sha256", event.hashes)
6665
self.assertEqual(
67-
event.hashes["sha256"], "6tJjLpXtggfke8UxFhAKg82QVkJzvKOVOOSjUDK4ZSI"
66+
event.hashes["sha256"], "A6Nco6sqoy18PPfPDVdYvoowfc0PVBk9g9OiyT3ncRM"
6867
)
6968

7069
self.assertTrue(hasattr(event, "signatures"))
7170
self.assertIn(HOSTNAME, event.signatures)
7271
self.assertIn(KEY_NAME, event.signatures["domain"])
7372
self.assertEqual(
7473
event.signatures[HOSTNAME][KEY_NAME],
75-
"2Wptgo4CwmLo/Y8B8qinxApKaCkBG2fjTWB7AbP5Uy+"
76-
"aIbygsSdLOFzvdDjww8zUVKCmI02eP9xtyJxc/cLiBA",
74+
"PBc48yDVszWB9TRaB/+CZC1B+pDAC10F8zll006j+NN"
75+
"fe4PEMWcVuLaG63LFTK9e4rwJE8iLZMPtCKhDTXhpAQ",
7776
)
7877

7978
def test_sign_message(self) -> None:
8079
event_dict = {
8180
"content": {"body": "Here is the message content"},
8281
"event_id": "$0:domain",
83-
"origin": "domain",
8482
"origin_server_ts": 1000000,
8583
"type": "m.room.message",
8684
"room_id": "!r:domain",
@@ -98,14 +96,14 @@ def test_sign_message(self) -> None:
9896
self.assertTrue(hasattr(event, "hashes"))
9997
self.assertIn("sha256", event.hashes)
10098
self.assertEqual(
101-
event.hashes["sha256"], "onLKD1bGljeBWQhWZ1kaP9SorVmRQNdN5aM2JYU2n/g"
99+
event.hashes["sha256"], "rDCeYBepPlI891h/RkI2/Lkf9bt7u0TxFku4tMs7WKk"
102100
)
103101

104102
self.assertTrue(hasattr(event, "signatures"))
105103
self.assertIn(HOSTNAME, event.signatures)
106104
self.assertIn(KEY_NAME, event.signatures["domain"])
107105
self.assertEqual(
108106
event.signatures[HOSTNAME][KEY_NAME],
109-
"Wm+VzmOUOz08Ds+0NTWb1d4CZrVsJSikkeRxh6aCcUw"
110-
"u6pNC78FunoD7KNWzqFn241eYHYMGCA5McEiVPdhzBA",
107+
"Ay4aj2b5oJ1k8INYZ9n3KnszCflM0emwcmQQ7vxpbdc"
108+
"Sv9bkJxIZdWX1IJllcZLq89+D3sSabE+vqPtZs9akDw",
111109
)

tests/events/test_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_basic_keys(self) -> None:
122122
"prev_events": "prev_events",
123123
"prev_state": "prev_state",
124124
"auth_events": "auth_events",
125-
"origin": "domain",
125+
"origin": "domain", # historical top-level field that still exists on old events
126126
"origin_server_ts": 1234,
127127
"membership": "join",
128128
# Also include a key that should be removed.
@@ -139,7 +139,7 @@ def test_basic_keys(self) -> None:
139139
"prev_events": "prev_events",
140140
"prev_state": "prev_state",
141141
"auth_events": "auth_events",
142-
"origin": "domain",
142+
"origin": "domain", # historical top-level field that still exists on old events
143143
"origin_server_ts": 1234,
144144
"membership": "join",
145145
"content": {},
@@ -148,13 +148,12 @@ def test_basic_keys(self) -> None:
148148
},
149149
)
150150

151-
# As of room versions we now redact the membership, prev_states, and origin keys.
151+
# As of room versions we now redact the membership and prev_states keys.
152152
self.run_test(
153153
{
154154
"type": "A",
155155
"prev_state": "prev_state",
156156
"membership": "join",
157-
"origin": "example.com",
158157
},
159158
{"type": "A", "content": {}, "signatures": {}, "unsigned": {}},
160159
room_version=RoomVersions.V11,
@@ -238,7 +237,6 @@ def test_create(self) -> None:
238237
{
239238
"type": "m.room.create",
240239
"content": {"not_a_real_key": True},
241-
"origin": "some_homeserver",
242240
"nonsense_field": "some_random_garbage",
243241
},
244242
{

0 commit comments

Comments
 (0)