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): re-authorize a recursive sync on every update
Calvinf169647d1952
diff --git a/backend/e2e-test/routes/v1/secret-sync-recursive-permissions.spec.ts b/backend/e2e-test/routes/v1/secret-sync-recursive-permissions.spec.tsindex 48d0b61ec5..243059cf10 100644--- a/backend/e2e-test/routes/v1/secret-sync-recursive-permissions.spec.ts+++ b/backend/e2e-test/routes/v1/secret-sync-recursive-permissions.spec.ts@@ -215,6 +215,37 @@ describe("A secret sync is refused when it would read a folder the actor cannot"expect(secretSync).toEqual(expect.objectContaining({ name: "non-recursive-allowed" }));});+ test("repointing an existing recursive sync at another destination is refused", async () => {+ // The admin can read the whole subtree, so this sync is legitimate at the moment it is made.+ // The Manage grant then gives the actor Edit on it, scoped to "/backend", while leaving+ // "/backend/api" denied. Without a check on this path the actor sends the denied folder to a+ // destination of their choosing without ever touching the sync's source.+ const { secretSync } = await createSecretSync({+ name: "recursive-created-by-admin",+ projectId,+ connectionId,+ environmentSlug: ENV,+ secretPath: "/backend",+ region: REGION,+ destinationPath: "/recursive-created-by-admin/",+ initialSyncBehavior: SecretSyncInitialSyncBehavior.OverwriteDestination,+ recursive: true,+ isAutoSyncEnabled: false,+ authToken: jwtAuthToken+ });+ createdSyncIds.push(secretSync!.id);++ const res = await testServer.inject({+ method: "PATCH",+ url: `/api/v1/secret-syncs/aws-parameter-store/${secretSync!.id}`,+ headers: { authorization: `Bearer ${actorJwt}` },+ body: { destinationConfig: { region: REGION, path: "/actor-controlled/" } }+ });++ expect(res.statusCode).toBe(403);+ expect(res.json().message).toContain("/backend/api");+ });+test("turning subfolders on for an existing sync is refused", async () => {const { secretSync } = await newSync({ name: "recursive-turned-on-later", recursive: false });diff --git a/backend/src/services/secret-sync/secret-sync-service.ts b/backend/src/services/secret-sync/secret-sync-service.tsindex be35d8d1d4..cfab649988 100644--- a/backend/src/services/secret-sync/secret-sync-service.ts+++ b/backend/src/services/secret-sync/secret-sync-service.ts@@ -164,7 +164,9 @@ export const secretSyncServiceFactory = ({secretPath: path});- } catch {+ } catch (error) {+ if (!(error instanceof ForbiddenError)) throw error;+throw new ForbiddenRequestError({message:path === sourcePath@@ -672,7 +674,11 @@ export const secretSyncServiceFactory = ({const wasRecursive = Boolean((secretSync.syncOptions as { recursive?: boolean } | undefined)?.recursive);const isRecursive = Boolean((params.syncOptions as { recursive?: boolean } | undefined)?.recursive ?? wasRecursive);- if (isSourceChanged || (isRecursive && !wasRecursive)) {+ // Every update to a recursive sync re-authorizes the whole subtree, because an actor holding+ // Edit on the source folder can otherwise repoint an existing recursive sync at a destination+ // they control and read descendants they were never granted. A non-recursive sync covers only+ // its source folder, so it re-authorizes when that source actually changes.+ if (isSourceChanged || isRecursive) {const updatedEnvironment = environment ?? secretSync.environment?.slug;const updatedSecretPath = secretPath ?? secretSync.folder?.path;