Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

address comments

adilsonbe195e23c979
diff --git a/backend/src/services/secret-sync/netlify/netlify-sync-fns.test.ts b/backend/src/services/secret-sync/netlify/netlify-sync-fns.test.ts
index 164b799b07..78de5126b0 100644
--- a/backend/src/services/secret-sync/netlify/netlify-sync-fns.test.ts
+++ b/backend/src/services/secret-sync/netlify/netlify-sync-fns.test.ts
@@ -44,6 +44,16 @@ describe("NetlifySyncFns.syncSecrets", () => {
getVariables.mockResolvedValue([{ key: "EXISTING", values: [] }]);
});
+ it("fails without retry when listing variables is rejected with 400", async () => {
+ getVariables.mockRejectedValue(axiosErrorWithStatus(400));
+
+ const error = await NetlifySyncFns.syncSecrets(sync, payloadOf(["NEW"])).catch((err: unknown) => err);
+
+ expect(error).toBeInstanceOf(SecretSyncError);
+ expect((error as SecretSyncError).shouldRetry).toBe(false);
+ expect((error as SecretSyncError).secretKey).toBeUndefined();
+ });
+
it("fails without retry when Netlify rejects a new variable with 400", async () => {
createVariable.mockRejectedValue(axiosErrorWithStatus(400));
diff --git a/backend/src/services/secret-sync/netlify/netlify-sync-fns.ts b/backend/src/services/secret-sync/netlify/netlify-sync-fns.ts
index 8899ebcdc0..06f8a09c04 100644
--- a/backend/src/services/secret-sync/netlify/netlify-sync-fns.ts
+++ b/backend/src/services/secret-sync/netlify/netlify-sync-fns.ts
@@ -9,7 +9,7 @@ import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
import { SecretSyncError } from "../secret-sync-errors";
import type { TNetlifySyncWithCredentials } from "./netlify-sync-types";
-const throwNetlifySyncError = (error: unknown, secretKey: string): never => {
+const throwNetlifySyncError = (error: unknown, secretKey?: string): never => {
throw new SecretSyncError({
error,
secretKey,
@@ -18,6 +18,14 @@ const throwNetlifySyncError = (error: unknown, secretKey: string): never => {
});
};
+const getNetlifyVariables = async (...args: Parameters<typeof NetlifyPublicAPI.getVariables>) => {
+ try {
+ return await NetlifyPublicAPI.getVariables(...args);
+ } catch (error) {
+ throwNetlifySyncError(error);
+ }
+};
+
export const NetlifySyncFns = {
async getSecrets(secretSync: TNetlifySyncWithCredentials): Promise<TSecretMap> {
const config = secretSync.destinationConfig;
@@ -28,7 +36,7 @@ export const NetlifySyncFns = {
site_id: config.siteId
};
- const variables = await NetlifyPublicAPI.getVariables(secretSync.connection, params);
+ const variables = await getNetlifyVariables(secretSync.connection, params);
const map = {} as TSecretMap;
@@ -64,7 +72,7 @@ export const NetlifySyncFns = {
context_name: config.context
};
- const variables = await NetlifyPublicAPI.getVariables(secretSync.connection, baseParams);
+ const variables = await getNetlifyVariables(secretSync.connection, baseParams);
const existingInNetlify = Object.fromEntries(variables.map((variable) => [variable.key, variable]));
const variablesToCreate = Object.keys(secretMap).filter((key) => !existingInNetlify[key]);
@@ -140,7 +148,7 @@ export const NetlifySyncFns = {
context_name: config.context
};
- const variables = await NetlifyPublicAPI.getVariables(secretSync.connection, baseParams);
+ const variables = await getNetlifyVariables(secretSync.connection, baseParams);
const existingSecrets = Object.fromEntries(variables.map((variable) => [variable.key, variable]));
diff --git a/backend/src/services/secret-sync/vercel/vercel-sync-fns.test.ts b/backend/src/services/secret-sync/vercel/vercel-sync-fns.test.ts
index 99e8d2b62a..e1c96df6d8 100644
--- a/backend/src/services/secret-sync/vercel/vercel-sync-fns.test.ts
+++ b/backend/src/services/secret-sync/vercel/vercel-sync-fns.test.ts
@@ -60,7 +60,9 @@ describe("Vercel retry error handling", () => {
["seconds", () => "2", 2000],
["an HTTP date", () => new Date(Date.now() + 5000).toUTCString(), 5000],
["more than the cap", () => "3600", 60000],
- ["unparseable", () => "soon", 60000]
+ ["unparseable", () => "soon", 60000],
+ ["zero", () => "0", 3000],
+ ["an already elapsed HTTP date", () => new Date(Date.now() - 5000).toUTCString(), 1000]
])("waits for Retry-After given as %s", async (_, retryAfter, expectedDelayMs) => {
vi.setSystemTime(new Date("2026-01-01T00:00:00Z"));
get
diff --git a/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts b/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts
index f5a0bfda6b..c82f5ee02e 100644
--- a/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts
+++ b/backend/src/services/secret-sync/vercel/vercel-sync-fns.ts
@@ -22,6 +22,7 @@ function isVercelDefaultEnvType(value: string): value is DefaultVercelEnvType {
const MAX_RETRIES = 5;
const RATE_LIMIT_DELAY_MS = 60000;
+const MIN_RATE_LIMIT_DELAY_MS = 3000;
// Vercel answers with these codes when a request can never succeed as sent, so retrying only repeats the
// failure. The message shown to the user is the one Vercel returned.
@@ -33,7 +34,8 @@ const sleep = async (ms: number) =>
setTimeout(resolve, ms);
});
-// Retry-After is either seconds or an HTTP date. It can only shorten the wait, never extend it.
+// Retry-After is either seconds or an HTTP date. It can only shorten the wait, never extend it,
+// and never drop below the floor: 0 (or an already elapsed date) would otherwise retry every in-flight request at once.
const getRateLimitDelayMs = (error: AxiosError) => {
const retryAfter = String(error.response?.headers?.["retry-after"] ?? "").trim();
if (!retryAfter) return RATE_LIMIT_DELAY_MS;
@@ -42,7 +44,7 @@ const getRateLimitDelayMs = (error: AxiosError) => {
const delayMs = Number.isFinite(seconds) ? seconds * 1000 : Date.parse(retryAfter) - Date.now();
if (Number.isNaN(delayMs)) return RATE_LIMIT_DELAY_MS;
- return Math.min(Math.max(delayMs, 0), RATE_LIMIT_DELAY_MS);
+ return Math.min(Math.max(delayMs, MIN_RATE_LIMIT_DELAY_MS), RATE_LIMIT_DELAY_MS);
};
// Vercel isn't consistent about casing, e.g. BAD_REQUEST alongside envs_size_too_large.