From adc4af996d30b295b06e4ee517aa53be62c0f6c1 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Thu, 26 Sep 2024 21:50:23 +0200 Subject: [PATCH] fix: omit invalid username characters in oidc registration --- backend/src/oauth/oauth.service.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/oauth/oauth.service.ts b/backend/src/oauth/oauth.service.ts index 691469a9..daef0ab1 100644 --- a/backend/src/oauth/oauth.service.ts +++ b/backend/src/oauth/oauth.service.ts @@ -108,8 +108,10 @@ export class OAuthService { } private async getAvailableUsername(preferredUsername: string) { - // only remove + and - from preferred username for now (maybe not enough) - let username = preferredUsername.replace(/[+-]/g, "").substring(0, 20); + // Only keep letters, numbers, dots, and underscores. Truncate to 20 characters. + let username = preferredUsername + .replace(/[^a-zA-Z0-9._]/g, "") + .substring(0, 20); while (true) { const user = await this.prisma.user.findFirst({ where: {