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
Improve logging when signature checks fail #12925
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e8ba5dc
Raise a dedicated `InvalidEventSignatureError` from `_check_sigs_on_pdu`
richvdh d696b92
Downgrade logging about redactions to DEBUG
richvdh ae44ee8
Raise `InvalidEventSignatureError` from `_check_sigs_and_hash`
richvdh dc05746
changelog
richvdh 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 @@ | ||
Improve the logging when signature checks on events fail. |
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
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 |
---|---|---|
|
@@ -54,7 +54,11 @@ | |
RoomVersions, | ||
) | ||
from synapse.events import EventBase, builder | ||
from synapse.federation.federation_base import FederationBase, event_from_pdu_json | ||
from synapse.federation.federation_base import ( | ||
FederationBase, | ||
InvalidEventSignatureError, | ||
event_from_pdu_json, | ||
) | ||
from synapse.federation.transport.client import SendJoinResponse | ||
from synapse.http.types import QueryParams | ||
from synapse.types import JsonDict, UserID, get_domain_from_id | ||
|
@@ -319,7 +323,13 @@ async def get_pdu_from_destination_raw( | |
pdu = pdu_list[0] | ||
|
||
# Check signatures are correct. | ||
signed_pdu = await self._check_sigs_and_hash(room_version, pdu) | ||
try: | ||
signed_pdu = await self._check_sigs_and_hash(room_version, pdu) | ||
except InvalidEventSignatureError as e: | ||
errmsg = f"event id {pdu.event_id}: {e}" | ||
logger.warning("%s", errmsg) | ||
raise SynapseError(403, errmsg, Codes.FORBIDDEN) | ||
|
||
return signed_pdu | ||
|
||
return None | ||
|
@@ -552,20 +562,24 @@ async def _check_sigs_and_hash_and_fetch_one( | |
|
||
Returns: | ||
The PDU (possibly redacted) if it has valid signatures and hashes. | ||
None if no valid copy could be found. | ||
""" | ||
|
||
res = None | ||
try: | ||
res = await self._check_sigs_and_hash(room_version, pdu) | ||
except SynapseError: | ||
pass | ||
|
||
if not res: | ||
# Check local db. | ||
res = await self.store.get_event( | ||
pdu.event_id, allow_rejected=True, allow_none=True | ||
return await self._check_sigs_and_hash(room_version, pdu) | ||
except InvalidEventSignatureError as e: | ||
logger.warning( | ||
"Signature on retrieved event %s was invalid (%s). " | ||
"Checking local store/orgin server", | ||
pdu.event_id, | ||
e, | ||
) | ||
Comment on lines
+570
to
576
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 was the real driver for the whole PR. I wanted a clearer error message when the sig check fails in this case. |
||
|
||
# Check local db. | ||
res = await self.store.get_event( | ||
pdu.event_id, allow_rejected=True, allow_none=True | ||
) | ||
|
||
pdu_origin = get_domain_from_id(pdu.sender) | ||
if not res and pdu_origin != origin: | ||
try: | ||
|
@@ -1040,9 +1054,14 @@ async def send_invite( | |
pdu = event_from_pdu_json(pdu_dict, room_version) | ||
|
||
# Check signatures are correct. | ||
pdu = await self._check_sigs_and_hash(room_version, pdu) | ||
try: | ||
pdu = await self._check_sigs_and_hash(room_version, pdu) | ||
except InvalidEventSignatureError as e: | ||
errmsg = f"event id {pdu.event_id}: {e}" | ||
logger.warning("%s", errmsg) | ||
raise SynapseError(403, errmsg, Codes.FORBIDDEN) | ||
|
||
# FIXME: We should handle signature failures more gracefully. | ||
# FIXME: We should handle signature failures more gracefully. | ||
|
||
return pdu | ||
|
||
|
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.
this (and the three other copies of the same change) should be a non-functional change; we're just pulling the functionality out of
_check_sigs_and_hash