Skip to content

Commit e1b429d

Browse files
authored
Add experimental support for MSC4277: Harmonizing the reporting endpoints (#18263)
[MSC4277](matrix-org/matrix-spec-proposals#4277): Harmonizing the reporting endpoints
1 parent 8c1e600 commit e1b429d

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

changelog.d/18263.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add experimental support for [MSC4277](https://github.com/matrix-org/matrix-spec-proposals/pull/4277).

synapse/config/experimental.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,12 @@ def read_config(
561561
# MSC4076: Add `disable_badge_count`` to pusher configuration
562562
self.msc4076_enabled: bool = experimental.get("msc4076_enabled", False)
563563

564+
# MSC4277: Harmonizing the reporting endpoints
565+
#
566+
# If enabled, ignore the score parameter and respond with HTTP 200 on
567+
# reporting requests regardless of the subject's existence.
568+
self.msc4277_enabled: bool = experimental.get("msc4277_enabled", False)
569+
564570
# MSC4235: Add `via` param to hierarchy endpoint
565571
self.msc4235_enabled: bool = experimental.get("msc4235_enabled", False)
566572

synapse/rest/client/reporting.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ async def on_POST(
6969
"Param 'reason' must be a string",
7070
Codes.BAD_JSON,
7171
)
72-
if type(body.get("score", 0)) is not int: # noqa: E721
72+
if (
73+
not self.hs.config.experimental.msc4277_enabled
74+
and type(body.get("score", 0)) is not int
75+
): # noqa: E721
7376
raise SynapseError(
7477
HTTPStatus.BAD_REQUEST,
7578
"Param 'score' must be an integer",
@@ -85,10 +88,15 @@ async def on_POST(
8588
event = None
8689

8790
if event is None:
88-
raise NotFoundError(
89-
"Unable to report event: "
90-
"it does not exist or you aren't able to see it."
91-
)
91+
if self.hs.config.experimental.msc4277_enabled:
92+
# Respond with 200 and no content regardless of whether the event
93+
# exists to prevent enumeration attacks.
94+
return 200, {}
95+
else:
96+
raise NotFoundError(
97+
"Unable to report event: "
98+
"it does not exist or you aren't able to see it."
99+
)
92100

93101
await self.store.add_event_report(
94102
room_id=room_id,
@@ -138,7 +146,12 @@ async def on_POST(
138146

139147
room = await self.store.get_room(room_id)
140148
if room is None:
141-
raise NotFoundError("Room does not exist")
149+
if self.hs.config.experimental.msc4277_enabled:
150+
# Respond with 200 and no content regardless of whether the room
151+
# exists to prevent enumeration attacks.
152+
return 200, {}
153+
else:
154+
raise NotFoundError("Room does not exist")
142155

143156
await self.store.add_room_report(
144157
room_id=room_id,

tests/rest/client/test_reporting.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from synapse.util import Clock
3030

3131
from tests import unittest
32+
from tests.unittest import override_config
3233

3334

3435
class ReportEventTestCase(unittest.HomeserverTestCase):
@@ -81,6 +82,11 @@ def test_reason_and_score_null(self) -> None:
8182
data = {"reason": None, "score": None}
8283
self._assert_status(400, data)
8384

85+
@override_config({"experimental_features": {"msc4277_enabled": True}})
86+
def test_score_str(self) -> None:
87+
data = {"score": "string"}
88+
self._assert_status(200, data)
89+
8490
def test_cannot_report_nonexistent_event(self) -> None:
8591
"""
8692
Tests that we don't accept event reports for events which do not exist.
@@ -98,6 +104,19 @@ def test_cannot_report_nonexistent_event(self) -> None:
98104
msg=channel.result["body"],
99105
)
100106

107+
@override_config({"experimental_features": {"msc4277_enabled": True}})
108+
def test_event_existence_hidden(self) -> None:
109+
"""
110+
Tests that the requester cannot infer the existence of an event.
111+
"""
112+
channel = self.make_request(
113+
"POST",
114+
f"rooms/{self.room_id}/report/$nonsenseeventid:test",
115+
{"reason": "i am very sad"},
116+
access_token=self.other_user_tok,
117+
)
118+
self.assertEqual(200, channel.code, msg=channel.result["body"])
119+
101120
def test_cannot_report_event_if_not_in_room(self) -> None:
102121
"""
103122
Tests that we don't accept event reports for events that exist, but for which
@@ -193,6 +212,20 @@ def test_cannot_report_nonexistent_room(self) -> None:
193212
msg=channel.result["body"],
194213
)
195214

215+
@override_config({"experimental_features": {"msc4277_enabled": True}})
216+
def test_room_existence_hidden(self) -> None:
217+
"""
218+
Tests that the requester cannot infer the existence of a room.
219+
"""
220+
channel = self.make_request(
221+
"POST",
222+
"/_matrix/client/v3/rooms/!bloop:example.org/report",
223+
{"reason": "i am very sad"},
224+
access_token=self.other_user_tok,
225+
shorthand=False,
226+
)
227+
self.assertEqual(200, channel.code, msg=channel.result["body"])
228+
196229
def _assert_status(self, response_status: int, data: JsonDict) -> None:
197230
channel = self.make_request(
198231
"POST",

0 commit comments

Comments
 (0)