Skip to content

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

feat(dynamic-secret): enhance host verification with pre-resolved IPs

Victor Hugo dos Santosd3ac13b13307
diff --git a/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts b/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
index 8a440c1aeb..455b44d8b5 100644
--- a/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
+++ b/backend/src/ee/services/dynamic-secret/dynamic-secret-fns.ts
@@ -9,11 +9,13 @@ import { getDbConnectionHost } from "@app/lib/knex";
export const verifyHostInputValidity = async ({
host,
isDynamicSecret,
- isGateway
+ isGateway,
+ preResolvedIps
}: {
host: string;
isDynamicSecret: boolean;
isGateway?: boolean;
+ preResolvedIps?: string[];
}) => {
const appCfg = getConfig();
@@ -42,27 +44,32 @@ export const verifyHostInputValidity = async ({
}
const normalizedHost = host.split(":")[0].toLowerCase();
- const inputHostIps: string[] = [];
- if (net.isIP(host)) {
- inputHostIps.push(host);
+ let inputHostIps: string[];
+ if (preResolvedIps) {
+ inputHostIps = preResolvedIps;
} else {
- if (!appCfg.DYNAMIC_SECRET_ALLOW_INTERNAL_IP && !appCfg.ALLOW_INTERNAL_IP_CONNECTIONS) {
- if (normalizedHost === "localhost" || normalizedHost === "host.docker.internal") {
- throw new BadRequestError({
- message: `Local host IP addresses (${normalizedHost}) are not allowed.${!appCfg.isCloud ? ` If you are self-hosting, you can allow local host IP addresses by setting the '${isDynamicSecret ? "'DYNAMIC_SECRET_ALLOW_INTERNAL_IP'" : "'ALLOW_INTERNAL_IP_CONNECTIONS'"}' environment variable to 'true' on your instance.` : ""}`
- });
+ inputHostIps = [];
+ if (net.isIP(host)) {
+ inputHostIps.push(host);
+ } else {
+ if (!appCfg.DYNAMIC_SECRET_ALLOW_INTERNAL_IP && !appCfg.ALLOW_INTERNAL_IP_CONNECTIONS) {
+ if (normalizedHost === "localhost" || normalizedHost === "host.docker.internal") {
+ throw new BadRequestError({
+ message: `Local host IP addresses (${normalizedHost}) are not allowed.${!appCfg.isCloud ? ` If you are self-hosting, you can allow local host IP addresses by setting the '${isDynamicSecret ? "'DYNAMIC_SECRET_ALLOW_INTERNAL_IP'" : "'ALLOW_INTERNAL_IP_CONNECTIONS'"}' environment variable to 'true' on your instance.` : ""}`
+ });
+ }
}
+ const resolvedIps = (await dns.lookup(host, { all: true })).map(({ address }) => address);
+ inputHostIps.push(...resolvedIps);
}
- const resolvedIps = (await dns.lookup(host, { all: true })).map(({ address }) => address);
- inputHostIps.push(...resolvedIps);
- }
- if (!(appCfg.DYNAMIC_SECRET_ALLOW_INTERNAL_IP || appCfg.ALLOW_INTERNAL_IP_CONNECTIONS)) {
- const isInternalIp = inputHostIps.some((el) => isPrivateIp(el));
- if (isInternalIp)
- throw new BadRequestError({
- message: `Private IP addresses (${normalizedHost}) are not allowed.${!appCfg.isCloud ? ` If you are self-hosting, you can allow private IP addresses by setting the '${isDynamicSecret ? "'DYNAMIC_SECRET_ALLOW_INTERNAL_IP'" : "'ALLOW_INTERNAL_IP_CONNECTIONS'"}' environment variable to 'true' on your instance.` : ""}`
- });
+ if (!(appCfg.DYNAMIC_SECRET_ALLOW_INTERNAL_IP || appCfg.ALLOW_INTERNAL_IP_CONNECTIONS)) {
+ const isInternalIp = inputHostIps.some((el) => isPrivateIp(el));
+ if (isInternalIp)
+ throw new BadRequestError({
+ message: `Private IP addresses (${normalizedHost}) are not allowed.${!appCfg.isCloud ? ` If you are self-hosting, you can allow private IP addresses by setting the '${isDynamicSecret ? "'DYNAMIC_SECRET_ALLOW_INTERNAL_IP'" : "'ALLOW_INTERNAL_IP_CONNECTIONS'"}' environment variable to 'true' on your instance.` : ""}`
+ });
+ }
}
const isAppUsedIps = inputHostIps.some((el) => exclusiveIps.includes(el));
diff --git a/backend/src/lib/validator/safe-request.test.ts b/backend/src/lib/validator/safe-request.test.ts
index 76059bc2e6..526d1638b0 100644
--- a/backend/src/lib/validator/safe-request.test.ts
+++ b/backend/src/lib/validator/safe-request.test.ts
@@ -142,6 +142,20 @@ describe("safe-request SSRF helpers", () => {
await expect(validateAndPinUrl("https://internal-db.example")).rejects.toThrow(/internal infra/i);
});
+ it("passes the pre-resolved IPs into verifyHostInputValidity so both checks use the same lookup", async () => {
+ setLookup([
+ { address: PUBLIC_IP_V4, family: 4 },
+ { address: PUBLIC_IP_V4_ALT, family: 4 }
+ ]);
+ await validateAndPinUrl("https://example.com");
+ expect(verifyHostInputValidityMock).toHaveBeenCalledWith(
+ expect.objectContaining({
+ host: "example.com",
+ preResolvedIps: [PUBLIC_IP_V4, PUBLIC_IP_V4_ALT]
+ })
+ );
+ });
+
it("returns the resolved IPs on success so the caller can pin to them", async () => {
setLookup([
{ address: PUBLIC_IP_V4, family: 4 },
diff --git a/backend/src/lib/validator/safe-request.ts b/backend/src/lib/validator/safe-request.ts
index 40162ba86e..2d5c0cfd09 100644
--- a/backend/src/lib/validator/safe-request.ts
+++ b/backend/src/lib/validator/safe-request.ts
@@ -62,7 +62,12 @@ export const validateAndPinUrl = async (
}
// Block Infisical's own infrastructure (DB, Redis, etc.).
- await verifyHostInputValidity({ host: validUrl.hostname, isGateway: false, isDynamicSecret: false });
+ await verifyHostInputValidity({
+ host: validUrl.hostname,
+ isGateway: false,
+ isDynamicSecret: false,
+ preResolvedIps: entries.map((e) => e.address)
+ });
return { hostname: validUrl.hostname, entries };
};