Improve username validity checks

This commit is contained in:
trevor-signal
2026-03-12 12:38:14 -04:00
committed by GitHub
parent 1e7d5ec614
commit 6c28e066cd
3 changed files with 14 additions and 3 deletions

View File

@@ -267,6 +267,7 @@ import { maybeNotify } from '../messages/maybeNotify.preload.js';
import { missingCaseError } from '../util/missingCaseError.std.js';
import * as Message from '../types/Message2.preload.js';
import { itemStorage } from '../textsecure/Storage.preload.js';
import { isUsernameValid } from '../util/Username.dom.js';
const { compact, isNumber, throttle, debounce } = lodash;
@@ -4454,6 +4455,16 @@ export class ConversationModel {
return;
}
if (username && !isUsernameValid(username)) {
log.error(
`updateUsername(${this.idForLogging()}): username is invalid, dropping`,
{
fromStorageService,
}
);
return;
}
log.info(`updateUsername(${this.idForLogging()}): updating username`);
this.#doSet({ username });

View File

@@ -1259,7 +1259,7 @@ export class BackupExportStream extends Readable {
aci,
pni,
e164,
username: convo.username ?? null,
username: convo.username || null,
blocked: convo.serviceId
? itemStorage.blocked.isServiceIdBlocked(convo.serviceId)
: null,

View File

@@ -1378,7 +1378,7 @@ export async function mergeContactRecord(
};
}
await conversation.updateUsername(dropNull(contactRecord.username), {
await conversation.updateUsername(dropNull(contactRecord.username || null), {
shouldSave: false,
fromStorageService: true,
});
@@ -1986,7 +1986,7 @@ export async function mergeAccountRecord(
needsStorageServiceSync: false,
});
await conversation.updateUsername(dropNull(username), {
await conversation.updateUsername(dropNull(username || null), {
shouldSave: false,
fromStorageService: true,
});