From 6426b85c1e973d64589278b6a05e6c4a8689df02 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Fri, 14 Mar 2025 21:16:42 -0400 Subject: [PATCH] Upgrade passport/saml to 5.0 This addresses the breaking changes in 5.0 listed here https://github.com/node-saml/node-saml/blob/v5.0.0/CHANGELOG.md#-major-changes Todo: test with existing saml workflow --- backend/src/ee/routes/v1/saml-router.ts | 46 ++++++++++++------- .../saml-config/saml-config-service.ts | 12 ++--- .../services/saml-config/saml-config-types.ts | 4 +- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/backend/src/ee/routes/v1/saml-router.ts b/backend/src/ee/routes/v1/saml-router.ts index 71facb22a..184bdc817 100644 --- a/backend/src/ee/routes/v1/saml-router.ts +++ b/backend/src/ee/routes/v1/saml-router.ts @@ -22,7 +22,7 @@ import { SanitizedSamlConfigSchema } from "@app/server/routes/sanitizedSchema/di import { AuthMode } from "@app/services/auth/auth-type"; type TSAMLConfig = { - callbackUrl: string; + callbackUrl: string; entryPoint: string; issuer: string; cert: string; @@ -302,15 +302,21 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => { } }, handler: async (req) => { - const saml = await server.services.saml.createSamlCfg({ - actor: req.permission.type, - actorId: req.permission.id, - actorAuthMethod: req.permission.authMethod, - actorOrgId: req.permission.orgId, - orgId: req.body.organizationId, - ...req.body + const { isActive, authProvider, issuer, entryPoint, cert } = req.body; + const { permission } = req; + + return server.services.saml.createSamlCfg({ + isActive, + authProvider, + issuer, + entryPoint, + idpCert: cert, + actor: permission.type, + actorId: permission.id, + actorAuthMethod: permission.authMethod, + actorOrgId: permission.orgId, + orgId: req.body.organizationId }); - return saml; } }); @@ -337,15 +343,21 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => { } }, handler: async (req) => { - const saml = await server.services.saml.updateSamlCfg({ - actor: req.permission.type, - actorId: req.permission.id, - actorAuthMethod: req.permission.authMethod, - actorOrgId: req.permission.orgId, - orgId: req.body.organizationId, - ...req.body + const { isActive, authProvider, issuer, entryPoint, cert } = req.body; + const { permission } = req; + + return server.services.saml.updateSamlCfg({ + isActive, + authProvider, + issuer, + entryPoint, + idpCert: cert, + actor: permission.type, + actorId: permission.id, + actorAuthMethod: permission.authMethod, + actorOrgId: permission.orgId, + orgId: req.body.organizationId }); - return saml; } }); }; diff --git a/backend/src/ee/services/saml-config/saml-config-service.ts b/backend/src/ee/services/saml-config/saml-config-service.ts index f22e2ad58..601347862 100644 --- a/backend/src/ee/services/saml-config/saml-config-service.ts +++ b/backend/src/ee/services/saml-config/saml-config-service.ts @@ -63,7 +63,7 @@ export const samlConfigServiceFactory = ({ kmsService }: TSamlConfigServiceFactoryDep) => { const createSamlCfg = async ({ - cert, + idpCert, actor, actorAuthMethod, actorOrgId, @@ -93,9 +93,9 @@ export const samlConfigServiceFactory = ({ orgId, authProvider, isActive, - encryptedSamlIssuer: encryptor({ plainText: Buffer.from(issuer) }).cipherTextBlob, + encryptedSamlCertificate: encryptor({ plainText: Buffer.from(idpCert) }).cipherTextBlob, encryptedSamlEntryPoint: encryptor({ plainText: Buffer.from(entryPoint) }).cipherTextBlob, - encryptedSamlCertificate: encryptor({ plainText: Buffer.from(cert) }).cipherTextBlob + encryptedSamlIssuer: encryptor({ plainText: Buffer.from(issuer) }).cipherTextBlob }); return samlConfig; @@ -106,7 +106,7 @@ export const samlConfigServiceFactory = ({ actor, actorOrgId, actorAuthMethod, - cert, + idpCert, actorId, issuer, isActive, @@ -136,8 +136,8 @@ export const samlConfigServiceFactory = ({ updateQuery.encryptedSamlIssuer = encryptor({ plainText: Buffer.from(issuer) }).cipherTextBlob; } - if (cert !== undefined) { - updateQuery.encryptedSamlCertificate = encryptor({ plainText: Buffer.from(cert) }).cipherTextBlob; + if (idpCert !== undefined) { + updateQuery.encryptedSamlCertificate = encryptor({ plainText: Buffer.from(idpCert) }).cipherTextBlob; } const [ssoConfig] = await samlConfigDAL.update({ orgId }, updateQuery); diff --git a/backend/src/ee/services/saml-config/saml-config-types.ts b/backend/src/ee/services/saml-config/saml-config-types.ts index 03db4cfa1..444839a21 100644 --- a/backend/src/ee/services/saml-config/saml-config-types.ts +++ b/backend/src/ee/services/saml-config/saml-config-types.ts @@ -15,7 +15,7 @@ export type TCreateSamlCfgDTO = { isActive: boolean; entryPoint: string; issuer: string; - cert: string; + idpCert: string; } & TOrgPermission; export type TUpdateSamlCfgDTO = Partial<{ @@ -23,7 +23,7 @@ export type TUpdateSamlCfgDTO = Partial<{ isActive: boolean; entryPoint: string; issuer: string; - cert: string; + idpCert: string; }> & TOrgPermission;