Skip to content

Commit 6fa6c3c

Browse files
committed
Ensure multi-recipient messages are addressed to ACI service IDs
1 parent e4ffc93 commit 6fa6c3c

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,13 @@ private void checkAccessKeys(
717717
final @NotNull CombinedUnidentifiedSenderAccessKeys accessKeys,
718718
final Collection<MultiRecipientDeliveryData> destinations) {
719719
final int keyLength = UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH;
720+
721+
if (destinations.stream()
722+
.anyMatch(destination -> IdentityType.PNI.equals(destination.serviceIdentifier.identityType()))) {
723+
throw new WebApplicationException("Multi-recipient messages must be addressed to ACI service IDs",
724+
Status.UNAUTHORIZED);
725+
}
726+
720727
final byte[] combinedUnidentifiedAccessKeys = destinations.stream()
721728
.map(MultiRecipientDeliveryData::account)
722729
.filter(Predicate.not(Account::isUnrestrictedUnidentifiedAccess))

service/src/test/java/org/whispersystems/textsecuregcm/controllers/MessageControllerTest.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,10 +1343,10 @@ private static ArgumentSets testMultiRecipientMessagePni() {
13431343
new MultiRecipientMessageTestCase(bothAccountsMixed, auth, story, 200, 4),
13441344
new MultiRecipientMessageTestCase(realAndFakeMixed, auth, story, 200, 4),
13451345

1346-
new MultiRecipientMessageTestCase(singleDevicePni, auth, notStory, 200, 1),
1347-
new MultiRecipientMessageTestCase(singleDeviceAciAndPni, unauth, story, 200, 2),
1348-
new MultiRecipientMessageTestCase(multiDevicePni, auth, notStory, 200, 3),
1349-
new MultiRecipientMessageTestCase(bothAccountsMixed, auth, notStory, 200, 4),
1346+
new MultiRecipientMessageTestCase(singleDevicePni, auth, notStory, 401, 0),
1347+
new MultiRecipientMessageTestCase(singleDeviceAciAndPni, auth, notStory, 401, 0),
1348+
new MultiRecipientMessageTestCase(multiDevicePni, auth, notStory, 401, 0),
1349+
new MultiRecipientMessageTestCase(bothAccountsMixed, auth, notStory, 401, 0),
13501350
new MultiRecipientMessageTestCase(realAndFakeMixed, auth, notStory, 404, 0))
13511351
.argumentsForNextParameter(false, true); // urgent
13521352
}
@@ -1580,10 +1580,10 @@ private static Stream<Arguments> testSendMultiRecipientMessageToUnknownAccounts(
15801580
);
15811581
}
15821582

1583-
@ParameterizedTest
1584-
@MethodSource
1585-
void sendMultiRecipientMessageMismatchedDevices(final ServiceIdentifier serviceIdentifier)
1586-
throws JsonProcessingException {
1583+
@Test
1584+
void sendMultiRecipientMessageMismatchedDevices() throws JsonProcessingException {
1585+
1586+
final ServiceIdentifier serviceIdentifier = MULTI_DEVICE_ACI_ID;
15871587

15881588
final byte extraDeviceId = MULTI_DEVICE_ID3 + 1;
15891589

@@ -1627,15 +1627,9 @@ void sendMultiRecipientMessageMismatchedDevices(final ServiceIdentifier serviceI
16271627
}
16281628
}
16291629

1630-
private static Stream<Arguments> sendMultiRecipientMessageMismatchedDevices() {
1631-
return Stream.of(
1632-
Arguments.of(MULTI_DEVICE_ACI_ID),
1633-
Arguments.of(MULTI_DEVICE_PNI_ID));
1634-
}
1635-
1636-
@ParameterizedTest
1637-
@MethodSource
1638-
void sendMultiRecipientMessageStaleDevices(final ServiceIdentifier serviceIdentifier) throws JsonProcessingException {
1630+
@Test
1631+
void sendMultiRecipientMessageStaleDevices() throws JsonProcessingException {
1632+
final ServiceIdentifier serviceIdentifier = MULTI_DEVICE_ACI_ID;
16391633
final List<Recipient> recipients = List.of(
16401634
new Recipient(serviceIdentifier, MULTI_DEVICE_ID1, MULTI_DEVICE_REG_ID1 + 1, new byte[48]),
16411635
new Recipient(serviceIdentifier, MULTI_DEVICE_ID2, MULTI_DEVICE_REG_ID2 + 1, new byte[48]),
@@ -1677,12 +1671,6 @@ void sendMultiRecipientMessageStaleDevices(final ServiceIdentifier serviceIdenti
16771671
}
16781672
}
16791673

1680-
private static Stream<Arguments> sendMultiRecipientMessageStaleDevices() {
1681-
return Stream.of(
1682-
Arguments.of(MULTI_DEVICE_ACI_ID),
1683-
Arguments.of(MULTI_DEVICE_PNI_ID));
1684-
}
1685-
16861674
@Test
16871675
void sendMultiRecipientMessageStoryRateLimited() {
16881676
final List<Recipient> recipients = List.of(new Recipient(SINGLE_DEVICE_ACI_ID, SINGLE_DEVICE_ID1, SINGLE_DEVICE_REG_ID1, new byte[48]));

0 commit comments

Comments
 (0)