Skip to content

Stop sending or processing the origin field in PDUs #18418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18418.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop adding the "origin" field to newly-created events (PDUs).
2 changes: 2 additions & 0 deletions contrib/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def make_graph(pdus: List[dict], filename_prefix: str) -> None:
colors = {"red", "green", "blue", "yellow", "purple"}

for pdu in pdus:
# TODO: The "origin" field have since been removed from events generated
# by Synapse.
origins.add(pdu.get("origin"))

color_map = {color: color for color in colors if color in origins}
Expand Down
1 change: 0 additions & 1 deletion docs/admin_api/event_reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ It returns a JSON body like the following:
"hashes": {
"sha256": "xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw"
},
"origin": "matrix.org",
"origin_server_ts": 1592291711430,
"prev_events": [
"$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M"
Expand Down
1 change: 0 additions & 1 deletion synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def __init__(
depth: DictProperty[int] = DictProperty("depth")
content: DictProperty[JsonDict] = DictProperty("content")
hashes: DictProperty[Dict[str, str]] = DictProperty("hashes")
origin: DictProperty[str] = DictProperty("origin")
origin_server_ts: DictProperty[int] = DictProperty("origin_server_ts")
room_id: DictProperty[str] = DictProperty("room_id")
sender: DictProperty[str] = DictProperty("sender")
Expand Down
1 change: 0 additions & 1 deletion synapse/events/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def create_local_event_from_event_dict(
if format_version == EventFormatVersions.ROOM_V1_V2:
event_dict["event_id"] = _create_event_id(clock, hostname)

event_dict["origin"] = hostname
event_dict.setdefault("origin_server_ts", time_now)

event_dict.setdefault("unsigned", {})
Expand Down
8 changes: 0 additions & 8 deletions synapse/events/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def validate_new(self, event: EventBase, config: HomeServerConfig) -> None:
"auth_events",
"content",
"hashes",
"origin",
"prev_events",
"sender",
"type",
Expand All @@ -77,13 +76,6 @@ def validate_new(self, event: EventBase, config: HomeServerConfig) -> None:
if k not in event:
raise SynapseError(400, "Event does not have key %s" % (k,))

# Check that the following keys have string values
event_strings = ["origin"]

for s in event_strings:
if not isinstance(getattr(event, s), str):
raise SynapseError(400, "'%s' not a string type" % (s,))

# Depending on the room version, ensure the data is spec compliant JSON.
if event.room_version.strict_canonicaljson:
validate_canonicaljson(event.get_pdu_json())
Expand Down
2 changes: 1 addition & 1 deletion synapse/util/caches/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def register_cache(
"depth",
"event_id",
"hashes",
"origin",
"origin", # old events were created with an origin field.
"origin_server_ts",
"prev_events",
"room_id",
Expand Down
2 changes: 0 additions & 2 deletions tests/crypto/test_event_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def setUp(self) -> None:
def test_sign_minimal(self) -> None:
event_dict = {
"event_id": "$0:domain",
"origin": "domain",
"origin_server_ts": 1000000,
"signatures": {},
"type": "X",
Expand Down Expand Up @@ -80,7 +79,6 @@ def test_sign_message(self) -> None:
event_dict = {
"content": {"body": "Here is the message content"},
"event_id": "$0:domain",
"origin": "domain",
"origin_server_ts": 1000000,
"type": "m.room.message",
"room_id": "!r:domain",
Expand Down
6 changes: 1 addition & 5 deletions tests/events/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def test_basic_keys(self) -> None:
"prev_events": "prev_events",
"prev_state": "prev_state",
"auth_events": "auth_events",
"origin": "domain",
"origin_server_ts": 1234,
"membership": "join",
# Also include a key that should be removed.
Expand All @@ -139,7 +138,6 @@ def test_basic_keys(self) -> None:
"prev_events": "prev_events",
"prev_state": "prev_state",
"auth_events": "auth_events",
"origin": "domain",
"origin_server_ts": 1234,
"membership": "join",
"content": {},
Expand All @@ -148,13 +146,12 @@ def test_basic_keys(self) -> None:
},
)

# As of room versions we now redact the membership, prev_states, and origin keys.
# As of room versions we now redact the membership and prev_states keys.
self.run_test(
{
"type": "A",
"prev_state": "prev_state",
"membership": "join",
"origin": "example.com",
},
{"type": "A", "content": {}, "signatures": {}, "unsigned": {}},
room_version=RoomVersions.V11,
Expand Down Expand Up @@ -238,7 +235,6 @@ def test_create(self) -> None:
{
"type": "m.room.create",
"content": {"not_a_real_key": True},
"origin": "some_homeserver",
"nonsense_field": "some_random_garbage",
},
{
Expand Down
3 changes: 0 additions & 3 deletions tests/federation/test_federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,6 @@ def test_strip_unauthorized_unsigned_values(self) -> None:
"depth": 1000,
"origin_server_ts": 1,
"type": "m.room.member",
"origin": "test.servx",
"content": {"membership": "join"},
"auth_events": [],
"unsigned": {"malicious garbage": "hackz", "more warez": "more hackz"},
Expand All @@ -550,7 +549,6 @@ def test_strip_event_maintains_allowed_fields(self) -> None:
"depth": 1000,
"origin_server_ts": 1,
"type": "m.room.member",
"origin": "test.servx",
"auth_events": [],
"content": {"membership": "join"},
"unsigned": {
Expand All @@ -577,7 +575,6 @@ def test_strip_event_removes_fields_based_on_event_type(self) -> None:
"depth": 1000,
"origin_server_ts": 1,
"type": "m.room.power_levels",
"origin": "test.servx",
"content": {},
"auth_events": [],
"unsigned": {
Expand Down
Loading