This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Prevent clients from reporting nonexistent events. #13779
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b633f19
Don't allow users to generate bogus reports for events that don't exist
reivilibre 7b36001
Newsfile
reivilibre f9eecd4
Extract event_handler in constructor
reivilibre 8e33085
Merge branch 'develop' into rei/slash_report
reivilibre f321af7
Add a test for reporting non-existent event IDs
reivilibre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Prevent clients from reporting nonexistent events. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
from http import HTTPStatus | ||
from typing import TYPE_CHECKING, Tuple | ||
|
||
from synapse.api.errors import Codes, SynapseError | ||
from synapse.api.errors import Codes, NotFoundError, SynapseError | ||
from synapse.http.server import HttpServer | ||
from synapse.http.servlet import RestServlet, parse_json_object_from_request | ||
from synapse.http.site import SynapseRequest | ||
|
@@ -39,6 +39,7 @@ def __init__(self, hs: "HomeServer"): | |
self.auth = hs.get_auth() | ||
self.clock = hs.get_clock() | ||
self.store = hs.get_datastores().main | ||
self._event_handler = self.hs.get_event_handler() | ||
|
||
async def on_POST( | ||
self, request: SynapseRequest, room_id: str, event_id: str | ||
|
@@ -61,6 +62,14 @@ async def on_POST( | |
Codes.BAD_JSON, | ||
) | ||
|
||
event = await self._event_handler.get_event( | ||
requester.user, room_id, event_id, show_redacted=False | ||
) | ||
if event is None: | ||
raise NotFoundError( | ||
"Unable to report event: it does not exist or you aren't able to see it." | ||
) | ||
Comment on lines
+69
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really part of the spec, but I guess a 404 is reasonable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, best I can think of short of speccing something |
||
|
||
await self.store.add_event_report( | ||
room_id=room_id, | ||
event_id=event_id, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see cases where it's useful to be able to report an event that's been redacted. We keep redacted events in db for a few days (7 by default iirc) before purging them, so someone might want to report them to bring them up to the server's admins/T&S team, or their report might be racing with the redaction, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't care about fetching the redacted content here: this doesn't ignore redacted events, it just returns the redacted version (but since we only do this to check the event exists, it's OK I believe)