Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
address ai review comments
adilsone9bd186768ad
diff --git a/backend/src/server/routes/v1/dashboard-router.ts b/backend/src/server/routes/v1/dashboard-router.tsindex 863a61b43d..d8195907f0 100644--- a/backend/src/server/routes/v1/dashboard-router.ts+++ b/backend/src/server/routes/v1/dashboard-router.ts@@ -1893,7 +1893,9 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {200: z.object({canMove: z.boolean(),folderName: z.string(),- blockingType: z.enum(["dynamic_secret", "secret_rotation", "honey_token", "secret_import"]).optional(),+ blockingType: z+ .enum(["dynamic_secret", "secret_rotation", "honey_token", "secret_import", "secret_approval_policy"])+ .optional(),blockingPath: z.string().optional()})}diff --git a/backend/src/services/secret-folder/secret-folder-service.ts b/backend/src/services/secret-folder/secret-folder-service.tsindex 4b830cb447..2086adfcbf 100644--- a/backend/src/services/secret-folder/secret-folder-service.ts+++ b/backend/src/services/secret-folder/secret-folder-service.ts@@ -1537,6 +1537,34 @@ export const secretFolderServiceFactory = ({return null;};+ const $getFolderMovePolicyBlock = async ({+ projectId,+ environment,+ rootFolderPath,+ subtree+ }: {+ projectId: string;+ environment: string;+ rootFolderPath: string;+ subtree: { path: string }[];+ }) => {+ const toSourceAbsPath = (f: { path: string }) => (f.path === "/" ? rootFolderPath : `${rootFolderPath}${f.path}`);+ const subtreeAbsPaths = subtree.map(toSourceAbsPath);++ const policyByPath = await secretApprovalPolicyService.getSecretApprovalPolicyByPaths(+ projectId,+ environment,+ subtreeAbsPaths+ );++ // report the first blocked path in subtree order, matching the previous per-folder behavior.+ for (const blockedPath of subtreeAbsPaths) {+ const policy = policyByPath.get(blockedPath);+ if (policy) return { blockedPath, policyName: policy.name };+ }+ return null;+ };+// checks whether a folder (and its entire recursive subtree) can be moved.const getFolderMoveEligibility = async ({actor,@@ -1551,7 +1579,21 @@ export const secretFolderServiceFactory = ({const block = await folderDAL.transaction(async (tx) => {// parent folder + full recursive subtree (with paths); reserved folders are already excluded.const subtree = await folderDAL.findByEnvsDeep({ parentIds: [folder.id] }, tx);- return $getFolderMoveBlock(subtree, folder.path, tx);++ const secretBlock = await $getFolderMoveBlock(subtree, folder.path, tx);+ if (secretBlock) return secretBlock;++ const policyBlock = await $getFolderMovePolicyBlock({+ projectId: folder.projectId,+ environment: folder.environment.envSlug,+ rootFolderPath: folder.path,+ subtree+ });+ if (policyBlock) {+ return { blockingType: "secret_approval_policy" as const, blockingPath: policyBlock.blockedPath };+ }++ return null;});return {@@ -1586,6 +1628,13 @@ export const secretFolderServiceFactory = ({const folderName = sourceFolder.name;const sourceParentPath = path.dirname(sourceFolderPath);+ // check if the folder is in the same project+ if (projectId !== sourceFolder.projectId) {+ throw new BadRequestError({+ message: "The provided project ID does not match the source folder's project ID"+ });+ }+// 2. permission: a move is create-at-destination + delete-at-source (secret-level perms are enforced in moveSecrets)const { permission } = await permissionService.getProjectPermission({actor,@@ -1671,23 +1720,17 @@ export const secretFolderServiceFactory = ({const toSourceAbsPath = (f: { path: string }) =>f.path === "/" ? sourceFolderPath : `${sourceFolderPath}${f.path}`;- // block the move if any folder in the source subtree is governed by a secret approval policy. resolve all- // subtree paths in a single batched lookup rather than one query per folder.- const subtreeAbsPaths = subtree.map(toSourceAbsPath);- const policyByPath = await secretApprovalPolicyService.getSecretApprovalPolicyByPaths(+ const policyBlock = await $getFolderMovePolicyBlock({projectId,- sourceEnvironment,- subtreeAbsPaths- );- // report the first blocked path in subtree order, matching the previous per-folder behavior.- for (const blockedPath of subtreeAbsPaths) {- const policy = policyByPath.get(blockedPath);- if (policy) {- throw new BadRequestError({- message: `Cannot move folder '${folderName}'. The folder at path '${blockedPath}' is protected by the secret approval policy '${policy.name}'. Folders governed by a secret approval policy cannot be moved. If you need to move this folder, please disable the secret approval policy for the path '${blockedPath}'`,- name: "MoveFolderProtectedByPolicy"- });- }+ environment: sourceEnvironment,+ rootFolderPath: sourceFolderPath,+ subtree+ });+ if (policyBlock) {+ throw new BadRequestError({+ message: `Cannot move folder '${folderName}'. The folder at path '${policyBlock.blockedPath}' is protected by the secret approval policy '${policyBlock.policyName}'. Folders governed by a secret approval policy cannot be moved. If you need to move this folder, please disable the secret approval policy for the path '${policyBlock.blockedPath}'`,+ name: "MoveFolderProtectedByPolicy"+ });}const subtreeSecrets = await secretV2BridgeDAL.findByFolderIds({ folderIds: subtree.map((f) => f.id), tx });@@ -1801,8 +1844,6 @@ export const secretFolderServiceFactory = ({actorId,actorAuthMethod,actorOrgId,- // the whole subtree was authorized up front, so skip the redundant per-batch check- skipPermissionCheck: true,tx,permissionService,kmsService,diff --git a/backend/src/services/secret-folder/secret-folder-types.ts b/backend/src/services/secret-folder/secret-folder-types.tsindex 3a7ae90a02..cee3be6c3a 100644--- a/backend/src/services/secret-folder/secret-folder-types.ts+++ b/backend/src/services/secret-folder/secret-folder-types.ts@@ -56,7 +56,12 @@ export type TGetFolderByIdDTO = {id: string;} & Omit<TProjectPermission, "projectId">;-export type TFolderMoveBlockingType = "dynamic_secret" | "secret_rotation" | "honey_token" | "secret_import";+export type TFolderMoveBlockingType =+ | "dynamic_secret"+ | "secret_rotation"+ | "honey_token"+ | "secret_import"+ | "secret_approval_policy";export type TFolderMoveEligibility = {canMove: boolean;diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.tsindex 51cc3fc2b9..240e27813a 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-fns.ts@@ -1480,8 +1480,7 @@ export const createRelativeImportExpander = ({// moves a batch of secrets from one folder to another inside the caller-supplied transaction.// performs the two-step move (create/update at destination, then delete at source) plus reference// updates, but does NOT snapshot/sync/invalidate the cache — the caller runs those after the tx-// commits. permission authorization is skipped entirely when skipPermissionCheck is set (the caller-// has already authorized the move at the path level).+// commits.export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveResult> => {const {projectId,@@ -1495,7 +1494,6 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveResactorId,actorOrgId,permission,- skipPermissionCheck,tx,kmsService,folderDAL,@@ -1562,9 +1560,6 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveResthrow new BadRequestError({ message: `Cannot move honey token secret: ${secret.key}` });}- // the caller (e.g. folder move) has already pre-authorized the move at the path level- if (skipPermissionCheck) return;-for (const sourceAction of sourceActions) {if (sourceAction === ProjectPermissionSecretActions.DescribeSecret ||@@ -1678,22 +1673,19 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveRes}// permission check whether can create or edit the ones in the destination folder- // (skipped when the caller has already pre-authorized the move at the path level)- if (!skipPermissionCheck) {- locallyCreatedSecrets.forEach((secret) => {- for (const destinationAction of destinationActions) {- ForbiddenError.from(permission).throwUnlessCan(- destinationAction,- subject(ProjectPermissionSub.Secrets, {- environment: destinationEnvironment,- secretPath: destinationFolder.path,- secretName: secret.key,- secretTags: secret.tags.map((el) => el.slug)- })- );- }- });- }+ locallyCreatedSecrets.forEach((secret) => {+ for (const destinationAction of destinationActions) {+ ForbiddenError.from(permission).throwUnlessCan(+ destinationAction,+ subject(ProjectPermissionSub.Secrets, {+ environment: destinationEnvironment,+ secretPath: destinationFolder.path,+ secretName: secret.key,+ secretTags: secret.tags.map((el) => el.slug)+ })+ );+ }+ });const destinationFolderPolicy = await secretApprovalPolicyService.getSecretApprovalPolicy(projectId,@@ -1979,8 +1971,7 @@ export const fnSecretMove = async (dto: TFnSecretMove): Promise<TFnSecretMoveRes// performs the move within a caller-supplied transaction and returns the result without side effects.// external callers (e.g. folder move) use this to run several moves inside one transaction, then call-// dispatchSecretMoveSideEffects + invalidateSecretCacheByProjectId afterwards. the project-permission-// lookup still runs; per-secret authorization is skipped when skipPermissionCheck is set.+// dispatchSecretMoveSideEffects + invalidateSecretCacheByProjectId afterwards.export const fnSecretMoveInTransaction = async (dto: TFnSecretMoveInTransaction): Promise<TFnSecretMoveResult> => {const { actorAuthMethod, permissionService, ...fnSecretMoveDTO } = dto;diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.tsindex 8e84dc86bf..551fa38eab 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-types.ts@@ -279,8 +279,6 @@ export type TFnSecretMove = {actorId: string;actorOrgId: string;permission: MongoAbility<ProjectPermissionSet>;- // when true the per-secret source/destination authorization is skipped (the caller pre-authorized the move)- skipPermissionCheck?: boolean;tx: Knex;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath" | "findSecretPathByFolderIds">;@@ -432,7 +430,6 @@ export type TMoveSecretsDTO = {destinationSecretPath: string;secretIds: string[];shouldOverwrite: boolean;- skipPermissionCheck?: boolean;} & Omit<TProjectPermission, "projectId">;export type TDuplicateSecretAttributes = {diff --git a/backend/src/services/secret/secret-service.ts b/backend/src/services/secret/secret-service.tsindex 200157eb1e..749900d85a 100644--- a/backend/src/services/secret/secret-service.ts+++ b/backend/src/services/secret/secret-service.ts@@ -2983,8 +2983,7 @@ export const secretServiceFactory = ({actorId,actorAuthMethod,actorOrgId,- projectId: inputProjectId,- skipPermissionCheck+ projectId: inputProjectId}: TMoveSecretsDTO) => {let project;if (projectSlug) {@@ -3014,8 +3013,7 @@ export const secretServiceFactory = ({actor,actorId,actorAuthMethod,- actorOrgId,- skipPermissionCheck+ actorOrgId});}@@ -3068,15 +3066,13 @@ export const secretServiceFactory = ({}// a move is delete-at-source + create/edit-at-destination. this is path-scoped, so it is checked- // once for the whole batch rather than per secret (skipped when the caller has pre-authorized).- if (!skipPermissionCheck) {- validateSecretMovePermissions(permission, {- sourceEnvironment,- sourceSecretPath,- destinationEnvironment,- destinationSecretPath- });- }+ // once for the whole batch rather than per secret.+ validateSecretMovePermissions(permission, {+ sourceEnvironment,+ sourceSecretPath,+ destinationEnvironment,+ destinationSecretPath+ });const decryptedSourceSecrets = sourceSecrets.map((secret) => ({...secret,diff --git a/backend/src/services/secret/secret-types.ts b/backend/src/services/secret/secret-types.tsindex b6b829656d..10b157cc26 100644--- a/backend/src/services/secret/secret-types.ts+++ b/backend/src/services/secret/secret-types.ts@@ -562,7 +562,6 @@ export type TMoveSecretsDTO = {destinationSecretPath: string;secretIds: string[];shouldOverwrite: boolean;- skipPermissionCheck?: boolean;} & Omit<TProjectPermission, "projectId">;export enum SecretProtectionType {