Skip to content

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

fix: block DNS rebinding SSRF

Carlos Monastyrskif89dc7b62dad
diff --git a/backend/src/ee/services/audit-log-stream/audit-log-stream-fns.ts b/backend/src/ee/services/audit-log-stream/audit-log-stream-fns.ts
index ffed6ee6ab..902aa2df02 100644
--- a/backend/src/ee/services/audit-log-stream/audit-log-stream-fns.ts
+++ b/backend/src/ee/services/audit-log-stream/audit-log-stream-fns.ts
@@ -1,6 +1,6 @@
import { TAuditLogs, TAuditLogStreams } from "@app/db/schemas";
import { getConfig } from "@app/lib/config/env";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, createIpGuardedAgents } from "@app/lib/validator";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { KmsDataKey } from "@app/services/kms/kms-types";
@@ -17,6 +17,8 @@ import { getSumoLogicProviderListItem } from "./sumo-logic/sumo-logic-provider-f
export const blockAuditLogStreamInternalIps = (url: string) =>
blockLocalAndPrivateIpAddresses(url, false, getConfig().AUDIT_LOG_STREAM_ALLOW_INTERNAL_IP);
+export const auditLogStreamAgents = createIpGuardedAgents(() => getConfig().AUDIT_LOG_STREAM_ALLOW_INTERNAL_IP);
+
// The instant a provider should report the event at. Delivery can lag the event by minutes
// (retry backoff tops out around 240s) or by months during a backfill, so a provider that
// stamps its own send time misdates the record. Falls back to now for payloads that carry no
diff --git a/backend/src/ee/services/audit-log-stream/azure/azure-provider-factory.ts b/backend/src/ee/services/audit-log-stream/azure/azure-provider-factory.ts
index 91dadd2b05..b4e0ce37f7 100644
--- a/backend/src/ee/services/audit-log-stream/azure/azure-provider-factory.ts
+++ b/backend/src/ee/services/audit-log-stream/azure/azure-provider-factory.ts
@@ -4,7 +4,7 @@ import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { AUDIT_LOG_STREAM_BATCH_TIMEOUT, AUDIT_LOG_STREAM_TIMEOUT } from "../../audit-log/audit-log-queue";
-import { blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
+import { auditLogStreamAgents, blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
import {
TLogStreamFactoryBatchStreamLog,
TLogStreamFactoryGetProviderBatchLimit,
@@ -62,6 +62,7 @@ export const AzureProviderFactory = () => {
`${dceUrl}/dataCollectionRules/${dcrId}/streams/Custom-${cltName}_CL?api-version=2023-01-01`,
createPayload({ ping: "ok" }),
{
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_TIMEOUT
}
@@ -94,6 +95,7 @@ export const AzureProviderFactory = () => {
`${dceUrl}/dataCollectionRules/${dcrId}/streams/Custom-${cltName}_CL?api-version=2023-01-01`,
auditLogs.map(buildAzureEvent),
{
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_BATCH_TIMEOUT
}
diff --git a/backend/src/ee/services/audit-log-stream/cribl/cribl-provider-factory.ts b/backend/src/ee/services/audit-log-stream/cribl/cribl-provider-factory.ts
index 1cc7809d72..2921e132a6 100644
--- a/backend/src/ee/services/audit-log-stream/cribl/cribl-provider-factory.ts
+++ b/backend/src/ee/services/audit-log-stream/cribl/cribl-provider-factory.ts
@@ -4,7 +4,7 @@ import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { AUDIT_LOG_STREAM_BATCH_TIMEOUT, AUDIT_LOG_STREAM_TIMEOUT } from "../../audit-log/audit-log-queue";
-import { blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
+import { auditLogStreamAgents, blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
import {
TLogStreamFactoryBatchStreamLog,
TLogStreamFactoryGetProviderBatchLimit,
@@ -28,6 +28,7 @@ export const CriblProviderFactory = () => {
await request
.post(url, JSON.stringify({ ping: "ok" }), {
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_TIMEOUT
})
@@ -57,6 +58,7 @@ export const CriblProviderFactory = () => {
const body = auditLogs.map((auditLog) => JSON.stringify(auditLog)).join("\n");
await request.post(url, body, {
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_BATCH_TIMEOUT
});
@@ -73,6 +75,7 @@ export const CriblProviderFactory = () => {
};
await request.post(url, JSON.stringify(auditLog), {
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_TIMEOUT
});
diff --git a/backend/src/ee/services/audit-log-stream/custom/custom-provider-factory.ts b/backend/src/ee/services/audit-log-stream/custom/custom-provider-factory.ts
index 9f8316461e..b84ebc0deb 100644
--- a/backend/src/ee/services/audit-log-stream/custom/custom-provider-factory.ts
+++ b/backend/src/ee/services/audit-log-stream/custom/custom-provider-factory.ts
@@ -4,7 +4,7 @@ import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { AUDIT_LOG_STREAM_BATCH_TIMEOUT, AUDIT_LOG_STREAM_TIMEOUT } from "../../audit-log/audit-log-queue";
-import { blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
+import { auditLogStreamAgents, blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
import {
TLogStreamFactoryBatchStreamLog,
TLogStreamFactoryGetProviderBatchLimit,
@@ -33,6 +33,7 @@ export const CustomProviderFactory = () => {
url,
{ ping: "ok" },
{
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_TIMEOUT,
maxRedirects: 0
@@ -64,6 +65,7 @@ export const CustomProviderFactory = () => {
}
await request.post(url, auditLogs, {
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_BATCH_TIMEOUT
});
@@ -83,6 +85,7 @@ export const CustomProviderFactory = () => {
}
await request.post(url, auditLog, {
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_TIMEOUT
});
diff --git a/backend/src/ee/services/audit-log-stream/datadog/datadog-provider-factory.ts b/backend/src/ee/services/audit-log-stream/datadog/datadog-provider-factory.ts
index 2fb3f337bb..f271790c20 100644
--- a/backend/src/ee/services/audit-log-stream/datadog/datadog-provider-factory.ts
+++ b/backend/src/ee/services/audit-log-stream/datadog/datadog-provider-factory.ts
@@ -5,7 +5,7 @@ import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { AUDIT_LOG_STREAM_BATCH_TIMEOUT, AUDIT_LOG_STREAM_TIMEOUT } from "../../audit-log/audit-log-queue";
-import { blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
+import { auditLogStreamAgents, blockAuditLogStreamInternalIps } from "../audit-log-stream-fns";
import {
TLogStreamFactoryBatchStreamLog,
TLogStreamFactoryGetProviderBatchLimit,
@@ -39,6 +39,7 @@ export const DatadogProviderFactory = () => {
await request
.post(url, createPayload({ ping: "ok" }), {
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_TIMEOUT
})
@@ -62,6 +63,7 @@ export const DatadogProviderFactory = () => {
const streamHeaders: RawAxiosRequestHeaders = { "Content-Type": "application/json", "DD-API-KEY": token };
await request.post(url, auditLogs.map(createPayload), {
+ ...auditLogStreamAgents,
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_BATCH_TIMEOUT
});
diff --git a/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.test.ts b/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.test.ts
index 0aa59a6335..ee50a2ec44 100644
--- a/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.test.ts
+++ b/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.test.ts
@@ -21,6 +21,7 @@ vi.mock("@app/lib/logger", () => ({
// Only safeRequest's URL validation is stubbed, because the real one resolves DNS. The stub still
// dispatches through the axios instance below, so the on-wire assertions stay on real behaviour.
vi.mock("@app/lib/validator", () => ({
+ createIpGuardedAgents: () => ({}),
safeRequest: {
post: async (url: string, data: unknown, options: Record<string, unknown> = {}) => {
const { allowPrivateIps, ...axiosOpts } = options;
diff --git a/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts
index 8eec7bdba8..0c86d81121 100644
--- a/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/auth0-client-secret/auth0-client-secret-rotation-fns.ts
@@ -15,7 +15,7 @@ import {
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { removeTrailingSlash } from "@app/lib/fn";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { getAuth0ConnectionAccessToken } from "@app/services/app-connection/auth0/auth0-connection-fns";
import { generatePassword } from "../shared/utils";
@@ -39,6 +39,7 @@ export const auth0ClientSecretRotationFactory: TRotationFactory<
await request.request({
method: "PATCH",
url: `${audience}clients/${clientId}`,
+ ...ipGuardedAgents,
headers: { authorization: `Bearer ${accessToken}` },
data: {
client_secret: clientSecret
@@ -68,6 +69,7 @@ export const auth0ClientSecretRotationFactory: TRotationFactory<
await request.request({
method: "POST",
url: `${audience}clients/${clientId}/rotate-secret`,
+ ...ipGuardedAgents,
headers: { authorization: `Bearer ${accessToken}` }
});
@@ -111,6 +113,7 @@ export const auth0ClientSecretRotationFactory: TRotationFactory<
await request.request({
method: "POST",
url: `${removeTrailingSlash(instanceUrl)}/oauth/token`,
+ ...ipGuardedAgents,
headers: { "content-type": "application/x-www-form-urlencoded" },
data: new URLSearchParams({
grant_type: "client_credentials",
diff --git a/backend/src/lib/validator/index.ts b/backend/src/lib/validator/index.ts
index db8b80f9d7..78b1e7bdd9 100644
--- a/backend/src/lib/validator/index.ts
+++ b/backend/src/lib/validator/index.ts
@@ -25,6 +25,9 @@ export {
} from "./validate-smb";
export {
blockLocalAndPrivateIpAddresses,
+ createIpGuardedAgents,
+ ipGuardedAgents,
+ ipGuardedLookup,
isValidAzureKeyVaultUrl,
ssrfSafeGet,
ssrfSafePost,
diff --git a/backend/src/lib/validator/validate-url.ts b/backend/src/lib/validator/validate-url.ts
index fd87da021b..f4ba85d142 100644
--- a/backend/src/lib/validator/validate-url.ts
+++ b/backend/src/lib/validator/validate-url.ts
@@ -1,4 +1,8 @@
+import nodeDns, { LookupAddress } from "node:dns";
import dns from "node:dns/promises";
+import http from "node:http";
+import https from "node:https";
+import { LookupFunction } from "node:net";
import { isIP } from "net";
import RE2 from "re2";
@@ -42,6 +46,41 @@ export const blockLocalAndPrivateIpAddresses = async (url: string, isGateway = f
if (isInternalIp && !allowInternal) throw new BadRequestError({ message: "Local IPs not allowed as URL" });
};
+const createIpGuardedLookup =
+ (isInternalIpAllowed: () => boolean = () => false): LookupFunction =>
+ (hostname, options, callback) => {
+ nodeDns.lookup(hostname, { ...options, all: true }, (err, addresses: LookupAddress[]) => {
+ if (err) {
+ callback(err, "", 0);
+ return;
+ }
+ const appCfg = getConfig();
+ const isInternalAllowed =
+ appCfg.isDevelopmentMode || appCfg.ALLOW_INTERNAL_IP_CONNECTIONS || isInternalIpAllowed();
+ if (!isInternalAllowed && addresses.some(({ address }) => isPrivateIp(address))) {
+ callback(new BadRequestError({ message: "Local IPs not allowed as URL" }), "", 0);
+ return;
+ }
+ if (options.all) {
+ (callback as unknown as (error: null, result: LookupAddress[]) => void)(null, addresses);
+ return;
+ }
+ callback(null, addresses[0].address, addresses[0].family);
+ });
+ };
+
+export const ipGuardedLookup = createIpGuardedLookup();
+
+export const createIpGuardedAgents = (isInternalIpAllowed?: () => boolean) => {
+ const lookup = createIpGuardedLookup(isInternalIpAllowed);
+ return {
+ httpAgent: new http.Agent({ keepAlive: true, lookup }),
+ httpsAgent: new https.Agent({ keepAlive: true, lookup })
+ };
+};
+
+export const ipGuardedAgents = createIpGuardedAgents();
+
const AZURE_KEY_VAULT_HOST_REGEX = new RE2(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?\.vault\.azure\.net$/);
/**
diff --git a/backend/src/services/app-connection/1password/1password-connection-fns.ts b/backend/src/services/app-connection/1password/1password-connection-fns.ts
index 44f3757b21..e036d27bb2 100644
--- a/backend/src/services/app-connection/1password/1password-connection-fns.ts
+++ b/backend/src/services/app-connection/1password/1password-connection-fns.ts
@@ -3,7 +3,7 @@ import { AxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { removeTrailingSlash } from "@app/lib/fn";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { OnePassConnectionMethod } from "./1password-connection-enums";
@@ -32,6 +32,7 @@ export const validateOnePassConnectionCredentials = async (config: TOnePassConne
try {
const res = await request.get(`${instanceUrl}/v1/vaults`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiToken}`,
Accept: "application/json"
@@ -60,6 +61,7 @@ export const listOnePassVaults = async (appConnection: TOnePassConnection) => {
const { apiToken } = appConnection.credentials;
const resp = await request.get<TOnePassVault[]>(`${instanceUrl}/v1/vaults`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiToken}`,
Accept: "application/json"
diff --git a/backend/src/services/app-connection/auth0/auth0-connection-fns.ts b/backend/src/services/app-connection/auth0/auth0-connection-fns.ts
index 944b1f69a3..5cde54eab6 100644
--- a/backend/src/services/app-connection/auth0/auth0-connection-fns.ts
+++ b/backend/src/services/app-connection/auth0/auth0-connection-fns.ts
@@ -1,7 +1,7 @@
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { removeTrailingSlash } from "@app/lib/fn";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { encryptAppConnectionCredentials } from "@app/services/app-connection/app-connection-fns";
@@ -30,6 +30,7 @@ const authorizeAuth0Connection = async ({
const { data } = await request.request<TAuth0AccessTokenResponse>({
method: "POST",
url: `${removeTrailingSlash(instanceUrl)}/oauth/token`,
+ ...ipGuardedAgents,
headers: { "content-type": "application/x-www-form-urlencoded" },
data: new URLSearchParams({
grant_type: "client_credentials", // this will need to be resolved if we support methods other than client credentials
diff --git a/backend/src/services/app-connection/auth0/auth0-connection-service.ts b/backend/src/services/app-connection/auth0/auth0-connection-service.ts
index 693c55ea62..2e1a561da8 100644
--- a/backend/src/services/app-connection/auth0/auth0-connection-service.ts
+++ b/backend/src/services/app-connection/auth0/auth0-connection-service.ts
@@ -1,6 +1,6 @@
import { request } from "@app/lib/config/request";
import { OrgServiceActor } from "@app/lib/types";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { getAuth0ConnectionAccessToken } from "@app/services/app-connection/auth0/auth0-connection-fns";
@@ -31,6 +31,7 @@ const listAuth0Clients = async (
while (hasMore) {
// eslint-disable-next-line no-await-in-loop
const { data: clientsPage } = await request.get<TAuth0ListClientsResponse>(`${audience}clients`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${accessToken}`,
"Accept-Encoding": "application/json"
diff --git a/backend/src/services/app-connection/azure-adcs/azure-adcs-connection-fns.ts b/backend/src/services/app-connection/azure-adcs/azure-adcs-connection-fns.ts
index 3aaf9fb6e9..baf8da737b 100644
--- a/backend/src/services/app-connection/azure-adcs/azure-adcs-connection-fns.ts
+++ b/backend/src/services/app-connection/azure-adcs/azure-adcs-connection-fns.ts
@@ -4,7 +4,7 @@ import https from "https";
import RE2 from "re2";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator/validate-url";
+import { blockLocalAndPrivateIpAddresses, ipGuardedLookup } from "@app/lib/validator";
import { decryptAppConnectionCredentials } from "@app/services/app-connection/app-connection-fns";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
@@ -112,7 +112,8 @@ const createHttpsAgent = (sslRejectUnauthorized: boolean, sslCertificate?: strin
ca: sslCertificate ? [sslCertificate.trim()] : undefined,
// Disable hostname verification as Microsoft servers by default use local IPs for certificates
// which may not match the hostname used to connect
- checkServerIdentity: () => undefined
+ checkServerIdentity: () => undefined,
+ lookup: ipGuardedLookup
};
return new https.Agent(agentOptions);
@@ -130,6 +131,7 @@ const axiosNtlmRequest = async (config: AxiosNtlmConfig): Promise<AxiosNtlmRespo
const axiosConfig = {
httpsAgent: config.httpsAgent,
+ maxRedirects: 0,
timeout: 60000
};
diff --git a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts
index 94c4ef81a6..4f8a91baeb 100644
--- a/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts
+++ b/backend/src/services/app-connection/azure-key-vault/azure-key-vault-connection-fns.ts
@@ -13,7 +13,7 @@ import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
import { GatewayProxyProtocol } from "@app/lib/gateway-v2/types";
import { logger } from "@app/lib/logger";
import { getTlsServerNameOptions } from "@app/lib/tls";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import {
decryptAppConnectionCredentials,
encryptAppConnectionCredentials,
@@ -66,7 +66,7 @@ export const requestWithAzureKeyVaultGateway = async <T>(
// If gateway isn't set up, don't proxy the request
if (!gatewayId) {
- return request.request(requestConfig);
+ return request.request({ ...requestConfig, ...ipGuardedAgents });
}
const [targetHost] = await verifyHostInputValidity({ host: url.hostname, isGateway: true, isDynamicSecret: false });
diff --git a/backend/src/services/app-connection/netscaler/netscaler-connection-fns.ts b/backend/src/services/app-connection/netscaler/netscaler-connection-fns.ts
index 3e2c7924e2..e1df435aeb 100644
--- a/backend/src/services/app-connection/netscaler/netscaler-connection-fns.ts
+++ b/backend/src/services/app-connection/netscaler/netscaler-connection-fns.ts
@@ -8,7 +8,7 @@ import { getMissingGatewayMessage } from "@app/lib/gateway-v2/gateway-errors";
import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
import { GatewayProxyProtocol } from "@app/lib/gateway-v2/types";
import { getTlsServerNameOptions } from "@app/lib/tls";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedLookup } from "@app/lib/validator";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { NetScalerConnectionMethod } from "./netscaler-connection-enums";
@@ -20,7 +20,8 @@ export const createNetScalerHttpsAgent = (credentials: {
}): https.Agent => {
return new https.Agent({
rejectUnauthorized: credentials.sslRejectUnauthorized,
- ca: credentials.sslCertificate ? [credentials.sslCertificate] : undefined
+ ca: credentials.sslCertificate ? [credentials.sslCertificate] : undefined,
+ lookup: ipGuardedLookup
});
};
diff --git a/backend/src/services/app-connection/trigger-dev/trigger-dev-connection-fns.ts b/backend/src/services/app-connection/trigger-dev/trigger-dev-connection-fns.ts
index c294b9408a..dc10b9e8d3 100644
--- a/backend/src/services/app-connection/trigger-dev/trigger-dev-connection-fns.ts
+++ b/backend/src/services/app-connection/trigger-dev/trigger-dev-connection-fns.ts
@@ -3,7 +3,7 @@ import { AxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { removeTrailingSlash } from "@app/lib/fn";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
@@ -59,6 +59,7 @@ export const validateTriggerDevConnectionCredentials = async (config: TTriggerDe
try {
await request.get(`${instanceUrl}/api/v1/projects`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/json"
@@ -83,6 +84,7 @@ export const listTriggerDevProjects = async (appConnection: TTriggerDevConnectio
const { apiKey } = appConnection.credentials;
const { data } = await request.get<TTriggerDevApiProject[]>(`${instanceUrl}/api/v1/projects`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/json"
@@ -115,6 +117,7 @@ export const listTriggerDevEnvironments = async (
const { data } = await request.get<TTriggerDevApiEnvironment[]>(
`${instanceUrl}/api/v1/projects/${encodeURIComponent(projectRef)}/environments`,
{
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/json"
diff --git a/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.ts b/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.ts
index 4a6386ea95..b21b59959d 100644
--- a/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.ts
+++ b/backend/src/services/app-connection/venafi-tpp/venafi-tpp-connection-fns.ts
@@ -10,7 +10,7 @@ import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
import { GatewayProxyProtocol } from "@app/lib/gateway-v2/types";
import { logger } from "@app/lib/logger";
import { getTlsServerNameOptions } from "@app/lib/tls";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator/validate-url";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { VenafiTppConnectionMethod } from "./venafi-tpp-connection-enums";
@@ -55,7 +55,7 @@ export const requestWithVenafiTppGateway = async <T>(
await blockLocalAndPrivateIpAddresses(url.toString(), Boolean(gatewayId));
if (!gatewayId) {
- return request.request(requestConfig);
+ return request.request({ ...requestConfig, ...ipGuardedAgents });
}
const [targetHost] = await verifyHostInputValidity({ host: url.hostname, isGateway: true, isDynamicSecret: false });
diff --git a/backend/src/services/app-connection/zabbix/zabbix-connection-fns.ts b/backend/src/services/app-connection/zabbix/zabbix-connection-fns.ts
index a34a6c3815..4e6f2ae410 100644
--- a/backend/src/services/app-connection/zabbix/zabbix-connection-fns.ts
+++ b/backend/src/services/app-connection/zabbix/zabbix-connection-fns.ts
@@ -3,7 +3,7 @@ import RE2 from "re2";
import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { ZabbixConnectionMethod } from "./zabbix-connection-enums";
@@ -41,6 +41,7 @@ export const validateZabbixConnectionCredentials = async (config: TZabbixConnect
};
const response: { data: { error?: { message: string }; result?: string } } = await request.post(apiUrl, payload, {
+ ...ipGuardedAgents,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`
@@ -83,6 +84,7 @@ export const listZabbixHosts = async (appConnection: TZabbixConnection): Promise
};
const response: { data: TZabbixHostListResponse } = await request.post(apiUrl, payload, {
+ ...ipGuardedAgents,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`
diff --git a/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts b/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
index 7d87c02902..7464e0b90d 100644
--- a/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
+++ b/backend/src/services/certificate-authority/acme/acme-certificate-authority-fns.ts
@@ -17,7 +17,7 @@ import { isPrivateIp } from "@app/lib/ip/ipRange";
import { ProcessedPermissionRules } from "@app/lib/knex/permission-filter-utils";
import { logger } from "@app/lib/logger";
import { OrgServiceActor } from "@app/lib/types";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { decryptAppConnection } from "@app/services/app-connection/app-connection-fns";
@@ -462,7 +462,12 @@ export const executeAcmeOrder = async (
await reportProgress("Submitting order to the certificate authority");
- const pem = await acmeClient.auto({
+ const ipGuardInterceptorId = acme.axios.interceptors.request.use(async (config) => {
+ if (config.url) await blockLocalAndPrivateIpAddresses(config.url);
+ return { ...config, ...ipGuardedAgents, maxRedirects: 0 };
+ });
+
+ const order = acmeClient.auto({
csr,
email: acmeCa.configuration.accountEmail,
challengePriority: ["dns-01"],
@@ -629,6 +634,8 @@ export const executeAcmeOrder = async (
}
});
+ const pem = await order.finally(() => acme.axios.interceptors.request.eject(ipGuardInterceptorId));
+
if (isCancelled && (await isCancelled())) {
throw new CertificateRequestCancelledError();
}
diff --git a/backend/src/services/secret-sync/1password/1password-sync-fns.ts b/backend/src/services/secret-sync/1password/1password-sync-fns.ts
index 0cc881018f..4fb8972185 100644
--- a/backend/src/services/secret-sync/1password/1password-sync-fns.ts
+++ b/backend/src/services/secret-sync/1password/1password-sync-fns.ts
@@ -1,4 +1,5 @@
import { request } from "@app/lib/config/request";
+import { ipGuardedAgents } from "@app/lib/validator";
import { getOnePassInstanceUrl } from "@app/services/app-connection/1password";
import {
TDeleteOnePassVariable,
@@ -18,6 +19,7 @@ const VALUE_LABEL_DEFAULT = "value";
const listOnePassItems = async ({ instanceUrl, apiToken, vaultId, valueLabel }: TOnePassListVariables) => {
const { data } = await request.get<TOnePassListVariablesResponse>(`${instanceUrl}/v1/vaults/${vaultId}/items`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiToken}`,
Accept: "application/json"
@@ -38,6 +40,7 @@ const listOnePassItems = async ({ instanceUrl, apiToken, vaultId, valueLabel }:
}
const { data: secret } = await request.get<TOnePassVariable>(`${instanceUrl}/v1/vaults/${vaultId}/items/${s.id}`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiToken}`,
Accept: "application/json"
@@ -85,6 +88,7 @@ const createOnePassItem = async ({
]
},
{
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiToken}`,
"Content-Type": "application/json"
@@ -125,6 +129,7 @@ const updateOnePassItem = async ({
]
},
{
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiToken}`,
"Content-Type": "application/json"
@@ -135,6 +140,7 @@ const updateOnePassItem = async ({
const deleteOnePassItem = async ({ instanceUrl, apiToken, vaultId, itemId }: TDeleteOnePassVariable) => {
return request.delete(`${instanceUrl}/v1/vaults/${vaultId}/items/${itemId}`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiToken}`
}
diff --git a/backend/src/services/secret-sync/trigger-dev/trigger-dev-sync-fns.ts b/backend/src/services/secret-sync/trigger-dev/trigger-dev-sync-fns.ts
index 7b70668397..0d18e36a68 100644
--- a/backend/src/services/secret-sync/trigger-dev/trigger-dev-sync-fns.ts
+++ b/backend/src/services/secret-sync/trigger-dev/trigger-dev-sync-fns.ts
@@ -1,4 +1,5 @@
import { request } from "@app/lib/config/request";
+import { ipGuardedAgents } from "@app/lib/validator";
import { getTriggerDevInstanceUrl } from "@app/services/app-connection/trigger-dev";
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
@@ -37,6 +38,7 @@ const listTriggerDevEnvVars = async (
try {
const { data } = await request.get<TTriggerDevEnvVar[]>(baseUrl, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/json"
@@ -68,6 +70,7 @@ const importTriggerDevEnvVars = async (
`${baseUrl}/import`,
{ variables, override: true, isSecret },
{
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json"
@@ -94,6 +97,7 @@ const deleteTriggerDevEnvVar = async (
try {
await request.delete(`${baseUrl}/${encodeURIComponent(key)}`, {
+ ...ipGuardedAgents,
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/json"
diff --git a/backend/src/services/secret-sync/zabbix/zabbix-sync-fns.ts b/backend/src/services/secret-sync/zabbix/zabbix-sync-fns.ts
index 5346c88477..bb0950f3c5 100644
--- a/backend/src/services/secret-sync/zabbix/zabbix-sync-fns.ts
+++ b/backend/src/services/secret-sync/zabbix/zabbix-sync-fns.ts
@@ -1,7 +1,7 @@
import RE2 from "re2";
import { request } from "@app/lib/config/request";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, ipGuardedAgents } from "@app/lib/validator";
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
import { TSecretSyncPayload } from "@app/services/secret-sync/secret-sync-payload";
@@ -59,6 +59,7 @@ const listZabbixSecrets = async (apiToken: string, instanceUrl: string, hostId?:
try {
const response: ZabbixApiResponse<TZabbixSecret[]> = await request.post(apiUrl, payload, {
+ ...ipGuardedAgents,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`
@@ -106,6 +107,7 @@ const putZabbixSecrets = async (
// eslint-disable-next-line no-await-in-loop
const response: ZabbixApiResponse<ZabbixMacroCreateResponse> = await request.post(apiUrl, updatePayload, {
+ ...ipGuardedAgents,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`
@@ -137,6 +139,7 @@ const putZabbixSecrets = async (
// eslint-disable-next-line no-await-in-loop
const response: ZabbixApiResponse<ZabbixMacroCreateResponse> = await request.post(apiUrl, createPayload, {
+ ...ipGuardedAgents,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`
@@ -181,6 +184,7 @@ const deleteZabbixSecrets = async (
};
const response: ZabbixApiResponse<ZabbixMacroDeleteResponse> = await request.post(apiUrl, payload, {
+ ...ipGuardedAgents,
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`