Skip to content

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

refac: remove unnecessary ssrf duplicate check

adilson18efbc45bb1c
diff --git a/backend/src/services/app-connection/qovery/qovery-connection-fns.ts b/backend/src/services/app-connection/qovery/qovery-connection-fns.ts
index 84598a59a8..593c7f4a41 100644
--- a/backend/src/services/app-connection/qovery/qovery-connection-fns.ts
+++ b/backend/src/services/app-connection/qovery/qovery-connection-fns.ts
@@ -23,7 +23,7 @@ export const getQoveryInstanceUrl = async (connection: { credentials: { instance
return instanceUrl;
};
-const getQoveryAuthHeaders = (accessToken: string) => ({
+export const getQoveryAuthHeaders = (accessToken: string) => ({
Authorization: `Token ${accessToken}`,
Accept: "application/json"
});
diff --git a/backend/src/services/secret-sync/qovery/qovery-sync-fns.test.ts b/backend/src/services/secret-sync/qovery/qovery-sync-fns.test.ts
index 26330ccd76..37e6d76ac8 100644
--- a/backend/src/services/secret-sync/qovery/qovery-sync-fns.test.ts
+++ b/backend/src/services/secret-sync/qovery/qovery-sync-fns.test.ts
@@ -4,7 +4,6 @@ import { AxiosResponse } from "axios";
import { beforeEach, describe, expect, test, vi } from "vitest";
import { request } from "@app/lib/config/request";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
import { QoverySyncScope, QoveryVariableType } from "./qovery-sync-enums";
@@ -22,16 +21,17 @@ vi.mock("@app/lib/config/request", () => ({
}
}));
-vi.mock("@app/lib/validator", () => ({
- blockLocalAndPrivateIpAddresses: vi.fn()
-}));
-
-// Resolve the base URL without the SSRF/DNS check the real helper performs.
+// Resolve the base URL without the SSRF/DNS check the real helper performs, and reuse the real
+// auth-header builder that the sync now imports from the connection module.
vi.mock("@app/services/app-connection/qovery", () => ({
getQoveryInstanceUrl: vi.fn(
async (connection: { credentials: { instanceUrl?: string } }) =>
connection.credentials.instanceUrl ?? "https://api.qovery.com"
- )
+ ),
+ getQoveryAuthHeaders: (accessToken: string) => ({
+ Authorization: `Token ${accessToken}`,
+ Accept: "application/json"
+ })
}));
// keySchema filtering is exercised elsewhere; here every key is considered a match.
@@ -84,52 +84,52 @@ beforeEach(() => {
describe("getQoveryResourceUrl", () => {
const instanceUrl = "https://api.qovery.com";
- test("secret + project scope", async () => {
- await expect(
+ test("secret + project scope", () => {
+ expect(
getQoveryResourceUrl({
instanceUrl,
scope: QoverySyncScope.Project,
scopeId: "proj-1",
variableType: QoveryVariableType.Secret
})
- ).resolves.toBe("https://api.qovery.com/project/proj-1/secret");
+ ).toBe("https://api.qovery.com/project/proj-1/secret");
});
- test("variable + project scope", async () => {
- await expect(
+ test("variable + project scope", () => {
+ expect(
getQoveryResourceUrl({
instanceUrl,
scope: QoverySyncScope.Project,
scopeId: "proj-1",
variableType: QoveryVariableType.Variable
})
- ).resolves.toBe("https://api.qovery.com/project/proj-1/environmentVariable");
+ ).toBe("https://api.qovery.com/project/proj-1/environmentVariable");
});
- test("variable + environment scope", async () => {
- await expect(
+ test("variable + environment scope", () => {
+ expect(
getQoveryResourceUrl({
instanceUrl,
scope: QoverySyncScope.Environment,
scopeId: "env-1",
variableType: QoveryVariableType.Variable
})
- ).resolves.toBe("https://api.qovery.com/environment/env-1/environmentVariable");
+ ).toBe("https://api.qovery.com/environment/env-1/environmentVariable");
});
- test("secret + environment scope", async () => {
- await expect(
+ test("secret + environment scope", () => {
+ expect(
getQoveryResourceUrl({
instanceUrl,
scope: QoverySyncScope.Environment,
scopeId: "env-1",
variableType: QoveryVariableType.Secret
})
- ).resolves.toBe("https://api.qovery.com/environment/env-1/secret");
+ ).toBe("https://api.qovery.com/environment/env-1/secret");
});
- test("appends the resource id when provided", async () => {
- await expect(
+ test("appends the resource id when provided", () => {
+ expect(
getQoveryResourceUrl({
instanceUrl,
scope: QoverySyncScope.Project,
@@ -137,29 +137,18 @@ describe("getQoveryResourceUrl", () => {
variableType: QoveryVariableType.Secret,
resourceId: "sec-1"
})
- ).resolves.toBe("https://api.qovery.com/project/proj-1/secret/sec-1");
+ ).toBe("https://api.qovery.com/project/proj-1/secret/sec-1");
});
- test("normalizes a trailing slash on the instance URL", async () => {
- await expect(
+ test("normalizes a trailing slash on the instance URL", () => {
+ expect(
getQoveryResourceUrl({
instanceUrl: "https://qovery.self-hosted.io/",
scope: QoverySyncScope.Project,
scopeId: "proj-1",
variableType: QoveryVariableType.Secret
})
- ).resolves.toBe("https://qovery.self-hosted.io/project/proj-1/secret");
- });
-
- test("validates the constructed URL against local and private IP addresses", async () => {
- const url = await getQoveryResourceUrl({
- instanceUrl,
- scope: QoverySyncScope.Project,
- scopeId: "proj-1",
- variableType: QoveryVariableType.Secret
- });
-
- expect(blockLocalAndPrivateIpAddresses).toHaveBeenCalledWith(url);
+ ).toBe("https://qovery.self-hosted.io/project/proj-1/secret");
});
});
diff --git a/backend/src/services/secret-sync/qovery/qovery-sync-fns.ts b/backend/src/services/secret-sync/qovery/qovery-sync-fns.ts
index de3828b1e6..c0cbd2f52a 100644
--- a/backend/src/services/secret-sync/qovery/qovery-sync-fns.ts
+++ b/backend/src/services/secret-sync/qovery/qovery-sync-fns.ts
@@ -1,7 +1,6 @@
import { request } from "@app/lib/config/request";
import { removeTrailingSlash } from "@app/lib/fn";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
-import { getQoveryInstanceUrl } from "@app/services/app-connection/qovery";
+import { getQoveryAuthHeaders, getQoveryInstanceUrl } from "@app/services/app-connection/qovery";
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
import { SECRET_SYNC_NAME_MAP } from "@app/services/secret-sync/secret-sync-maps";
@@ -10,15 +9,17 @@ import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
import { QoverySyncScope, QoveryVariableType } from "./qovery-sync-enums";
import { TQoveryApiVariable, TQoverySyncWithCredentials } from "./qovery-sync-types";
-const QOVERY_SCOPE = {
- [QoverySyncScope.Project]: { pathSegment: QoverySyncScope.Project, apiScope: "PROJECT" },
- [QoverySyncScope.Environment]: { pathSegment: QoverySyncScope.Environment, apiScope: "ENVIRONMENT" }
-} as const;
+// The scope path segment is the enum value itself ("project" / "environment"); this map only carries
+// the scope value Qovery reports back, used to identify the entries we manage.
+const QOVERY_API_SCOPE: Record<QoverySyncScope, string> = {
+ [QoverySyncScope.Project]: "PROJECT",
+ [QoverySyncScope.Environment]: "ENVIRONMENT"
+};
-const QOVERY_VARIABLE_TYPE = {
- [QoveryVariableType.Secret]: { pathSegment: "secret" },
- [QoveryVariableType.Variable]: { pathSegment: "environmentVariable" }
-} as const;
+const QOVERY_VARIABLE_TYPE_PATH_SEGMENT: Record<QoveryVariableType, string> = {
+ [QoveryVariableType.Secret]: "secret",
+ [QoveryVariableType.Variable]: "environmentVariable"
+};
// Qovery returns inherited, built-in, alias, and override entries alongside the ones defined at the
// requested level. We only manage entries defined at the matching scope with a plain value type so we
@@ -44,45 +45,35 @@ export const resolveQoverySyncTarget = (
return { scope: QoverySyncScope.Project, scopeId: projectId, variableType };
};
-// Pure, verifiable URL construction: {instanceUrl}/{scopeSegment}/{scopeId}/{variableTypeSegment}[/{resourceId}]
-export const getQoveryResourceUrl = async ({
+// Pure, verifiable URL construction: {instanceUrl}/{scope}/{scopeId}/{variableTypeSegment}[/{resourceId}].
+// SSRF validation of the host happens once in getQoveryInstanceUrl; the segments appended here are
+// resource ids, not hosts, so they cannot change the host that was already validated.
+export const getQoveryResourceUrl = ({
instanceUrl,
scope,
scopeId,
variableType,
resourceId
}: TQoverySyncTarget & { instanceUrl: string; resourceId?: string }) => {
- const segments = [
- removeTrailingSlash(instanceUrl),
- QOVERY_SCOPE[scope].pathSegment,
- scopeId,
- QOVERY_VARIABLE_TYPE[variableType].pathSegment
- ];
+ const segments = [removeTrailingSlash(instanceUrl), scope, scopeId, QOVERY_VARIABLE_TYPE_PATH_SEGMENT[variableType]];
if (resourceId) segments.push(resourceId);
- const fullUrl = segments.join("/");
- await blockLocalAndPrivateIpAddresses(fullUrl);
- return fullUrl;
+ return segments.join("/");
};
-const getQoveryAuthHeaders = (accessToken: string) => ({
- Authorization: `Token ${accessToken}`,
- Accept: "application/json"
-});
-
const listManagedQoveryVariables = async (
instanceUrl: string,
accessToken: string,
target: TQoverySyncTarget
): Promise<TQoveryApiVariable[]> => {
- const url = await getQoveryResourceUrl({ instanceUrl, ...target });
+ const url = getQoveryResourceUrl({ instanceUrl, ...target });
const { data } = await request.get<{ results?: TQoveryApiVariable[] }>(url, {
headers: getQoveryAuthHeaders(accessToken)
});
return (data.results ?? []).filter(
(variable) =>
- variable.scope === QOVERY_SCOPE[target.scope].apiScope &&
+ variable.scope === QOVERY_API_SCOPE[target.scope] &&
(!variable.variable_type || variable.variable_type === QOVERY_MANAGED_VARIABLE_TYPE)
);
};
@@ -94,7 +85,7 @@ const createQoveryVariable = async (
key: string,
value: string
) => {
- const url = await getQoveryResourceUrl({ instanceUrl, ...target });
+ const url = getQoveryResourceUrl({ instanceUrl, ...target });
await request.post(url, { key, value }, { headers: getQoveryAuthHeaders(accessToken) });
};
@@ -106,7 +97,7 @@ const updateQoveryVariable = async (
key: string,
value: string
) => {
- const url = await getQoveryResourceUrl({ instanceUrl, ...target, resourceId });
+ const url = getQoveryResourceUrl({ instanceUrl, ...target, resourceId });
await request.put(url, { key, value }, { headers: getQoveryAuthHeaders(accessToken) });
};
@@ -116,7 +107,7 @@ const deleteQoveryVariable = async (
target: TQoverySyncTarget,
resourceId: string
) => {
- const url = await getQoveryResourceUrl({ instanceUrl, ...target, resourceId });
+ const url = getQoveryResourceUrl({ instanceUrl, ...target, resourceId });
await request.delete(url, { headers: getQoveryAuthHeaders(accessToken) });
};
@@ -144,8 +135,8 @@ export const QoverySyncFns = {
// Secrets never return their value, so they cannot be diffed and are always overwritten.
// Variables expose their value, so we skip the update when it is already up to date.
- const isSecretScope = target.variableType === QoveryVariableType.Secret;
- if (isSecretScope || existingVariable.value !== value) {
+ const isSecretVariableType = target.variableType === QoveryVariableType.Secret;
+ if (isSecretVariableType || existingVariable.value !== value) {
await updateQoveryVariable(instanceUrl, accessToken, target, existingVariable.id, key, value);
}
} catch (error) {