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
Update secret-v2-bridge-service.ts
Daniel Hougaard9984fa41ca3c
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.tsindex 88e90c493d..70cc5131de 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts@@ -1404,13 +1404,42 @@ export const secretV2BridgeServiceFactory = ({const secretImports = await secretImportDAL.findByFolderIds(paths.map((p) => p.folderId));const allowedImports = secretImports.filter(({ isReplication }) => !isReplication);++ const mainPathFolderId = paths.find((p) => p.path === path)?.folderId;+ const currentEnvSecretsForImportRefs = mainPathFolderId+ ? await secretDAL.findByFolderIds({ folderIds: [mainPathFolderId] })+ : [];+ const currentEnvSecretKeys = new Set(currentEnvSecretsForImportRefs.map((s) => s.key));++ // for imported secrets local references (${KEY}): resolve against the current environment first. if the key doesn't exist in the current environment the reference falls back to the source import environment.+ // nested references (${env.folder.KEY}): they always resolve via their absolute path+ const expandImportedSecretReferences = (inputSecret: Parameters<typeof expandSecretReferences>[number]) => {+ const { localReferences } = getAllSecretReferences(inputSecret.value || "");+ if (!localReferences.length) {+ return expandSecretReferences({ ...inputSecret, environment, secretPath: path });+ }++ // rewrite local refs absent from the current environment into absolute nested refs+ // pointing to the source environment so the existing expander handles the fallback+ let modifiedValue = inputSecret.value || "";+ for (const localRef of localReferences) {+ if (!currentEnvSecretKeys.has(localRef)) {+ const pathParts = inputSecret.secretPath.split("/").filter(Boolean);+ const absoluteRef = `\${${[inputSecret.environment, ...pathParts, localRef].join(".")}}`;+ modifiedValue = modifiedValue.replaceAll(`\${${localRef}}`, absoluteRef);+ }+ }++ return expandSecretReferences({ ...inputSecret, value: modifiedValue, environment, secretPath: path });+ };+const importedSecrets = await fnSecretsV2FromImports({viewSecretValue,secretImports: allowedImports,secretDAL,folderDAL,secretImportDAL,- expandSecretReferences,+ expandSecretReferences: expandImportedSecretReferences,decryptor: (value) => (value ? secretManagerDecryptor({ cipherTextBlob: value }).toString() : ""),hasSecretAccess: (expandEnvironment, expandSecretPath, expandSecretKey, expandSecretTags) => {const canDescribe = hasSecretReadValueOrDescribePermission(