Skip to content

Commit

Permalink
MessageReceiver: handle sender key distro message included in any proto
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Nonnenberg <scott@signal.org>
  • Loading branch information
automated-signal and scottnonnenberg-signal committed Jan 25, 2023
1 parent fa526c1 commit fdfbab0
Showing 1 changed file with 45 additions and 47 deletions.
92 changes: 45 additions & 47 deletions ts/textsecure/MessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,59 +1413,57 @@ export default class MessageReceiver
envelope,
content.senderKeyDistributionMessage
);
} else {
// Note: `story = true` can be set for sender key distribution messages
}

const isStoryReply = Boolean(content.dataMessage?.storyContext);
const isGroupStoryReply = Boolean(
isStoryReply && content.dataMessage?.groupV2
const isStoryReply = Boolean(content.dataMessage?.storyContext);
const isGroupStoryReply = Boolean(
isStoryReply && content.dataMessage?.groupV2
);
const isStory = Boolean(content.storyMessage);
const isDeleteForEveryone = Boolean(content.dataMessage?.delete);

if (
envelope.story &&
!(isGroupStoryReply || isStory) &&
!isDeleteForEveryone
) {
log.warn(
`${logId}: Dropping story message - story=true on envelope, but message was not a group story send or delete`
);
const isStory = Boolean(content.storyMessage);
const isDeleteForEveryone = Boolean(content.dataMessage?.delete);

if (
envelope.story &&
!(isGroupStoryReply || isStory) &&
!isDeleteForEveryone
) {
log.warn(
`${logId}: Dropping story message - story=true on envelope, but message was not a group story send or delete`
);
this.removeFromCache(envelope);
return { plaintext: undefined, envelope };
}
this.removeFromCache(envelope);
return { plaintext: undefined, envelope };
}

if (!envelope.story && (isGroupStoryReply || isStory)) {
log.warn(
`${logId}: Malformed story - story=false on envelope, but was a group story send`
);
}
if (!envelope.story && (isGroupStoryReply || isStory)) {
log.warn(
`${logId}: Malformed story - story=false on envelope, but was a group story send`
);
}

const areStoriesBlocked = getStoriesBlocked();
// Note that there are other story-related message types which aren't captured
// here. Look for other calls to getStoriesBlocked down-file.
if (areStoriesBlocked && (isStoryReply || isStory)) {
log.warn(
`${logId}: Dropping story message - stories are disabled or unavailable`
);
this.removeFromCache(envelope);
return { plaintext: undefined, envelope };
}
const areStoriesBlocked = getStoriesBlocked();
// Note that there are other story-related message types which aren't captured
// here. Look for other calls to getStoriesBlocked down-file.
if (areStoriesBlocked && (isStoryReply || isStory)) {
log.warn(
`${logId}: Dropping story message - stories are disabled or unavailable`
);
this.removeFromCache(envelope);
return { plaintext: undefined, envelope };
}

const sender = window.ConversationController.get(
envelope.sourceUuid || envelope.source
const sender = window.ConversationController.get(
envelope.sourceUuid || envelope.source
);
if (
(isStoryReply || isStory) &&
!isGroupV2 &&
(!sender || !sender.get('profileSharing'))
) {
log.warn(
`${logId}: Dropping story message - !profileSharing for sender`
);
if (
(isStoryReply || isStory) &&
!isGroupV2 &&
(!sender || !sender.get('profileSharing'))
) {
log.warn(
`${logId}: Dropping story message - !profileSharing for sender`
);
this.removeFromCache(envelope);
return { plaintext: undefined, envelope };
}
this.removeFromCache(envelope);
return { plaintext: undefined, envelope };
}

if (content.pniSignatureMessage) {
Expand Down

0 comments on commit fdfbab0

Please sign in to comment.