Skip to content

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

refactor: standardize HTTP requests using safeRequest across dynamic secret providers

Victor Hugo dos Santos0772d8770fdd
diff --git a/backend/src/ee/services/dynamic-secret/providers/azure-entra-id.ts b/backend/src/ee/services/dynamic-secret/providers/azure-entra-id.ts
index cc72f268b3..ff8286884f 100644
--- a/backend/src/ee/services/dynamic-secret/providers/azure-entra-id.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/azure-entra-id.ts
@@ -1,8 +1,8 @@
import { customAlphabet } from "nanoid";
-import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { sanitizeString } from "@app/lib/fn";
+import { safeRequest } from "@app/lib/validator";
import { AzureEntraIDSchema, TDynamicProviderFns } from "./models";
@@ -29,7 +29,7 @@ export const AzureEntraIDProvider = (): TDynamicProviderFns & {
applicationId: string,
clientSecret: string
): Promise<{ token?: string; success: boolean }> => {
- const response = await request.post<{ access_token: string }>(
+ const response = await safeRequest.post<{ access_token: string }>(
`${MSFT_LOGIN_URL}/${tenantId}/oauth2/v2.0/token`,
{
grant_type: "client_credentials",
@@ -76,7 +76,7 @@ export const AzureEntraIDProvider = (): TDynamicProviderFns & {
throw new BadRequestError({ message: "Failed to authorize to Microsoft Entra ID" });
}
- const response = await request.patch(
+ const response = await safeRequest.patch(
`${MSFT_GRAPH_API_URL}/users/${providerInputs.userId}`,
{
passwordProfile: {
@@ -136,15 +136,14 @@ export const AzureEntraIDProvider = (): TDynamicProviderFns & {
throw new BadRequestError({ message: "Failed to authorize to Microsoft Entra ID" });
}
- const response = await request.get<{ value: [{ id: string; displayName: string; userPrincipalName: string }] }>(
- `${MSFT_GRAPH_API_URL}/users`,
- {
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
- Authorization: `Bearer ${data.token}`
- }
+ const response = await safeRequest.get<{
+ value: [{ id: string; displayName: string; userPrincipalName: string }];
+ }>(`${MSFT_GRAPH_API_URL}/users`, {
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ Authorization: `Bearer ${data.token}`
}
- );
+ });
if (response.status !== 200) {
throw new BadRequestError({ message: "Failed to fetch users" });
diff --git a/backend/src/ee/services/dynamic-secret/providers/couchbase.ts b/backend/src/ee/services/dynamic-secret/providers/couchbase.ts
index 06ed1c38e9..ed53e1929e 100644
--- a/backend/src/ee/services/dynamic-secret/providers/couchbase.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/couchbase.ts
@@ -3,11 +3,10 @@ import crypto from "node:crypto";
import RE2 from "re2";
import { TDynamicSecrets } from "@app/db/schemas";
-import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { sanitizeString } from "@app/lib/fn";
import { alphaNumericNanoId } from "@app/lib/nanoid";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator/validate-url";
+import { blockLocalAndPrivateIpAddresses, safeRequest } from "@app/lib/validator/validate-url";
import { ActorIdentityAttributes } from "../../dynamic-secret-lease/dynamic-secret-lease-types";
import { DynamicSecretCouchbaseSchema, PasswordRequirements, TDynamicProviderFns } from "./models";
@@ -156,10 +155,8 @@ const couchbaseApiRequest = async (
apiKey: string,
data?: unknown
): Promise<CouchbaseUserResponse> => {
- await blockLocalAndPrivateIpAddresses(url);
-
try {
- const response = await request({
+ const response = await safeRequest.request({
method: method.toLowerCase() as "get" | "post" | "put" | "delete",
url,
headers: {
@@ -167,8 +164,7 @@ const couchbaseApiRequest = async (
"Content-Type": "application/json"
},
data: data || undefined,
- timeout: 30000,
- maxRedirects: 0
+ timeout: 30000
});
return response.data as CouchbaseUserResponse;
diff --git a/backend/src/ee/services/dynamic-secret/providers/github.ts b/backend/src/ee/services/dynamic-secret/providers/github.ts
index 408189f56c..35fd07b5d2 100644
--- a/backend/src/ee/services/dynamic-secret/providers/github.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/github.ts
@@ -1,11 +1,11 @@
import { isAxiosError } from "axios";
import jwt from "jsonwebtoken";
-import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto";
import { BadRequestError, InternalServerError } from "@app/lib/errors";
import { sanitizeString } from "@app/lib/fn";
import { alphaNumericNanoId } from "@app/lib/nanoid";
+import { safeRequest } from "@app/lib/validator";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
import { DynamicSecretGithubSchema, TDynamicProviderFns } from "./models";
@@ -57,7 +57,7 @@ export const GithubProvider = (): TDynamicProviderFns => {
const tokenUrl = `${IntegrationUrls.GITHUB_API_URL}/app/installations/${String(installationId)}/access_tokens`;
try {
- const response = await request.post<GitHubInstallationTokenResponse>(tokenUrl, undefined, {
+ const response = await safeRequest.post<GitHubInstallationTokenResponse>(tokenUrl, undefined, {
headers: {
Authorization: `Bearer ${appJwt}`,
Accept: "application/vnd.github.v3+json",
diff --git a/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts b/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts
index 5dac4914fc..d9d5cd0a07 100644
--- a/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts
@@ -1,5 +1,6 @@
-import { AxiosError, isAxiosError } from "axios";
+import { AxiosError, AxiosRequestConfig, isAxiosError } from "axios";
import https from "https";
+import { z } from "zod";
import { TDynamicSecrets } from "@app/db/schemas";
import { request } from "@app/lib/config/request";
@@ -7,7 +8,7 @@ import { BadRequestError } from "@app/lib/errors";
import { sanitizeString } from "@app/lib/fn";
import { GatewayHttpProxyActions, GatewayProxyProtocol, withGatewayProxy } from "@app/lib/gateway";
import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
-import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
+import { blockLocalAndPrivateIpAddresses, safeRequest } from "@app/lib/validator";
import { TKubernetesTokenRequest } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-types";
import {
@@ -48,6 +49,59 @@ export const KubernetesProvider = ({
return providerInputs;
};
+ /**
+ * Returns the right HTTP client for a Kubernetes API request:
+ *
+ * - Gateway-routed (`isGatewayProxied = true`, asserted by `$gatewayProxyWrapper`):
+ * stays on the existing axios `request` so the gateway-supplied
+ * `httpsAgent` (carrying the relay TLS context) is honored as before.
+ * The gateway already enforces the originally configured target, so
+ * SSRF/rebinding cannot land elsewhere.
+ * - Direct (`isGatewayProxied = false`): switches to `safeRequest`, which
+ * validates the user-supplied URL and pins the connection to the
+ * validated IP set to defeat DNS rebinding TOCTOU between validation
+ * and connect. `httpsAgent` from caller is dropped because safeRequest
+ * builds its own pinned agent; CA / rejectUnauthorized are forwarded
+ * through safeRequest options instead.
+ *
+ */
+ const k8sHttpClient = (providerInputs: z.infer<typeof DynamicSecretKubernetesSchema>, isGatewayProxied: boolean) => {
+ type K8sRequestConfig = AxiosRequestConfig & { httpsAgent?: https.Agent };
+
+ if (isGatewayProxied) {
+ return {
+ get: <T = unknown>(url: string, config: K8sRequestConfig) => request.get<T>(url, config),
+ post: <T = unknown>(url: string, body: unknown, config: K8sRequestConfig) => request.post<T>(url, body, config),
+ delete: <T = unknown>(url: string, config: K8sRequestConfig) => request.delete<T>(url, config)
+ };
+ }
+
+ // safeRequest builds its own pinned agent — drop the caller's httpsAgent
+ // and propagate ca / rejectUnauthorized via safeRequest's own options.
+ const toSafeOpts = (config: K8sRequestConfig) => {
+ const rest: AxiosRequestConfig = { ...config };
+ delete (rest as { httpsAgent?: https.Agent }).httpsAgent;
+ return {
+ ...rest,
+ // Only forward TLS overrides on direct API auth; Gateway auth method
+ // does not need a custom CA because traffic flows through the proxy.
+ ...(providerInputs.authMethod === KubernetesAuthMethod.Api && providerInputs.sslEnabled && providerInputs.ca
+ ? {
+ ca: providerInputs.ca,
+ rejectUnauthorized: providerInputs.sslRejectUnauthorized
+ }
+ : {})
+ };
+ };
+
+ return {
+ get: <T = unknown>(url: string, config: K8sRequestConfig) => safeRequest.get<T>(url, toSafeOpts(config)),
+ post: <T = unknown>(url: string, body: unknown, config: K8sRequestConfig) =>
+ safeRequest.post<T>(url, body, toSafeOpts(config)),
+ delete: <T = unknown>(url: string, config: K8sRequestConfig) => safeRequest.delete<T>(url, toSafeOpts(config))
+ };
+ };
+
const $gatewayProxyWrapper = async <T>(
inputs: {
gatewayId: string;
@@ -56,7 +110,12 @@ export const KubernetesProvider = ({
httpsAgent?: https.Agent;
reviewTokenThroughGateway: boolean;
},
- gatewayCallback: (host: string, port: number, httpsAgent?: https.Agent) => Promise<T>
+ gatewayCallback: (
+ host: string,
+ port: number,
+ httpsAgent: https.Agent | undefined,
+ isGatewayProxied: boolean
+ ) => Promise<T>
): Promise<T> => {
const gatewayV2ConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
gatewayId: inputs.gatewayId,
@@ -69,7 +128,8 @@ export const KubernetesProvider = ({
return gatewayCallback(
inputs.reviewTokenThroughGateway ? "http://localhost" : "https://localhost",
port,
- inputs.httpsAgent
+ inputs.httpsAgent,
+ true
);
},
{
@@ -92,7 +152,8 @@ export const KubernetesProvider = ({
const res = await gatewayCallback(
inputs.reviewTokenThroughGateway ? "http://localhost" : "https://localhost",
port,
- httpsAgent
+ httpsAgent,
+ true
);
return res;
},
@@ -122,12 +183,18 @@ export const KubernetesProvider = ({
usernamePrefix: "dynamic-secret-sa-"
});
- const serviceAccountDynamicCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
+ const serviceAccountDynamicCallback = async (
+ host: string,
+ port: number,
+ httpsAgent: https.Agent | undefined,
+ isGatewayProxied: boolean
+ ) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) {
throw new Error("invalid callback");
}
const baseUrl = port ? `${host}:${port}` : host;
+ const httpClient = k8sHttpClient(providerInputs, isGatewayProxied);
const roleBindingName = `${serviceAccountName}-role-binding`;
const namespaces = providerInputs.namespace.split(",").map((namespace) => namespace.trim());
@@ -136,7 +203,7 @@ export const KubernetesProvider = ({
for await (const namespace of namespaces) {
try {
// 1. Create a test service account
- await request.post(
+ await httpClient.post(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts`,
{
metadata: {
@@ -172,7 +239,7 @@ export const KubernetesProvider = ({
...(providerInputs.roleType !== KubernetesRoleType.ClusterRole && { namespace })
};
- await request.post(
+ await httpClient.post(
roleBindingUrl,
{
metadata: roleBindingMetadata,
@@ -207,7 +274,7 @@ export const KubernetesProvider = ({
);
// 3. Request a token for the test service account
- await request.post(
+ await httpClient.post(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}/token`,
{
spec: {
@@ -234,7 +301,7 @@ export const KubernetesProvider = ({
// 4. Cleanup: delete role binding and service account
if (providerInputs.roleType === KubernetesRoleType.Role) {
- await request.delete(
+ await httpClient.delete(
`${baseUrl}/apis/rbac.authorization.k8s.io/v1/namespaces/${namespace}/rolebindings/${roleBindingName}`,
{
headers: {
@@ -253,7 +320,7 @@ export const KubernetesProvider = ({
}
);
} else {
- await request.delete(
+ await httpClient.delete(
`${baseUrl}/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/${roleBindingName}`,
{
headers: {
@@ -273,7 +340,7 @@ export const KubernetesProvider = ({
);
}
- await request.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}`, {
+ await httpClient.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}`, {
headers: {
"Content-Type": "application/json",
...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
@@ -302,14 +369,20 @@ export const KubernetesProvider = ({
}
};
- const serviceAccountStaticCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
+ const serviceAccountStaticCallback = async (
+ host: string,
+ port: number,
+ httpsAgent: https.Agent | undefined,
+ isGatewayProxied: boolean
+ ) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Static) {
throw new Error("invalid callback");
}
const baseUrl = port ? `${host}:${port}` : host;
+ const httpClient = k8sHttpClient(providerInputs, isGatewayProxied);
- await request.get(
+ await httpClient.get(
`${baseUrl}/api/v1/namespaces/${providerInputs.namespace}/serviceaccounts/${providerInputs.serviceAccountName}`,
{
headers: {
@@ -374,9 +447,9 @@ export const KubernetesProvider = ({
);
}
} else if (providerInputs.credentialType === KubernetesCredentialType.Static) {
- await serviceAccountStaticCallback(k8sHost, k8sPort, httpsAgent);
+ await serviceAccountStaticCallback(k8sHost, k8sPort, httpsAgent, false);
} else {
- await serviceAccountDynamicCallback(k8sHost, k8sPort, httpsAgent);
+ await serviceAccountDynamicCallback(k8sHost, k8sPort, httpsAgent, false);
}
return true;
@@ -433,12 +506,18 @@ export const KubernetesProvider = ({
usernamePrefix: "dynamic-secret-sa-"
});
- const serviceAccountDynamicCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
+ const serviceAccountDynamicCallback = async (
+ host: string,
+ port: number,
+ httpsAgent: https.Agent | undefined,
+ isGatewayProxied: boolean
+ ) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) {
throw new Error("invalid callback");
}
const baseUrl = port ? `${host}:${port}` : host;
+ const httpClient = k8sHttpClient(providerInputs, isGatewayProxied);
const roleBindingName = `${serviceAccountName}-role-binding`;
const allowedNamespaces = providerInputs.namespace.split(",").map((namespace) => namespace.trim());
@@ -456,7 +535,7 @@ export const KubernetesProvider = ({
}
// 1. Create the service account
- await request.post(
+ await httpClient.post(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts`,
{
metadata: {
@@ -492,7 +571,7 @@ export const KubernetesProvider = ({
...(providerInputs.roleType !== KubernetesRoleType.ClusterRole && { namespace })
};
- await request.post(
+ await httpClient.post(
roleBindingUrl,
{
metadata: roleBindingMetadata,
@@ -527,7 +606,7 @@ export const KubernetesProvider = ({
);
// 3. Request a token for the service account
- const res = await request.post<TKubernetesTokenRequest>(
+ const res = await httpClient.post<TKubernetesTokenRequest>(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}/token`,
{
spec: {
@@ -555,7 +634,12 @@ export const KubernetesProvider = ({
return { ...res.data, serviceAccountName };
};
- const tokenRequestStaticCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
+ const tokenRequestStaticCallback = async (
+ host: string,
+ port: number,
+ httpsAgent: https.Agent | undefined,
+ isGatewayProxied: boolean
+ ) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Static) {
throw new Error("invalid callback");
}
@@ -567,8 +651,9 @@ export const KubernetesProvider = ({
}
const baseUrl = port ? `${host}:${port}` : host;
+ const httpClient = k8sHttpClient(providerInputs, isGatewayProxied);
- const res = await request.post<TKubernetesTokenRequest>(
+ const res = await httpClient.post<TKubernetesTokenRequest>(
`${baseUrl}/api/v1/namespaces/${providerInputs.namespace}/serviceaccounts/${providerInputs.serviceAccountName}/token`,
{
spec: {
@@ -645,8 +730,8 @@ export const KubernetesProvider = ({
} else {
tokenData =
providerInputs.credentialType === KubernetesCredentialType.Static
- ? await tokenRequestStaticCallback(k8sHost, k8sPort, httpsAgent)
- : await serviceAccountDynamicCallback(k8sHost, k8sPort, httpsAgent);
+ ? await tokenRequestStaticCallback(k8sHost, k8sPort, httpsAgent, false)
+ : await serviceAccountDynamicCallback(k8sHost, k8sPort, httpsAgent, false);
}
return {
@@ -688,18 +773,24 @@ export const KubernetesProvider = ({
) => {
const providerInputs = await validateProviderInputs(inputs);
- const serviceAccountDynamicCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
+ const serviceAccountDynamicCallback = async (
+ host: string,
+ port: number,
+ httpsAgent: https.Agent | undefined,
+ isGatewayProxied: boolean
+ ) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) {
throw new Error("invalid callback");
}
const baseUrl = port ? `${host}:${port}` : host;
+ const httpClient = k8sHttpClient(providerInputs, isGatewayProxied);
const roleBindingName = `${entityId}-role-binding`;
const namespace = config?.namespace ?? providerInputs.namespace.split(",")[0].trim();
if (providerInputs.roleType === KubernetesRoleType.Role) {
- await request.delete(
+ await httpClient.delete(
`${baseUrl}/apis/rbac.authorization.k8s.io/v1/namespaces/${namespace}/rolebindings/${roleBindingName}`,
{
headers: {
@@ -718,7 +809,7 @@ export const KubernetesProvider = ({
}
);
} else {
- await request.delete(`${baseUrl}/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/${roleBindingName}`, {
+ await httpClient.delete(`${baseUrl}/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/${roleBindingName}`, {
headers: {
"Content-Type": "application/json",
...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
@@ -736,7 +827,7 @@ export const KubernetesProvider = ({
}
// Delete the service account
- await request.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${entityId}`, {
+ await httpClient.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${entityId}`, {
headers: {
"Content-Type": "application/json",
...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
@@ -798,7 +889,7 @@ export const KubernetesProvider = ({
);
}
} else {
- await serviceAccountDynamicCallback(k8sHost, k8sPort, httpsAgent);
+ await serviceAccountDynamicCallback(k8sHost, k8sPort, httpsAgent, false);
}
} catch (error) {
let errorMessage = error instanceof Error ? error.message : "Unknown error";
diff --git a/backend/src/services/app-connection/github/github-connection-fns.ts b/backend/src/services/app-connection/github/github-connection-fns.ts
index 14f93ac427..bbe2759e15 100644
--- a/backend/src/services/app-connection/github/github-connection-fns.ts
+++ b/backend/src/services/app-connection/github/github-connection-fns.ts
@@ -19,6 +19,8 @@ import { AppConnection } from "../app-connection-enums";
import { GitHubConnectionMethod } from "./github-connection-enums";
import { TGitHubConnection, TGitHubConnectionConfig } from "./github-connection-types";
+export type TGitHubGatewayRequestConfig = AxiosRequestConfig & { url: string };
+
export const getGitHubConnectionListItem = () => {
const { INF_APP_CONNECTION_GITHUB_OAUTH_CLIENT_ID, INF_APP_CONNECTION_GITHUB_APP_SLUG } = getConfig();
@@ -73,17 +75,17 @@ export const requestWithGitHubGateway = async <T>(
appConnection: { gatewayId?: string | null },
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
- requestConfig: AxiosRequestConfig,
+ requestConfig: TGitHubGatewayRequestConfig,
gatewayConnectionDetails?: Awaited<ReturnType<TGatewayV2ServiceFactory["getPlatformConnectionDetailsByGatewayId"]>>
): Promise<AxiosResponse<T>> => {
const { gatewayId } = appConnection;
// If gateway isn't set up, don't proxy request
if (!gatewayId) {
- return safeRequest.request<T>({ ...requestConfig, url: requestConfig.url as string });
+ return safeRequest.request<T>(requestConfig);
}
- const url = new URL(requestConfig.url as string);
+ const url = new URL(requestConfig.url);
await blockLocalAndPrivateIpAddresses(url.toString());
diff --git a/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts
index 0be04f14af..6f2c99c404 100644
--- a/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts
+++ b/backend/src/services/app-connection/hc-vault/hc-vault-connection-fns.ts
@@ -35,6 +35,8 @@ import {
THCVaultMountResponse
} from "./hc-vault-connection-types";
+export type THCVaultGatewayRequestConfig = AxiosRequestConfig & { url: string };
+
// HashiCorp Vault stores JSON data, so values can be any valid JSON type
export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
@@ -130,16 +132,16 @@ export const requestWithHCVaultGateway = async <T>(
appConnection: { gatewayId?: string | null },
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">,
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
- requestConfig: AxiosRequestConfig,
+ requestConfig: THCVaultGatewayRequestConfig,
gatewayDetails?: TGatewayDetails
): Promise<AxiosResponse<T>> => {
const { gatewayId } = appConnection;
- const url = new URL(requestConfig.url as string);
+ const url = new URL(requestConfig.url);
// If gateway isn't set up, don't proxy request
if (!gatewayId) {
- return safeRequest.request<T>({ ...requestConfig, url: requestConfig.url as string });
+ return safeRequest.request<T>(requestConfig);
}
let gatewayConnectionDetailsV2: TGatewayV2ConnectionDetails | undefined;
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 dadb37b22b..2e71bc745d 100644
--- a/backend/src/services/app-connection/netscaler/netscaler-connection-fns.ts
+++ b/backend/src/services/app-connection/netscaler/netscaler-connection-fns.ts
@@ -13,6 +13,8 @@ import { AppConnection } from "@app/services/app-connection/app-connection-enums
import { NetScalerConnectionMethod } from "./netscaler-connection-enums";
import { TNetScalerConnectionConfig } from "./netscaler-connection-types";
+export type TNetScalerRequestConfig = AxiosRequestConfig & { url: string };
+
export const getNetScalerConnectionListItem = () => {
return {
name: "NetScaler" as const,
@@ -24,7 +26,7 @@ export const getNetScalerConnectionListItem = () => {
const requestWithNetScalerGateway = async <T>(
config: TNetScalerConnectionConfig,
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
- requestConfig: AxiosRequestConfig
+ requestConfig: TNetScalerRequestConfig
): Promise<T> => {
const { gatewayId, credentials } = config;
const { hostname, port: credPort } = credentials;
@@ -52,7 +54,7 @@ const requestWithNetScalerGateway = async <T>(
const proxyUrl = `https://localhost:${proxyPort}`;
const finalRequestConfig: AxiosRequestConfig = {
...requestConfig,
- url: requestConfig.url?.replace(`https://${hostname}:${port}`, proxyUrl),
+ url: requestConfig.url.replace(`https://${hostname}:${port}`, proxyUrl),
headers: {
...requestConfig.headers,
Host: hostname
@@ -74,7 +76,6 @@ const requestWithNetScalerGateway = async <T>(
const resp = await safeRequest.request<T>({
...requestConfig,
- url: requestConfig.url as string,
rejectUnauthorized: credentials.sslRejectUnauthorized,
ca: credentials.sslCertificate ? [credentials.sslCertificate] : undefined
});
@@ -141,7 +142,7 @@ export const executeNetScalerOperationWithGateway = async <T>(
credentials: TNetScalerConnectionConfig["credentials"];
},
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId"> | undefined,
- operation: (makeRequest: <R>(requestCfg: AxiosRequestConfig) => Promise<R>) => Promise<T>
+ operation: (makeRequest: <R>(requestCfg: TNetScalerRequestConfig) => Promise<R>) => Promise<T>
): Promise<T> => {
const { gatewayId, credentials } = config;
const { hostname, port: credPort } = credentials;
@@ -169,10 +170,10 @@ export const executeNetScalerOperationWithGateway = async <T>(
const proxyBaseUrl = `https://localhost:${proxyPort}`;
const targetBaseUrl = `https://${hostname}:${port}`;
- const makeRequest = async <R>(requestCfg: AxiosRequestConfig): Promise<R> => {
+ const makeRequest = async <R>(requestCfg: TNetScalerRequestConfig): Promise<R> => {
const resp = await request.request<R>({
...requestCfg,
- url: requestCfg.url?.replace(targetBaseUrl, proxyBaseUrl),
+ url: requestCfg.url.replace(targetBaseUrl, proxyBaseUrl),
headers: {
...requestCfg.headers,
Host: hostname
@@ -193,10 +194,9 @@ export const executeNetScalerOperationWithGateway = async <T>(
);
}
- const makeRequest = async <R>(requestCfg: AxiosRequestConfig): Promise<R> => {
+ const makeRequest = async <R>(requestCfg: TNetScalerRequestConfig): Promise<R> => {
const resp = await safeRequest.request<R>({
...requestCfg,
- url: requestCfg.url as string,
rejectUnauthorized: credentials.sslRejectUnauthorized,
ca: credentials.sslCertificate ? [credentials.sslCertificate] : undefined
});
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 33f4c417a9..0745968cc0 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
@@ -15,6 +15,8 @@ import { AppConnection } from "@app/services/app-connection/app-connection-enums
import { VenafiTppConnectionMethod } from "./venafi-tpp-connection-enums";
import { TVenafiTppConnectionConfig } from "./venafi-tpp-connection-types";
+export type TVenafiTppGatewayRequestConfig = AxiosRequestConfig & { url: string };
+
type TVenafiTppCredentials = {
tppUrl: string;
clientId: string;
@@ -46,15 +48,15 @@ const normalizeTppUrl = (tppUrl: string): string => {
export const requestWithVenafiTppGateway = async <T>(
appConnection: { gatewayId?: string | null },
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">,
- requestConfig: AxiosRequestConfig
+ requestConfig: TVenafiTppGatewayRequestConfig
): Promise<AxiosResponse<T>> => {
const { gatewayId } = appConnection;
- const url = new URL(requestConfig.url as string);
+ const url = new URL(requestConfig.url);
// Non-gateway path: use safeRequest to validate and pin the connection.
if (!gatewayId) {
- return safeRequest.request<T>({ ...requestConfig, url: requestConfig.url as string });
+ return safeRequest.request<T>(requestConfig);
}
const [targetHost] = await verifyHostInputValidity({ host: url.hostname, isGateway: true, isDynamicSecret: false });
diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
index f249a3fafe..8547e6367b 100644
--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts
@@ -49,6 +49,7 @@ import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
import { RequestContextKey } from "@app/lib/request-context/request-context-keys";
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { AuthAttemptAuthMethod, AuthAttemptAuthResult, authAttemptCounter } from "@app/lib/telemetry/metrics";
+import { safeRequest } from "@app/lib/validator";
import { ActorType, AuthTokenType } from "../auth/auth-type";
import { TIdentityDALFactory } from "../identity/identity-dal";
@@ -336,7 +337,8 @@ export const identityKubernetesAuthServiceFactory = ({
const baseUrl = port ? `${host}:${port}` : host;
- const res = await request
+ const isGatewayProxied = port !== undefined;
+ const res = await safeRequest
.post<TCreateTokenReviewResponse>(
`${baseUrl}/apis/authentication.k8s.io/v1/tokenreviews`,
{
@@ -356,11 +358,10 @@ export const identityKubernetesAuthServiceFactory = ({
},
signal: AbortSignal.timeout(10000),
timeout: 10000,
- httpsAgent: new https.Agent({
- ca: caCert || undefined,
- rejectUnauthorized: true,
- servername
- })
+ allowPrivateIps: isGatewayProxied,
+ ca: caCert || undefined,
+ rejectUnauthorized: true,
+ servername
}
)
.catch((err) => {
diff --git a/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.ts b/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.ts
index 9d2aaa8bd8..56c1a3ea7f 100644
--- a/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.ts
+++ b/backend/src/services/pki-sync/netscaler/netscaler-pki-sync-fns.ts
@@ -1,12 +1,15 @@
/* eslint-disable no-await-in-loop */
-import { AxiosError, AxiosRequestConfig } from "axios";
+import { AxiosError } from "axios";
import handlebars from "handlebars";
import RE2 from "re2";
import { TCertificateSyncs } from "@app/db/schemas";
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { logger } from "@app/lib/logger";
-import { executeNetScalerOperationWithGateway } from "@app/services/app-connection/netscaler/netscaler-connection-fns";
+import {
+ executeNetScalerOperationWithGateway,
+ TNetScalerRequestConfig
+} from "@app/services/app-connection/netscaler/netscaler-connection-fns";
import { TNetScalerConnection } from "@app/services/app-connection/netscaler/netscaler-connection-types";
import { TCertificateDALFactory } from "@app/services/certificate/certificate-dal";
import { TCertificateSyncDALFactory } from "@app/services/certificate-sync/certificate-sync-dal";
@@ -19,7 +22,7 @@ import { TNetScalerPkiSyncConfig } from "./netscaler-pki-sync-types";
type TNetScalerCredentials = TNetScalerConnection["credentials"];
-type TRequestFn = <R>(requestCfg: AxiosRequestConfig) => Promise<R>;
+type TRequestFn = <R>(requestCfg: TNetScalerRequestConfig) => Promise<R>;
type TNetScalerSession = {
baseUrl: string;