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
fix(secret-sync): check each landing path and refetch syncs before warning
Calvin9bbfdd4e7fac
diff --git a/frontend/src/components/secret-syncs/SecretSyncMoveWarning.tsx b/frontend/src/components/secret-syncs/SecretSyncMoveWarning.tsxindex baca4993d0..2455fcb3cd 100644--- a/frontend/src/components/secret-syncs/SecretSyncMoveWarning.tsx+++ b/frontend/src/components/secret-syncs/SecretSyncMoveWarning.tsx@@ -24,25 +24,32 @@ export const useSecretSyncMoveWarning = (projectId: string, checks: TMoveWarning);const isEnabled = canReadSecretSyncs && checks.length > 0;- // never served from cache, so a sync created since the list was last loaded is not missedconst {data: projectSyncs,- isLoading,- isError+ isFetching,+ isError,+ refetch} = useListSecretSyncs(projectId, {enabled: isEnabled,staleTime: 0});+ // a cached list may predate a sync created since, so the list is refetched whenever the checks change+ // and submit stays blocked until it lands+ const checksKey = JSON.stringify(checks);+ useEffect(() => {+ if (isEnabled) refetch({ cancelRefetch: false });+ }, [checksKey, isEnabled]);+const secretSyncs = useMemo(() => (isEnabled && projectSyncs ? getSecretSyncsNewlyCoveringPaths(projectSyncs, checks) : []),[isEnabled, projectSyncs, checks]);- const isChecking = isEnabled && isLoading;+ const isChecking = isEnabled && isFetching;const hasError = isEnabled && isError;const warningKey = JSON.stringify({- checks,+ checksKey,syncIds: secretSyncs.map(({ id }) => id),hasError});diff --git a/frontend/src/helpers/secretSyncCoverage.test.ts b/frontend/src/helpers/secretSyncCoverage.test.tsindex ed8cb7e51a..1f2f3777d0 100644--- a/frontend/src/helpers/secretSyncCoverage.test.ts+++ b/frontend/src/helpers/secretSyncCoverage.test.ts@@ -1,10 +1,6 @@import { describe, expect, test } from "vitest";-import {- getSecretSyncsNewlyCoveringPaths,- isPathCoveredBySecretSync,- isPathOrDescendantCoveredBySecretSync-} from "./secretSyncCoverage";+import { getSecretSyncsNewlyCoveringPaths, isPathCoveredBySecretSync } from "./secretSyncCoverage";describe("isPathCoveredBySecretSync", () => {const sync = (path: string, includeAllSubFolders?: boolean, environment = "dev") => ({@@ -58,34 +54,6 @@ describe("isPathCoveredBySecretSync", () => {});});-describe("isPathOrDescendantCoveredBySecretSync", () => {- const sync = (path: string, includeAllSubFolders = false, environment = "dev") => ({- environment: { slug: environment },- folder: { path },- syncOptions: { includeAllSubFolders }- });-- const covers = (entry: ReturnType<typeof sync>, secretPath: string, environment = "dev") =>- isPathOrDescendantCoveredBySecretSync(entry, { environment, secretPath });-- test("covers whatever the path itself is covered by", () => {- expect(covers(sync("/apps"), "/apps")).toBe(true);- expect(covers(sync("/", true), "/apps")).toBe(true);- });-- test("covers a sync rooted anywhere beneath the path, recursive or not", () => {- expect(covers(sync("/apps/payments"), "/apps")).toBe(true);- expect(covers(sync("/apps/payments/api", true), "/apps")).toBe(true);- expect(covers(sync("/apps"), "/")).toBe(true);- });-- test("never covers a non-recursive ancestor, a sibling, or another environment", () => {- expect(covers(sync("/"), "/apps")).toBe(false);- expect(covers(sync("/apps-legacy/api"), "/apps")).toBe(false);- expect(covers(sync("/apps/payments", false, "prod"), "/apps")).toBe(false);- });-});-describe("getSecretSyncsNewlyCoveringPaths", () => {const sync = (id: string, overrides: Record<string, unknown> = {}) => ({id,@@ -118,6 +86,13 @@ describe("getSecretSyncsNewlyCoveringPaths", () => {expect(getSecretSyncsNewlyCoveringPaths([sync("a")], [])).toEqual([]);});+ test("leaves out a sync rooted beneath the landing path", () => {+ const syncs = [sync("nested", { folder: { path: "/apps/other" } })];++ expect(getSecretSyncsNewlyCoveringPaths(syncs, [check("/x", "/apps")])).toEqual([]);+ expect(getSecretSyncsNewlyCoveringPaths(syncs, [check("/x", "/")])).toEqual([]);+ });+test("returns a sync once even when several checks land under it", () => {const checks = [check("/x", "/apps"), { ...check("/y", "/apps"), sourceEnvironment: "prod" }];diff --git a/frontend/src/helpers/secretSyncCoverage.ts b/frontend/src/helpers/secretSyncCoverage.tsindex 1a0614c175..1679f6d4de 100644--- a/frontend/src/helpers/secretSyncCoverage.ts+++ b/frontend/src/helpers/secretSyncCoverage.ts@@ -37,25 +37,9 @@ export const isPathCoveredBySecretSync = ();};-// A move or copy can land items anywhere beneath its destination, so a sync rooted below the destination-// counts as well as one covering it. This can warn about a sync that nothing ends up under, which is-// safer for a warning than missing one.-export const isPathOrDescendantCoveredBySecretSync = (- sync: TCoverageSync,- { environment, secretPath }: { environment: string; secretPath: string }-) => {- if (isPathCoveredBySecretSync(sync, { environment, secretPath })) return true;- if (!sync.folder || sync.environment?.slug !== environment) return false;-- const syncSegments = toPathSegments(sync.folder.path);- const pathSegments = toPathSegments(secretPath);-- return pathSegments.every((segment, index) => syncSegments[index] === segment);-};-// The syncs that would start sending items to their destination if they were moved or copied as the checks-// describe. A sync that already covers a check's source is left out for that check, since the items-// already reach it.+// describe, one check per path the items land at. A sync that already covers a check's source is left out+// for that check, since the items already reach it.export const getSecretSyncsNewlyCoveringPaths = <T extends TCoverageSync & { id: string; name: string }>(@@ -66,7 +50,7 @@ export const getSecretSyncsNewlyCoveringPaths = <.filter((sync) =>checks.some((check) =>- isPathOrDescendantCoveredBySecretSync(sync, {+ isPathCoveredBySecretSync(sync, {environment: check.destinationEnvironment,secretPath: check.destinationSecretPath}) &&diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsxindex 5e119422e8..b5d13d4ff5 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx@@ -202,16 +202,13 @@ const CopySecretsSession = ({sourceEnvironmentSlug &&destinationEnvironmentSlug &&isSourcePathSettled &&- isDestinationPathSettled &&- (requestGroups.length || selectedFolderPaths.length)- ? [- {- sourceEnvironment: sourceEnvironmentSlug,- sourceSecretPath: normalizedSourcePath,- destinationEnvironment: destinationEnvironmentSlug,- destinationSecretPath: normalizedDestinationPath- }- ]+ isDestinationPathSettled+ ? requestGroups.map((group) => ({+ sourceEnvironment: sourceEnvironmentSlug,+ sourceSecretPath: group.sourcePath,+ destinationEnvironment: destinationEnvironmentSlug,+ destinationSecretPath: group.destinationPath+ })): []);const destinationFolderPaths = getCopyDestinationFolderPaths({diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsxindex d47413d758..2e10bc92c6 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx@@ -545,8 +545,8 @@ const buildDestinationTargets = ({return { checks: isSelfMove ? [] : checks, isSelfMove };};-// one check per environment pair that has something to move. syncs beneath the destination count too,-// so a moved folder needs no check of its own.+// one check per path the items land at. a moved folder always lands at a new path (the backend rejects a+// name clash), so only recursive syncs above it can cover it or anything inside it.const buildMoveWarningChecks = ({sourceSecretPath,destinationPath,@@ -560,19 +560,20 @@ const buildMoveWarningChecks = ({}): TMoveWarningsCheck[] => {if (!destinationPath) return [];- const environmentPairs = new Map(- [...secretEnvironments, ...movedFolders].map(({ sourceEnv, destinationEnvironment }) => [- `${sourceEnv}:${destinationEnvironment}`,- { sourceEnv, destinationEnvironment }- ])- );-- return [...environmentPairs.values()].map(({ sourceEnv, destinationEnvironment }) => ({+ const secretChecks = secretEnvironments.map(({ sourceEnv, destinationEnvironment }) => ({sourceEnvironment: sourceEnv,sourceSecretPath: removeTrailingSlash(sourceSecretPath),destinationEnvironment,destinationSecretPath: removeTrailingSlash(destinationPath)}));+ const folderChecks = movedFolders.map(({ folderName, sourceEnv, destinationEnvironment }) => ({+ sourceEnvironment: sourceEnv,+ sourceSecretPath: `${removeTrailingSlash(sourceSecretPath)}/${folderName}`,+ destinationEnvironment,+ destinationSecretPath: `${removeTrailingSlash(destinationPath)}/${folderName}`+ }));++ return [...secretChecks, ...folderChecks];};// memoizes the destination checks for the moved folders and runs the destination approval-policy eligibility