Skip to content

Commit

Permalink
Cancel receipt send when encountering safety number change
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and jamiebuilds-signal committed Feb 13, 2023
1 parent 32afdb3 commit 6a2b3c3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
7 changes: 7 additions & 0 deletions ts/jobs/conversationJobQueue.ts
Expand Up @@ -455,6 +455,13 @@ export class ConversationJobQueue extends JobQueue<ConversationQueueJobData> {
return;
}

if (type === jobSet.Receipts) {
log.warn(
`Cancelling receipt send, since there were ${untrustedUuids.length} untrusted send targets.`
);
return;
}

log.error(
`Send failed because ${untrustedUuids.length} conversation(s) were untrusted. Adding to verification list.`
);
Expand Down
23 changes: 2 additions & 21 deletions ts/jobs/helpers/sendProfileKey.ts
Expand Up @@ -23,7 +23,6 @@ import type {
ProfileKeyJobData,
} from '../conversationJobQueue';
import type { CallbackResultType } from '../../textsecure/Types.d';
import { isConversationAccepted } from '../../util/isConversationAccepted';
import { isConversationUnregistered } from '../../util/isConversationUnregistered';
import type { ConversationAttributesType } from '../../model-types.d';
import {
Expand All @@ -32,8 +31,7 @@ import {
SendMessageProtoError,
UnregisteredUserError,
} from '../../textsecure/Errors';
import { getRecipients } from '../../util/getRecipients';
import { getUntrustedConversationUuids } from './getUntrustedConversationUuids';
import { shouldSendToConversation } from './shouldSendToConversation';

export function canAllErrorsBeIgnored(
conversation: ConversationAttributesType,
Expand Down Expand Up @@ -104,24 +102,7 @@ export async function sendProfileKey(

// Note: flags and the profileKey itself are all that matter in the proto.

const recipients = getRecipients(conversation.attributes);
const untrustedUuids = getUntrustedConversationUuids(recipients);
if (untrustedUuids.length) {
log.info(
`conversation ${conversation.idForLogging()} has untrusted recipients; refusing to send`
);
}

if (!isConversationAccepted(conversation.attributes)) {
log.info(
`conversation ${conversation.idForLogging()} is not accepted; refusing to send`
);
return;
}
if (conversation.isBlocked()) {
log.info(
`conversation ${conversation.idForLogging()} is blocked; refusing to send`
);
if (!shouldSendToConversation(conversation, log)) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion ts/jobs/helpers/sendReceipts.ts
Expand Up @@ -7,12 +7,16 @@ import type {
ConversationQueueJobBundle,
ReceiptsJobData,
} from '../conversationJobQueue';
import { shouldSendToConversation } from './shouldSendToConversation';

export async function sendReceipts(
_conversation: ConversationModel,
conversation: ConversationModel,
{ log }: ConversationQueueJobBundle,
data: ReceiptsJobData
): Promise<void> {
if (!shouldSendToConversation(conversation, log)) {
return;
}
await sendReceiptsTask({
log,
receipts: data.receipts,
Expand Down
39 changes: 39 additions & 0 deletions ts/jobs/helpers/shouldSendToConversation.ts
@@ -0,0 +1,39 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import type { ConversationModel } from '../../models/conversations';
import type { LoggerType } from '../../types/Logging';
import { getRecipients } from '../../util/getRecipients';
import { isConversationAccepted } from '../../util/isConversationAccepted';
import { getUntrustedConversationUuids } from './getUntrustedConversationUuids';

export function shouldSendToConversation(
conversation: ConversationModel,
log: LoggerType
): boolean {
const recipients = getRecipients(conversation.attributes);
const untrustedUuids = getUntrustedConversationUuids(recipients);

if (untrustedUuids.length) {
log.info(
`conversation ${conversation.idForLogging()} has untrusted recipients; refusing to send`
);
return false;
}

if (!isConversationAccepted(conversation.attributes)) {
log.info(
`conversation ${conversation.idForLogging()} is not accepted; refusing to send`
);
return false;
}

if (conversation.isBlocked()) {
log.info(
`conversation ${conversation.idForLogging()} is blocked; refusing to send`
);
return false;
}

return true;
}

0 comments on commit 6a2b3c3

Please sign in to comment.