Fix issue when receiving invalid message from invalid sender

This commit is contained in:
AsamK 2022-10-07 21:50:07 +02:00
parent 605f31d1ad
commit ca5951861a

View file

@ -139,17 +139,23 @@ public final class IncomingMessageHandler {
} else { } else {
final var senderProfile = context.getProfileHelper().getRecipientProfile(sender); final var senderProfile = context.getProfileHelper().getRecipientProfile(sender);
final var selfProfile = context.getProfileHelper().getSelfProfile(); final var selfProfile = context.getProfileHelper().getSelfProfile();
final var serviceId = ServiceId.parseOrThrow(e.getSender()); final var serviceId = ServiceId.parseOrNull(e.getSender());
if ((!sender.equals(account.getSelfRecipientId()) || e.getSenderDevice() != account.getDeviceId()) if (serviceId != null) {
&& senderProfile != null final var isSelf = sender.equals(account.getSelfRecipientId())
&& senderProfile.getCapabilities().contains(Profile.Capability.senderKey) && e.getSenderDevice() == account.getDeviceId();
&& selfProfile != null final var isSenderSenderKeyCapable = senderProfile != null && senderProfile.getCapabilities()
&& selfProfile.getCapabilities().contains(Profile.Capability.senderKey)) { .contains(Profile.Capability.senderKey);
logger.debug("Received invalid message, requesting message resend."); final var isSelfSenderKeyCapable = selfProfile != null && selfProfile.getCapabilities()
actions.add(new SendRetryMessageRequestAction(sender, serviceId, e, envelope)); .contains(Profile.Capability.senderKey);
if (!isSelf && isSenderSenderKeyCapable && isSelfSenderKeyCapable) {
logger.debug("Received invalid message, requesting message resend.");
actions.add(new SendRetryMessageRequestAction(sender, serviceId, e, envelope));
} else {
logger.debug("Received invalid message, queuing renew session action.");
actions.add(new RenewSessionAction(sender, serviceId));
}
} else { } else {
logger.debug("Received invalid message, queuing renew session action."); logger.debug("Received invalid message from invalid sender: {}", e.getSender());
actions.add(new RenewSessionAction(sender, serviceId));
} }
} }
exception = e; exception = e;