fix: do not try to store contacts not matching pubkey regex in wrapper
also remove existing convo with spaces and 05 on start
This commit is contained in:
parent
83079a8b4c
commit
7c16ce9da4
|
@ -4,10 +4,12 @@ import path from 'path';
|
|||
import * as BetterSqlite3 from '@signalapp/better-sqlite3';
|
||||
import rimraf from 'rimraf';
|
||||
|
||||
import { base64_variants, from_base64, to_hex } from 'libsodium-wrappers-sumo';
|
||||
import {
|
||||
chunk,
|
||||
compact,
|
||||
difference,
|
||||
differenceBy,
|
||||
forEach,
|
||||
fromPairs,
|
||||
isArray,
|
||||
|
@ -20,7 +22,6 @@ import {
|
|||
omit,
|
||||
uniq,
|
||||
} from 'lodash';
|
||||
import { base64_variants, from_base64, to_hex } from 'libsodium-wrappers-sumo';
|
||||
|
||||
import { ConversationAttributes } from '../models/conversationAttributes';
|
||||
import { PubKey } from '../session/types/PubKey'; // checked - only node
|
||||
|
@ -60,11 +61,13 @@ import {
|
|||
} from '../types/sqlSharedTypes';
|
||||
|
||||
import { KNOWN_BLINDED_KEYS_ITEM, SettingsKey } from '../data/settings-key';
|
||||
import { Quote } from '../receiver/types';
|
||||
import {
|
||||
getSQLCipherIntegrityCheck,
|
||||
openAndMigrateDatabase,
|
||||
updateSchema,
|
||||
} from './migration/signalMigrations';
|
||||
import { configDumpData } from './sql_calls/config_dump';
|
||||
import {
|
||||
assertGlobalInstance,
|
||||
assertGlobalInstanceOrInstance,
|
||||
|
@ -72,8 +75,6 @@ import {
|
|||
initDbInstanceWith,
|
||||
isInstanceInitialized,
|
||||
} from './sqlInstance';
|
||||
import { configDumpData } from './sql_calls/config_dump';
|
||||
import { Quote } from '../receiver/types';
|
||||
|
||||
// eslint:disable: function-name non-literal-fs-path
|
||||
|
||||
|
@ -620,11 +621,28 @@ function getAllConversations() {
|
|||
.prepare(`SELECT * FROM ${CONVERSATIONS_TABLE} ORDER BY id ASC;`)
|
||||
.all();
|
||||
|
||||
return (rows || []).map(m => {
|
||||
const unreadCount = getUnreadCountByConversation(m.id) || 0;
|
||||
const mentionedUsStillUnread = !!getFirstUnreadMessageWithMention(m.id);
|
||||
return formatRowOfConversation(m, 'getAllConversations', unreadCount, mentionedUsStillUnread);
|
||||
const formatted = compact(
|
||||
(rows || []).map(m => {
|
||||
const unreadCount = getUnreadCountByConversation(m.id) || 0;
|
||||
const mentionedUsStillUnread = !!getFirstUnreadMessageWithMention(m.id);
|
||||
return formatRowOfConversation(m, 'getAllConversations', unreadCount, mentionedUsStillUnread);
|
||||
})
|
||||
);
|
||||
|
||||
const invalidOnLoad = formatted.filter(m => {
|
||||
return isString(m.id) && m.id.startsWith('05') && m.id.includes(' ');
|
||||
});
|
||||
|
||||
if (!isEmpty(invalidOnLoad)) {
|
||||
const idsInvalid = invalidOnLoad.map(m => m.id);
|
||||
console.info(
|
||||
'getAllConversations removing those conversations with invalid ids before load',
|
||||
idsInvalid
|
||||
);
|
||||
removeConversation(idsInvalid);
|
||||
}
|
||||
|
||||
return differenceBy(formatted, invalidOnLoad, c => c.id);
|
||||
}
|
||||
|
||||
function getPubkeysInPublicConversation(conversationId: string) {
|
||||
|
|
|
@ -29,6 +29,11 @@ const mappedContactWrapperValues = new Map<string, ContactInfo>();
|
|||
* We want to sync the message request status so we need to allow a contact even if it's not approved, did not approve us and is not blocked.
|
||||
*/
|
||||
function isContactToStoreInWrapper(convo: ConversationModel): boolean {
|
||||
try {
|
||||
PubKey.cast(convo.id as string);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return !convo.isMe() && convo.isPrivate() && convo.isActive() && !PubKey.isBlinded(convo.id);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ describe('libsession_contacts', () => {
|
|||
describe('filter contacts for wrapper', () => {
|
||||
const ourNumber = '051234567890acbdef';
|
||||
const validArgs = {
|
||||
id: '051111567890acbdef',
|
||||
id: '050123456789abcdef050123456789abcdef0123456789abcdef050123456789ab',
|
||||
type: ConversationTypeEnum.PRIVATE,
|
||||
isApproved: true,
|
||||
active_at: 123,
|
||||
|
@ -137,6 +137,58 @@ describe('libsession_contacts', () => {
|
|||
).to.be.eq(false);
|
||||
});
|
||||
|
||||
it('excludes contacts not matching a pubkey syntax (space in middle)', () => {
|
||||
const validIdWithSpaceInIt =
|
||||
'050123456789abcdef050123456789 bcdef0123456789abcdef050123456789ab'; // len 66 but has a ' ' in the middle
|
||||
expect(
|
||||
SessionUtilContact.isContactToStoreInWrapper(
|
||||
new ConversationModel({
|
||||
...validArgs,
|
||||
id: validIdWithSpaceInIt,
|
||||
} as any)
|
||||
)
|
||||
).to.be.eq(false);
|
||||
});
|
||||
|
||||
it('excludes contacts not matching a pubkey syntax (space at the end)', () => {
|
||||
const validIdWithSpaceInIt =
|
||||
'050123456789abcdef050123456789abcdef0123456789abcdef050123456789a '; // len 66 but has a ' ' at the end
|
||||
expect(
|
||||
SessionUtilContact.isContactToStoreInWrapper(
|
||||
new ConversationModel({
|
||||
...validArgs,
|
||||
id: validIdWithSpaceInIt,
|
||||
} as any)
|
||||
)
|
||||
).to.be.eq(false);
|
||||
});
|
||||
|
||||
it('excludes contacts not matching a pubkey syntax (space at the start)', () => {
|
||||
const validIdWithSpaceInIt =
|
||||
' 050123456789abcdef050123456789abcdef0123456789abcdef050123456789ab'; // len 66 but has a ' ' at the start
|
||||
expect(
|
||||
SessionUtilContact.isContactToStoreInWrapper(
|
||||
new ConversationModel({
|
||||
...validArgs,
|
||||
id: validIdWithSpaceInIt,
|
||||
} as any)
|
||||
)
|
||||
).to.be.eq(false);
|
||||
});
|
||||
|
||||
it('excludes contacts not matching a pubkey syntax (non hex char)', () => {
|
||||
const validIdWithSpaceInIt =
|
||||
'050123456789abcdef050123456789abcdef0123456789abcdef050123456789aU'; // len 66 but has 'U' at the end
|
||||
expect(
|
||||
SessionUtilContact.isContactToStoreInWrapper(
|
||||
new ConversationModel({
|
||||
...validArgs,
|
||||
id: validIdWithSpaceInIt,
|
||||
} as any)
|
||||
)
|
||||
).to.be.eq(false);
|
||||
});
|
||||
|
||||
it('includes approved only by them ', () => {
|
||||
expect(
|
||||
SessionUtilContact.isContactToStoreInWrapper(
|
||||
|
|
Loading…
Reference in New Issue