Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Conversation

@Yoric
Copy link
Contributor

@Yoric Yoric commented Jan 22, 2021

Context

This patch implements (a subset of) MSC 2938, i.e. the ability for users to report content to room moderators instead of system administrators.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
  • Pull request includes a sign off
  • Code style is correct (run the linters)

@Yoric Yoric marked this pull request as draft January 22, 2021 11:41
@clokep clokep requested a review from a team January 22, 2021 12:14
@clokep
Copy link
Member

clokep commented Jan 22, 2021

@Yoric asked for some early feedback on this.

@clokep
Copy link
Member

clokep commented Jan 26, 2021

This relates to matrix-org/matrix-spec-proposals#2938.

Copy link
Member

@clokep clokep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put some thoughts down on the code here. I think my main concern is how different reporting to a room moderator vs. a server admin is (one stores in the db, the other sends a notices message). I'm also a bit concerned that this might not make sense on other homeserver implementations or for all Synapse configs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docstrings and type hints.

This seems very different than how we handle the ones for homeserver admins. Does this behavior make sense?

In particular note that the server notices system is disabled by default in Synapse.

In particular is there need for any more state to be kept of these reports (e.g. the admin one gets stored into a table).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docstrings and type hints.

This seems very different than how we handle the ones for homeserver admins. Does this behavior make sense?

Well, this is being summarized/discussed here. It seems to be the best way for moderators to actually receive the info.

In particular note that the server notices system is disabled by default in Synapse.

It is enabled on matrix.org and EMS, though, right?

In particular is there need for any more state to be kept of these reports (e.g. the admin one gets stored into a table).

Not as far as I can tell. It's a simple message. We can't do that for the homeserver admin because the homeserver admin doesn't have an account, but in the future, we could imagine changing how it works for admins.

@ShadowJonathan
Copy link
Contributor

Continuing thoughts from matrix-org/matrix-spec-proposals#2938, maybe the best course of actions would be to send EDUs to target servers (which're more likely to be dropped safely if the remote server does not support this), and add a hook into the federation receiving mechanism to check for these EDUs, and then add them to an internal database?

Afterwards, when a potential MSC for homeserver-to-homeserver rooms is made ready, the mechanism can switch to that approach, while keeping the database and federation scoop.

This makes the federation-injection approach a glass-cannon hotfix for now (since it's fairly urgent), with the downside of it not being resilient to server downtime of the other side, while in the future a better approach can be steamrolled.

@Yoric Yoric requested a review from clokep March 19, 2021 11:18
@Yoric
Copy link
Contributor Author

Yoric commented Mar 19, 2021

Ok, ready for a new round of review.
We're still missing federation tests.

@Yoric Yoric force-pushed the develop-msc2938 branch 2 times, most recently from 06d07f8 to 2a7ac22 Compare March 19, 2021 13:23
@Yoric
Copy link
Contributor Author

Yoric commented Mar 29, 2021

@clokep Review ping?

@richvdh richvdh requested a review from a team March 29, 2021 10:56
@clokep clokep removed their request for review March 29, 2021 14:15
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yoric what are you looking for here? Feedback on the MSC? Feedback on whether the impl matches the MSC? Are there particular parts of the impl you have questions on?

The impl looks generally plausible, though as I point out I'd like to see part of it split out to a Handler class.

I'm a little worried about DoS vectors: it seems like it would be easy for a malicious client or federated server to spew hundreds of abuse reports which stack up into server notices. (Of course, that vector exists today, but it's hard to turn into a proper DoS.) Maybe we should apply some pre-emptive rate-limiting?

@Yoric
Copy link
Contributor Author

Yoric commented Mar 30, 2021

@Yoric what are you looking for here? Feedback on the MSC? Feedback on whether the impl matches the MSC? Are there particular parts of the impl you have questions on?

Essentially, I'd like to land this at some point during the next few weeks and then start experimenting with using this in the front-end. So, I'm looking for anything that can bring me closer to that end!

(I will apply your feedback asap)

@Yoric Yoric force-pushed the develop-msc2938 branch 2 times, most recently from 5b1c536 to 7113dc1 Compare April 7, 2021 15:14
@Yoric
Copy link
Contributor Author

Yoric commented Apr 8, 2021

Maybe we should apply some pre-emptive rate-limiting?

Done.

@Yoric Yoric force-pushed the develop-msc2938 branch 3 times, most recently from 2b164b9 to 09ddd87 Compare April 8, 2021 15:14
@Yoric Yoric changed the title [WIP] Prototyping MSC 2938 Prototyping MSC 2938 Apr 8, 2021
@Yoric Yoric marked this pull request as ready for review April 8, 2021 15:22
@Yoric Yoric requested a review from richvdh April 8, 2021 15:22
@Yoric
Copy link
Contributor Author

Yoric commented Apr 8, 2021

Note: I still need to write sytests.

@richvdh richvdh requested a review from a team April 8, 2021 21:19
@richvdh
Copy link
Member

richvdh commented Apr 8, 2021

[looks like your tests are failing]

@Yoric Yoric requested a review from richvdh April 9, 2021 10:44
@richvdh richvdh changed the title Prototyping MSC 2938 Implementation of MSC2938 Apr 9, 2021
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diff (https://github.com/matrix-org/synapse/pull/9207/files) seems to contain a bunch of unrelated changes: can you fix that so that this can be reviewed, please?

As a matter of general principle, in future please avoid rebasing PR branches once they have received a review, so that it's possible to see how it has changed since the previous review.

@Yoric
Copy link
Contributor Author

Yoric commented Apr 9, 2021

Apologies, looks like a merge error.

As a matter of general principle, in future please avoid rebasing PR branches once they have received a review, so that it's possible to see how it has changed since the previous review.

I'm not sure how I can do that when the review process has started 4 months ago and the work on typing has changed much of the underlying code since then. What's the policy in such cases?

@Yoric Yoric force-pushed the develop-msc2938 branch from 549a431 to 92f3c7f Compare April 9, 2021 11:37
@richvdh
Copy link
Member

richvdh commented Apr 9, 2021

As a matter of general principle, in future please avoid rebasing PR branches once they have received a review, so that it's possible to see how it has changed since the previous review.

I'm not sure how I can do that when the review process has started 4 months ago and the work on typing has changed much of the underlying code since then. What's the policy in such cases?

I agree if it's a complete rewrite then there's not much value in a merge rather than a rebase, but I'm assuming it hasn't completely changed since I first reviewed this (11 days ago).

@richvdh richvdh self-requested a review April 9, 2021 12:31
@Yoric
Copy link
Contributor Author

Yoric commented Apr 12, 2021

I agree if it's a complete rewrite then there's not much value in a merge rather than a rebase, but I'm assuming it hasn't completely changed since I first reviewed this (11 days ago).

I believe that we're using different meanings of the word "rebase". I'll try and avoid overwriting history in the future!

@richvdh
Copy link
Member

richvdh commented Apr 12, 2021

I'm referring to git rebase ;-p. Thanks!

Comment on lines 54 to 59
self.federation_sender = None
if hs.should_send_federation():
self.federation_sender = hs.get_federation_sender()
hs.get_federation_registry().register_edu_handler(
"org.matrix.m.content_report", self.on_receive_report_through_federation
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this stuff probably isn't going to work right in a multi-worker synapse deployment, though I think fixing that is out of scope for this PR review...

@Yoric Yoric requested a review from richvdh April 20, 2021 14:23
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting there! could you implement the msc2938_enabled setting properly please?

retry_after_ms=int(1000 * (time_allowed - time_now_s))
)
"""
Report an event as abuse.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Report an event as abuse.
Handle a request from a client to report an event as abuse.

room_id: The room in which the event took place.
reason: The human-readable reason provided by the user.
content: A JSON dictionary `{reason: String?, score: Number?}`.
score Optionally, a "badness" score where -100 is "really bad" and 0 is "acceptable".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
score Optionally, a "badness" score where -100 is "really bad" and 0 is "acceptable".
score: Optionally, a "badness" score where -100 is "really bad" and 0 is "acceptable".

room_id: The room in which the event took place.
reason: The human-readable reason provided by the user.
content: A JSON dictionary `{reason: String?, score: Number?}`.
score Optionally, a "badness" score where -100 is "really bad" and 0 is "acceptable".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in what way is it optional? the type declaration is int, not Optional.

reason: The human-readable reason provided by the user.
content: A JSON dictionary `{reason: String?, score: Number?}`.
score Optionally, a "badness" score where -100 is "really bad" and 0 is "acceptable".
nature An optional flag to aid classification and prioritization of abuse reports, e.g. "m.abuse.spam".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nature An optional flag to aid classification and prioritization of abuse reports, e.g. "m.abuse.spam".
nature: An optional flag to aid classification and prioritization of abuse reports, e.g. "m.abuse.spam".

self.msc3026_enabled = experimental.get("msc3026_enabled", False) # type: bool

# MSC2938 (report to moderator)
self.msc2938_enabled = experimental.get("msc2938_enabled", False) # type: bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is actually used?

Comment on lines +156 to +161
room_id The room in which the event took place.
event_id The event to report. We do not check whether the event took place in that room.
user_id The user who reported the event. We do not check whether the user can actually witness the event.
reason The human-readable reason provided by the user.
nature An optional flag to aid classification and prioritization of abuse reports, e.g. "abuse.spam".
score Optionally, a "badness" score where -100 is "really bad" and 0 is "acceptable".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all need :

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also, could they be in the right order, please?)


# A little sanity check on the event itself.
event = await self.store.get_event(event_id=event_id, check_room_id=None)
if event.room_id != room_id.to_string():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again I ask: why not let get_event do this check for you?

Generally it's a pretty poor use of your time and mine for me to make the same review comment multiple times. If something I've written is unclear, just comment on the thread and I'll do my best to clarify.

request, requester.user, body, room_id, event_id
await self._rate_limiter.ratelimit(requester=requester)

if not isinstance(body["reason"], str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will 500 if there is no reason property.

Suggested change
if not isinstance(body["reason"], str):
reason = body.get("reason")
if not isinstance(reason, str):

likewise below for score.

@erikjohnston erikjohnston added the X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged label May 20, 2021
@richvdh
Copy link
Member

richvdh commented Jun 2, 2021

@Yoric I believe you're planning to abandon this in favour of MSC3215 - are you happy for us to close this PR?

@Yoric
Copy link
Contributor Author

Yoric commented Jun 2, 2021

Yes, let's close it.

@Yoric Yoric closed this Jun 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants