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
improvement: only return true for secret_approval_policy and fix types
adilson132bc9b8c236
diff --git a/backend/src/services/secret-folder/secret-folder-fns.ts b/backend/src/services/secret-folder/secret-folder-fns.tsindex 62521f70a5..cb29479c74 100644--- a/backend/src/services/secret-folder/secret-folder-fns.ts+++ b/backend/src/services/secret-folder/secret-folder-fns.ts@@ -102,11 +102,11 @@ export const resolveClosestFolder = (// read permission used to decide whether an actor is allowed to learn that a given blocking resource// exists at a folder path. used to avoid disclosing subtree contents (e.g. honey tokens) to actors-// without access while still scanning the full subtree to enforce move correctness. a `null` entry means-// the block is not gated by any permission (the folder path is universally readable).+// without access while still scanning the full subtree to enforce move correctness. every blocking type+// except secret_approval_policy (handled explicitly in canActorReadBlock) must have an entry here.const FOLDER_MOVE_BLOCK_PERMISSION: Record<- TFolderMoveBlockingType,- { action: string; subject: ProjectPermissionSub } | null+ Exclude<TFolderMoveBlockingType, "secret_approval_policy">,+ { action: string; subject: ProjectPermissionSub }> = {secret_import: { action: ProjectPermissionActions.Read, subject: ProjectPermissionSub.SecretImports },dynamic_secret: {@@ -117,10 +117,7 @@ const FOLDER_MOVE_BLOCK_PERMISSION: Record<secret_rotation: {action: ProjectPermissionSecretRotationActions.Read,subject: ProjectPermissionSub.SecretRotation- },- // an approval policy blocks at a folder path, and folder read is implied-for-all (folder list/get is not- // gated by a Read permission), so its existence is not disclosure-gated on a Read-on-SecretFolders proxy.- secret_approval_policy: null+ }};// when set, the move-block scan only reports blocks at paths the actor is allowed to read, so it cannot@@ -148,9 +145,17 @@ export const canActorReadBlock = (blockingType: TFolderMoveBlockingType,secretPath: string) => {+ // an approval policy blocks at a folder path, and folder read is implied-for-all (folder list/get is not+ // gated by a Read permission), so its existence is not disclosure-gated on a Read-on-SecretFolders proxy.+ if (blockingType === "secret_approval_policy") return true;+const blockPermission = FOLDER_MOVE_BLOCK_PERMISSION[blockingType];- // no gating permission (e.g. approval policy at a universally-readable folder path): always readable.- if (!blockPermission) return true;+ if (!blockPermission) {+ throw new InternalServerError({+ message: `Unhandled folder move blocking type: ${blockingType}`+ });+ }+const { action, subject: sub } = blockPermission;return (permission as MongoAbility).can(action, subject(sub, { environment, secretPath }));};@@ -250,26 +255,18 @@ export const checkFolderMovePolicyBlock = async (subtree,projectId,environment,- rootFolderPath,- accessScope+ rootFolderPath}: {subtree: { id: string; path: string }[];projectId: string;environment: string;rootFolderPath: string;- accessScope?: TFolderMoveAccessScope;},{ secretApprovalPolicyService }: TCheckFolderMovePolicyBlockDeps): Promise<TFolderMoveBlock | null> => {const toAbsPath = buildToAbsPath(rootFolderPath);- let subtreeAbsPaths = subtree.map((f) => toAbsPath(f.path));- // only consider paths the actor is allowed to read, so policy presence at inaccessible paths isn't disclosed.- if (accessScope) {- subtreeAbsPaths = subtreeAbsPaths.filter((secretPath) =>- canActorReadBlock(accessScope.permission, accessScope.environment, "secret_approval_policy", secretPath)- );- }+ const subtreeAbsPaths = subtree.map((f) => toAbsPath(f.path));const policyByPath = await secretApprovalPolicyService.getSecretApprovalPolicyByPaths(projectId,diff --git a/backend/src/services/secret-folder/secret-folder-service.ts b/backend/src/services/secret-folder/secret-folder-service.tsindex ddda5b0bf3..b5d7228bea 100644--- a/backend/src/services/secret-folder/secret-folder-service.ts+++ b/backend/src/services/secret-folder/secret-folder-service.ts@@ -1548,7 +1548,7 @@ export const secretFolderServiceFactory = ({tx);const sourcePolicyBlock = await checkFolderMovePolicyBlock(- { subtree, projectId, environment: sourceEnvironment, rootFolderPath: sourceFolderPath, accessScope },+ { subtree, projectId, environment: sourceEnvironment, rootFolderPath: sourceFolderPath },folderMoveBlockDeps);const sourceBlock = secretTypeBlock ?? sourcePolicyBlock;