From e622b016fcb79ec9ffee18adcfa134a44e307034 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 25 Nov 2026 20:29:07 -0500 Subject: [PATCH] fix: Validate provider details when connecting authentication (#14704) * fix: Validate provider details when connecting authentication * fix: Limit provider validation to personal Google accounts * fix: Only validate provider details when connecting a new provider --- server/commands/accountProvisioner.test.ts | 64 ++++++++++++++++++++++ server/commands/accountProvisioner.ts | 6 ++ 2 files changed, 70 insertions(+) diff --git a/server/commands/accountProvisioner.test.ts b/server/commands/accountProvisioner.test.ts index ec596b0915..bb0458c3df 100644 --- a/server/commands/accountProvisioner.test.ts +++ b/server/commands/accountProvisioner.test.ts @@ -893,6 +893,70 @@ describe("accountProvisioner", () => { expect(isNewUser).toEqual(false); }); + it("should not connect or reconnect an authentication provider with an empty providerId", async () => { + const admin = await buildAdmin(); + const team = admin.team; + const [existingProvider] = await team.$get("authenticationProviders"); + + await expect( + accountProvisioner(createContext({ ip, user: admin }), { + user: { + name: admin.name, + email: admin.email!, + }, + team: { + teamId: team.id, + subdomain: team.subdomain!, + }, + authenticationProvider: { + name: existingProvider.name, + providerId: "", + }, + authentication: { + providerId: randomUUID(), + scopes: ["read"], + }, + }) + ).rejects.toThrow(); + + const providers = await team.$get("authenticationProviders"); + expect(providers.length).toEqual(1); + expect(providers[0].providerId).toEqual(existingProvider.providerId); + }); + + it("should allow an admin through an already connected provider with an empty providerId", async () => { + const team = await buildTeam({ + authenticationProviders: [{ name: "discord", providerId: "" }], + }); + const admin = await buildAdmin({ teamId: team.id }); + + const { user } = await accountProvisioner( + createContext({ ip, user: admin }), + { + user: { + name: admin.name, + email: admin.email!, + }, + team: { + teamId: team.id, + subdomain: team.subdomain!, + }, + authenticationProvider: { + name: "discord", + providerId: "", + }, + authentication: { + providerId: randomUUID(), + scopes: ["read"], + }, + } + ); + + expect(user.id).toEqual(admin.id); + const providers = await team.$get("authenticationProviders"); + expect(providers.length).toEqual(1); + }); + it("should add an authentication provider when the team has several of the same type", async () => { const team = await buildTeam({ authenticationProviders: [ diff --git a/server/commands/accountProvisioner.ts b/server/commands/accountProvisioner.ts index 9801785af5..ec11fb3459 100644 --- a/server/commands/accountProvisioner.ts +++ b/server/commands/accountProvisioner.ts @@ -117,6 +117,12 @@ async function accountProvisioner( provider.providerId === authenticationProviderParams.providerId ); + if (!isConnected && !authenticationProviderParams.providerId) { + throw InvalidAuthenticationError( + "A personal account cannot be used to connect a sign-in provider" + ); + } + if (!isConnected && providers.length === 1) { // Update in place so that existing user authentications stay linked. await sequelize.transaction((transaction) =>