Fix check for valid sender when handling sync message

pull/877/head
Mikunj 5 years ago
parent 0eaebcbcac
commit a03185248c

@ -131,7 +131,7 @@
if (deviceMapping.isPrimary === '0') { if (deviceMapping.isPrimary === '0') {
const { primaryDevicePubKey } = const { primaryDevicePubKey } =
authorisations.find( authorisations.find(
authorisation => authorisation.secondaryDevicePubKey === pubKey authorisation => authorisation && authorisation.secondaryDevicePubKey === pubKey
) || {}; ) || {};
if (primaryDevicePubKey) { if (primaryDevicePubKey) {
// do NOT call getprimaryDeviceMapping recursively // do NOT call getprimaryDeviceMapping recursively

@ -1469,18 +1469,20 @@ MessageReceiver.prototype.extend({
this.removeFromCache(envelope); this.removeFromCache(envelope);
}, },
async handleSyncMessage(envelope, syncMessage) { async handleSyncMessage(envelope, syncMessage) {
// We should only accept sync messages from our devices
const ourNumber = textsecure.storage.user.getNumber(); const ourNumber = textsecure.storage.user.getNumber();
// NOTE: Maybe we should be caching this list? const ourPrimaryNumber = window.storage.get('primaryDevicePubKey');
const ourDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( const ourOtherDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey(
window.storage.get('primaryDevicePubKey') window.storage.get('primaryDevicePubKey')
); );
const validSyncSender = const ourDevices = new Set([ourNumber, ourPrimaryNumber, ...ourOtherDevices]);
ourDevices && ourDevices.some(devicePubKey => devicePubKey === ourNumber); const validSyncSender = ourDevices.has(envelope.source);
if (!validSyncSender) { if (!validSyncSender) {
throw new Error( throw new Error(
"Received sync message from a device we aren't paired with" "Received sync message from a device we aren't paired with"
); );
} }
if (syncMessage.sent) { if (syncMessage.sent) {
const sentMessage = syncMessage.sent; const sentMessage = syncMessage.sent;
const to = sentMessage.message.group const to = sentMessage.message.group

Loading…
Cancel
Save