From 70985e900b267b3c297fec74525274ae3ad5f626 Mon Sep 17 00:00:00 2001 From: Samuel Bodin <1637651+bodinsamuel@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:58:16 +0100 Subject: [PATCH] fix(auth): reup connectionId check (#3413) ## Changes Fixes https://linear.app/nango/issue/NAN-2558/re-up-connectionid-check - Reup connectionId check This was reverted when a customer did something forbidden in prod (sending a hardcoded connectionId with sessionConnect) and just wanted them to fix the issue before re-upping that. --- .../server/lib/controllers/auth/postApiKey.ts | 10 +++++----- .../lib/controllers/auth/postAppStore.ts | 10 +++++----- .../server/lib/controllers/auth/postBasic.ts | 10 +++++----- .../server/lib/controllers/auth/postBill.ts | 10 +++++----- .../server/lib/controllers/auth/postJwt.ts | 10 +++++----- .../lib/controllers/auth/postSignature.ts | 10 +++++----- .../server/lib/controllers/auth/postTableau.ts | 10 +++++----- .../server/lib/controllers/auth/postTba.ts | 10 +++++----- .../server/lib/controllers/auth/postTwoStep.ts | 10 +++++----- .../postUnauthenticated.integration.test.ts | 2 +- .../controllers/auth/postUnauthenticated.ts | 10 +++++----- .../server/lib/controllers/oauth.controller.ts | 18 +++++++++--------- 12 files changed, 60 insertions(+), 60 deletions(-) diff --git a/packages/server/lib/controllers/auth/postApiKey.ts b/packages/server/lib/controllers/auth/postApiKey.ts index 8be767f0740..a35382cf0b2 100644 --- a/packages/server/lib/controllers/auth/postApiKey.ts +++ b/packages/server/lib/controllers/auth/postApiKey.ts @@ -21,7 +21,7 @@ import { hmacCheck } from '../../utils/hmac.js'; import { connectionCreated as connectionCreatedHook, connectionCreationFailed as connectionCreationFailedHook, connectionTest } from '../../hooks/hooks.js'; import { connectionCredential, connectionIdSchema, providerConfigKeySchema } from '../../helpers/validation.js'; import db from '@nangohq/database'; -import { isIntegrationAllowed } from '../../utils/auth.js'; +import { errorRestrictConnectionId, isIntegrationAllowed } from '../../utils/auth.js'; const bodyValidation = z .object({ @@ -76,10 +76,10 @@ export const postPublicApiKeyAuthorization = asyncWrapper { }); }); - it.skip('should not be allowed to pass a connection_id with session token', async () => { + it('should not be allowed to pass a connection_id with session token', async () => { const env = await seeders.createEnvironmentSeed(); const config = await seeders.createConfigSeed(env, 'unauthenticated', 'unauthenticated'); diff --git a/packages/server/lib/controllers/auth/postUnauthenticated.ts b/packages/server/lib/controllers/auth/postUnauthenticated.ts index c2f0022f9ff..d193f53c509 100644 --- a/packages/server/lib/controllers/auth/postUnauthenticated.ts +++ b/packages/server/lib/controllers/auth/postUnauthenticated.ts @@ -10,7 +10,7 @@ import type { LogContext } from '@nangohq/logs'; import { hmacCheck } from '../../utils/hmac.js'; import { connectionCreated, connectionCreationFailed } from '../../hooks/hooks.js'; import db from '@nangohq/database'; -import { isIntegrationAllowed } from '../../utils/auth.js'; +import { errorRestrictConnectionId, isIntegrationAllowed } from '../../utils/auth.js'; const queryStringValidation = z .object({ @@ -51,10 +51,10 @@ export const postPublicUnauthenticated = asyncWrapper>, _next: NextFunction) { @@ -65,10 +65,10 @@ class OAuthController { let userScope = req.query['user_scope'] as string | undefined; const isConnectSession = res.locals['authType'] === 'connectSession'; - // if (isConnectSession && receivedConnectionId) { - // errorRestrictConnectionId(res); - // return; - // } + if (isConnectSession && receivedConnectionId) { + errorRestrictConnectionId(res); + return; + } let logCtx: LogContext | undefined; @@ -309,10 +309,10 @@ class OAuthController { const { client_id, client_secret }: Record = body; - // if (isConnectSession && receivedConnectionId) { - // errorRestrictConnectionId(res); - // return; - // } + if (isConnectSession && receivedConnectionId) { + errorRestrictConnectionId(res); + return; + } let logCtx: LogContext | undefined;