Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Event.clearEvent handling to fix a bug where malformed events with falsey content wouldn't be considered decrypted #1807

Merged

Conversation

bradtgmurray
Copy link
Contributor

shouldAttemptDecryption was checking to see if we had a content property on our clearEvent, but it's possible that we've already been decrypted and the result still has a falsey content property. Instead, only set the clearEvent class member after we've successfully decrypted, and leave it undefined otherwise.

Signed-off-by: Brad Murray [email protected]

Copy link
Contributor Author

@bradtgmurray bradtgmurray left a comment

Choose a reason for hiding this comment

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

Most of this PR is just me reviewing references to clearEvent and making sure the code path still behaves if it's now undefined instead of an empty object.

@@ -486,7 +486,7 @@ export class MatrixEvent extends EventEmitter {
}

public shouldAttemptDecryption() {
return this.isEncrypted() && !this.isBeingDecrypted() && this.getClearContent() === null;
return this.isEncrypted() && !this.isBeingDecrypted() && !this.clearEvent;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the "fix" here.

src/models/event.ts Outdated Show resolved Hide resolved
src/models/event.ts Outdated Show resolved Hide resolved
src/models/event.ts Outdated Show resolved Hide resolved
src/models/event.ts Outdated Show resolved Hide resolved
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

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

Other than the minor nits this is great, thanks!

}).then((event) => {
expect(event.getRoomId()).toEqual(ROOM_ID);
expect(event.getContent()).toEqual({});
expect(event.getClearContent()).toBeUndefined();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test would fail on develop because getClearContent would continue to be null before and now it actually has the correct(?) value.

Also, testUtils.awaitDecryption would have thought that the event wasn't decoded yet because getClearContent would still be null, and therefore would wait for an "Event.decrypted" event that would never come as it was already decrypted.

@t3chguy t3chguy self-requested a review July 25, 2021 16:13
src/models/event.ts Outdated Show resolved Hide resolved
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

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

Great, thanks for this!

:shipit:

@t3chguy t3chguy merged commit 05c3236 into matrix-org:develop Jul 26, 2021
@bradtgmurray
Copy link
Contributor Author

Thanks for the feedback and the speedy review!

@dbkr dbkr added the T-Defect label Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants