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
Reject instead of erroring on invalid membership events #15564
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
61fb212
Do not error if sending an invalid membership event.
clokep 3c9ec0b
Remove identity check.
clokep 748e9b6
Newsfragment
clokep c075657
Fix type hint.
clokep 45b0bbf
Also check for signatures.
clokep 34faf72
Merge remote-tracking branch 'origin/develop' into clokep/third-party…
clokep 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 @@ | ||
Fix a long-standing bug where an invalid membership event could cause an internal server error. |
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 |
---|---|---|
|
@@ -1054,10 +1054,15 @@ def _verify_third_party_invite( | |
""" | ||
if "third_party_invite" not in event.content: | ||
return False | ||
if "signed" not in event.content["third_party_invite"]: | ||
third_party_invite = event.content["third_party_invite"] | ||
if not isinstance(third_party_invite, collections.abc.Mapping): | ||
return False | ||
signed = event.content["third_party_invite"]["signed"] | ||
for key in {"mxid", "token"}: | ||
if "signed" not in third_party_invite: | ||
return False | ||
signed = third_party_invite["signed"] | ||
if not isinstance(signed, collections.abc.Mapping): | ||
return False | ||
for key in {"mxid", "token", "signatures"}: | ||
if key not in signed: | ||
return False | ||
|
||
|
@@ -1075,8 +1080,6 @@ def _verify_third_party_invite( | |
|
||
if signed["mxid"] != event.state_key: | ||
return False | ||
if signed["token"] != token: | ||
return False | ||
|
||
for public_key_object in get_public_keys(invite_event): | ||
public_key = public_key_object["public_key"] | ||
|
@@ -1088,7 +1091,9 @@ def _verify_third_party_invite( | |
verify_key = decode_verify_key_bytes( | ||
key_name, decode_base64(public_key) | ||
) | ||
verify_signed_json(signed, server, verify_key) | ||
# verify_signed_json incorrectly states it wants a dict, it | ||
# just needs a mapping. | ||
verify_signed_json(signed, server, verify_key) # type: ignore[arg-type] | ||
Comment on lines
+1094
to
+1096
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. I'll fix this separately in signed-json. |
||
|
||
# We got the public key from the invite, so we know that the | ||
# correct server signed the signed bundle. | ||
|
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.
On line 1064 we set
token = signed["token"]
. Neithertoken
norsigned
change in the interim, so this is now just checking against itself.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 dug into the past to see if it was different and this just seems to be the
third_party_invite
content shape evolving and mistaken refactors from 8 years ago.