From d734a3f6f4ec30025b532725351f43c71724b58e Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:15:42 +0200 Subject: [PATCH 1/4] Fix: Add hard recursion limit to documentation --- backend/src/lib/api-docs/constants.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts index 90098a7b6..b9325ed28 100644 --- a/backend/src/lib/api-docs/constants.ts +++ b/backend/src/lib/api-docs/constants.ts @@ -221,7 +221,8 @@ export const SECRETS = { export const RAW_SECRETS = { LIST: { - recursive: "Whether or not to fetch all secrets from the specified base path, and all of its subdirectories.", + recursive: + "Whether or not to fetch all secrets from the specified base path, and all of its subdirectories. Note, the max depth is 20 deep.", workspaceId: "The ID of the project to list secrets from.", workspaceSlug: "The slug of the project to list secrets from. This parameter is only usable by machine identities.", environment: "The slug of the environment to list secrets from.", From 75267987fce621d2f295540d5193451a345b6405 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:28:03 +0200 Subject: [PATCH 2/4] Fix: Add recursive search max depth (20) --- backend/src/services/secret/secret-fns.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/src/services/secret/secret-fns.ts b/backend/src/services/secret/secret-fns.ts index 24c2bd811..edd656b55 100644 --- a/backend/src/services/secret/secret-fns.ts +++ b/backend/src/services/secret/secret-fns.ts @@ -92,7 +92,8 @@ const buildHierarchy = (folders: TSecretFolders[]): FolderMap => { const generatePaths = ( map: FolderMap, parentId: string = "null", - basePath: string = "" + basePath: string = "", + currentDepth: number = 0 ): { path: string; folderId: string }[] => { const children = map[parentId || "null"] || []; let paths: { path: string; folderId: string }[] = []; @@ -105,13 +106,19 @@ const generatePaths = ( // eslint-disable-next-line no-nested-ternary const currPath = basePath === "" ? (isRootFolder ? "/" : `/${child.name}`) : `${basePath}/${child.name}`; + // Add the current path paths.push({ path: currPath, folderId: child.id - }); // Add the current path + }); - // Recursively generate paths for children, passing down the formatted pathh - const childPaths = generatePaths(map, child.id, currPath); + // We make sure that the max depth doesn't exceed 20. + // We do this to make as a "circuit break", basically to ensure that we can't encounter any potential memory leaks. + if (currentDepth >= 20) { + return; + } + // Recursively generate paths for children, passing down the formatted path + const childPaths = generatePaths(map, child.id, currPath, currentDepth + 1); paths = paths.concat( childPaths.map((p) => ({ path: p.path, From 702cd0d403f4f4af4e46d8b8bf323083ce503723 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:31:48 +0200 Subject: [PATCH 3/4] Update secret-fns.ts --- backend/src/services/secret/secret-fns.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/services/secret/secret-fns.ts b/backend/src/services/secret/secret-fns.ts index edd656b55..5f0c445ba 100644 --- a/backend/src/services/secret/secret-fns.ts +++ b/backend/src/services/secret/secret-fns.ts @@ -112,8 +112,8 @@ const generatePaths = ( folderId: child.id }); - // We make sure that the max depth doesn't exceed 20. - // We do this to make as a "circuit break", basically to ensure that we can't encounter any potential memory leaks. + // We make sure that the recursion depth doesn't exceed 20. + // We do this to create "circuit break", basically to ensure that we can't encounter any potential memory leaks. if (currentDepth >= 20) { return; } From 1c90df9dd4be54a99a1e74885a69576f6c4589bb Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Fri, 12 Apr 2024 10:34:59 -0400 Subject: [PATCH 4/4] add log for secrets depth breakout --- backend/src/services/secret/secret-fns.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/services/secret/secret-fns.ts b/backend/src/services/secret/secret-fns.ts index 5f0c445ba..2bfda2cbe 100644 --- a/backend/src/services/secret/secret-fns.ts +++ b/backend/src/services/secret/secret-fns.ts @@ -21,6 +21,7 @@ import { } from "@app/lib/crypto"; import { BadRequestError } from "@app/lib/errors"; import { groupBy, unique } from "@app/lib/fn"; +import { logger } from "@app/lib/logger"; import { ActorAuthMethod, ActorType } from "../auth/auth-type"; import { getBotKeyFnFactory } from "../project-bot/project-bot-fns"; @@ -115,6 +116,7 @@ const generatePaths = ( // We make sure that the recursion depth doesn't exceed 20. // We do this to create "circuit break", basically to ensure that we can't encounter any potential memory leaks. if (currentDepth >= 20) { + logger.info(`generatePaths: Recursion depth exceeded 20, breaking out of recursion [map=${JSON.stringify(map)}]`); return; } // Recursively generate paths for children, passing down the formatted path