Improve username validity checks

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2026-03-12 15:20:50 -05:00
committed by GitHub
parent da339458ce
commit aed991f2d4
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,
});