Skip to content

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

feat: updated default config for request

=c5c508619a76
diff --git a/backend/src/ee/services/ai-mcp-server/ai-mcp-server-service.ts b/backend/src/ee/services/ai-mcp-server/ai-mcp-server-service.ts
index 859162d7ee..570b99acf7 100644
--- a/backend/src/ee/services/ai-mcp-server/ai-mcp-server-service.ts
+++ b/backend/src/ee/services/ai-mcp-server/ai-mcp-server-service.ts
@@ -7,7 +7,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - MCP SDK uses ESM with .js extensions which don't resolve types with moduleResolution: "Node"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
-import axios from "axios";
+import { isAxiosError } from "axios";
import { ActionProjectType, OrganizationActionScope } from "@app/db/schemas";
import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";
@@ -441,7 +441,7 @@ export const aiMcpServerServiceFactory = ({
}
} catch (err) {
// Log non-404 errors for debugging, but still fall through
- if (!axios.isAxiosError(err) || err.response?.status !== 404) {
+ if (!isAxiosError(err) || err.response?.status !== 404) {
logger.warn(err, "Failed to fetch OAuth authorization server metadata");
}
}
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 d9250b29cd..47dc1a24ee 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
@@ -29,7 +29,8 @@ export const CustomProviderFactory = () => {
{ ping: "ok" },
{
headers: streamHeaders,
- timeout: AUDIT_LOG_STREAM_TIMEOUT
+ timeout: AUDIT_LOG_STREAM_TIMEOUT,
+ maxRedirects: 0
}
)
.catch((err) => {
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 98386c4d37..cc72f268b3 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,6 +1,6 @@
-import axios from "axios";
import { customAlphabet } from "nanoid";
+import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { sanitizeString } from "@app/lib/fn";
@@ -29,7 +29,7 @@ export const AzureEntraIDProvider = (): TDynamicProviderFns & {
applicationId: string,
clientSecret: string
): Promise<{ token?: string; success: boolean }> => {
- const response = await axios.post<{ access_token: string }>(
+ const response = await request.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 axios.patch(
+ const response = await request.patch(
`${MSFT_GRAPH_API_URL}/users/${providerInputs.userId}`,
{
passwordProfile: {
@@ -136,7 +136,7 @@ export const AzureEntraIDProvider = (): TDynamicProviderFns & {
throw new BadRequestError({ message: "Failed to authorize to Microsoft Entra ID" });
}
- const response = await axios.get<{ value: [{ id: string; displayName: string; userPrincipalName: string }] }>(
+ const response = await request.get<{ value: [{ id: string; displayName: string; userPrincipalName: string }] }>(
`${MSFT_GRAPH_API_URL}/users`,
{
headers: {
diff --git a/backend/src/ee/services/dynamic-secret/providers/couchbase.ts b/backend/src/ee/services/dynamic-secret/providers/couchbase.ts
index 090eb549b2..06ed1c38e9 100644
--- a/backend/src/ee/services/dynamic-secret/providers/couchbase.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/couchbase.ts
@@ -1,9 +1,9 @@
import crypto from "node:crypto";
-import axios from "axios";
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";
@@ -159,7 +159,7 @@ const couchbaseApiRequest = async (
await blockLocalAndPrivateIpAddresses(url);
try {
- const response = await axios({
+ const response = await request({
method: method.toLowerCase() as "get" | "post" | "put" | "delete",
url,
headers: {
@@ -167,7 +167,8 @@ const couchbaseApiRequest = async (
"Content-Type": "application/json"
},
data: data || undefined,
- timeout: 30000
+ timeout: 30000,
+ maxRedirects: 0
});
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 d3259064ae..408189f56c 100644
--- a/backend/src/ee/services/dynamic-secret/providers/github.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/github.ts
@@ -1,6 +1,7 @@
-import axios from "axios";
+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";
@@ -56,7 +57,7 @@ export const GithubProvider = (): TDynamicProviderFns => {
const tokenUrl = `${IntegrationUrls.GITHUB_API_URL}/app/installations/${String(installationId)}/access_tokens`;
try {
- const response = await axios.post<GitHubInstallationTokenResponse>(tokenUrl, undefined, {
+ const response = await request.post<GitHubInstallationTokenResponse>(tokenUrl, undefined, {
headers: {
Authorization: `Bearer ${appJwt}`,
Accept: "application/vnd.github.v3+json",
@@ -73,7 +74,7 @@ export const GithubProvider = (): TDynamicProviderFns => {
});
} catch (error) {
let message = "Failed to fetch GitHub installation access token.";
- if (axios.isAxiosError(error) && error.response) {
+ if (isAxiosError(error) && error.response) {
const githubErrorMsg =
(error.response.data as { message?: string })?.message || JSON.stringify(error.response.data);
message += ` GitHub API Error: ${error.response.status} - ${githubErrorMsg}`;
diff --git a/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts b/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts
index a9b9cf1c27..74cc02c1c0 100644
--- a/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/kubernetes.ts
@@ -1,7 +1,8 @@
-import axios, { AxiosError } from "axios";
+import { AxiosError, isAxiosError } from "axios";
import https from "https";
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 { GatewayHttpProxyActions, GatewayProxyProtocol, withGatewayProxy } from "@app/lib/gateway";
@@ -135,7 +136,7 @@ export const KubernetesProvider = ({
for await (const namespace of namespaces) {
try {
// 1. Create a test service account
- await axios.post(
+ await request.post(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts`,
{
metadata: {
@@ -171,7 +172,7 @@ export const KubernetesProvider = ({
...(providerInputs.roleType !== KubernetesRoleType.ClusterRole && { namespace })
};
- await axios.post(
+ await request.post(
roleBindingUrl,
{
metadata: roleBindingMetadata,
@@ -206,7 +207,7 @@ export const KubernetesProvider = ({
);
// 3. Request a token for the test service account
- await axios.post(
+ await request.post(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}/token`,
{
spec: {
@@ -233,7 +234,7 @@ export const KubernetesProvider = ({
// 4. Cleanup: delete role binding and service account
if (providerInputs.roleType === KubernetesRoleType.Role) {
- await axios.delete(
+ await request.delete(
`${baseUrl}/apis/rbac.authorization.k8s.io/v1/namespaces/${namespace}/rolebindings/${roleBindingName}`,
{
headers: {
@@ -252,24 +253,27 @@ export const KubernetesProvider = ({
}
);
} else {
- await axios.delete(`${baseUrl}/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/${roleBindingName}`, {
- headers: {
- "Content-Type": "application/json",
- ...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
- ? { "x-infisical-action": GatewayHttpProxyActions.UseGatewayK8sServiceAccount }
- : { Authorization: `Bearer ${providerInputs.clusterToken}` })
- },
- ...(providerInputs.authMethod === KubernetesAuthMethod.Api
- ? {
- httpsAgent
- }
- : {}),
- signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
- timeout: EXTERNAL_REQUEST_TIMEOUT
- });
+ await request.delete(
+ `${baseUrl}/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/${roleBindingName}`,
+ {
+ headers: {
+ "Content-Type": "application/json",
+ ...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
+ ? { "x-infisical-action": GatewayHttpProxyActions.UseGatewayK8sServiceAccount }
+ : { Authorization: `Bearer ${providerInputs.clusterToken}` })
+ },
+ ...(providerInputs.authMethod === KubernetesAuthMethod.Api
+ ? {
+ httpsAgent
+ }
+ : {}),
+ signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
+ timeout: EXTERNAL_REQUEST_TIMEOUT
+ }
+ );
}
- await axios.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}`, {
+ await request.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}`, {
headers: {
"Content-Type": "application/json",
...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
@@ -305,7 +309,7 @@ export const KubernetesProvider = ({
const baseUrl = port ? `${host}:${port}` : host;
- await axios.get(
+ await request.get(
`${baseUrl}/api/v1/namespaces/${providerInputs.namespace}/serviceaccounts/${providerInputs.serviceAccountName}`,
{
headers: {
@@ -378,7 +382,7 @@ export const KubernetesProvider = ({
return true;
} catch (error) {
let errorMessage = error instanceof Error ? error.message : "Unknown error";
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
if (error.response) {
let { message } = error?.response?.data as unknown as { message?: string };
@@ -452,7 +456,7 @@ export const KubernetesProvider = ({
}
// 1. Create the service account
- await axios.post(
+ await request.post(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts`,
{
metadata: {
@@ -488,7 +492,7 @@ export const KubernetesProvider = ({
...(providerInputs.roleType !== KubernetesRoleType.ClusterRole && { namespace })
};
- await axios.post(
+ await request.post(
roleBindingUrl,
{
metadata: roleBindingMetadata,
@@ -523,7 +527,7 @@ export const KubernetesProvider = ({
);
// 3. Request a token for the service account
- const res = await axios.post<TKubernetesTokenRequest>(
+ const res = await request.post<TKubernetesTokenRequest>(
`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${serviceAccountName}/token`,
{
spec: {
@@ -564,7 +568,7 @@ export const KubernetesProvider = ({
const baseUrl = port ? `${host}:${port}` : host;
- const res = await axios.post<TKubernetesTokenRequest>(
+ const res = await request.post<TKubernetesTokenRequest>(
`${baseUrl}/api/v1/namespaces/${providerInputs.namespace}/serviceaccounts/${providerInputs.serviceAccountName}/token`,
{
spec: {
@@ -651,7 +655,7 @@ export const KubernetesProvider = ({
};
} catch (error) {
let errorMessage = error instanceof Error ? error.message : "Unknown error";
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
if (error.response) {
let { message } = error?.response?.data as unknown as { message?: string };
@@ -695,7 +699,7 @@ export const KubernetesProvider = ({
const namespace = config?.namespace ?? providerInputs.namespace.split(",")[0].trim();
if (providerInputs.roleType === KubernetesRoleType.Role) {
- await axios.delete(
+ await request.delete(
`${baseUrl}/apis/rbac.authorization.k8s.io/v1/namespaces/${namespace}/rolebindings/${roleBindingName}`,
{
headers: {
@@ -714,7 +718,7 @@ export const KubernetesProvider = ({
}
);
} else {
- await axios.delete(`${baseUrl}/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/${roleBindingName}`, {
+ await request.delete(`${baseUrl}/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/${roleBindingName}`, {
headers: {
"Content-Type": "application/json",
...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
@@ -732,7 +736,7 @@ export const KubernetesProvider = ({
}
// Delete the service account
- await axios.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${entityId}`, {
+ await request.delete(`${baseUrl}/api/v1/namespaces/${namespace}/serviceaccounts/${entityId}`, {
headers: {
"Content-Type": "application/json",
...(providerInputs.authMethod === KubernetesAuthMethod.Gateway
@@ -798,7 +802,7 @@ export const KubernetesProvider = ({
}
} catch (error) {
let errorMessage = error instanceof Error ? error.message : "Unknown error";
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
if (error.response) {
let { message } = error?.response?.data as unknown as { message?: string };
diff --git a/backend/src/ee/services/dynamic-secret/providers/mongo-atlas.ts b/backend/src/ee/services/dynamic-secret/providers/mongo-atlas.ts
index b4d296f8e1..163a7302ff 100644
--- a/backend/src/ee/services/dynamic-secret/providers/mongo-atlas.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/mongo-atlas.ts
@@ -28,7 +28,8 @@ export const MongoAtlasProvider = (): TDynamicProviderFns => {
headers: {
Accept: "application/vnd.atlas.2023-02-01+json",
"Content-Type": "application/json"
- }
+ },
+ maxRedirects: 0
});
const digestAuth = createDigestAuthRequestInterceptor(
client,
diff --git a/backend/src/ee/services/dynamic-secret/providers/rabbit-mq.ts b/backend/src/ee/services/dynamic-secret/providers/rabbit-mq.ts
index 639453bf31..f1d8dbf445 100644
--- a/backend/src/ee/services/dynamic-secret/providers/rabbit-mq.ts
+++ b/backend/src/ee/services/dynamic-secret/providers/rabbit-mq.ts
@@ -92,7 +92,7 @@ export const RabbitMqProvider = (): TDynamicProviderFns => {
headers: {
"Content-Type": "application/json"
},
-
+ maxRedirects: 0,
...(providerInputs.ca && {
httpsAgent: new https.Agent({ ca: providerInputs.ca, rejectUnauthorized: false })
})
diff --git a/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-factory.ts b/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-factory.ts
index ab847ca87a..d58e6e19f0 100644
--- a/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-factory.ts
+++ b/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-factory.ts
@@ -1,6 +1,7 @@
-import axios, { AxiosError } from "axios";
+import { AxiosError } from "axios";
import https from "https";
+import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { GatewayHttpProxyActions, GatewayProxyProtocol } from "@app/lib/gateway/types";
import { withGatewayV2Proxy } from "@app/lib/gateway-v2/gateway-v2";
@@ -119,7 +120,7 @@ export const kubernetesResourceFactory: TPamResourceFactory<
async (baseUrl, httpsAgent) => {
// Validate connection by checking API server version
try {
- await axios.get(`${baseUrl}/version`, {
+ await request.get(`${baseUrl}/version`, {
...(httpsAgent ? { httpsAgent } : {}),
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT
@@ -171,7 +172,7 @@ export const kubernetesResourceFactory: TPamResourceFactory<
// Validate service account token using SelfSubjectReview API (whoami)
// This endpoint doesn't require any special permissions from the service account
try {
- await axios.post(
+ await request.post(
`${baseUrl}/apis/authentication.k8s.io/v1/selfsubjectreviews`,
{
apiVersion: "authentication.k8s.io/v1",
@@ -227,7 +228,7 @@ export const kubernetesResourceFactory: TPamResourceFactory<
await validateWithGatewayHttp({ gatewayId }, gatewayV2Service, async (baseUrl) => {
const impersonateUser = `system:serviceaccount:${credentials.namespace}:${credentials.serviceAccountName}`;
try {
- await axios.post(
+ await request.post(
`${baseUrl}/apis/authentication.k8s.io/v1/selfsubjectreviews`,
{
apiVersion: "authentication.k8s.io/v1",
diff --git a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
index 2649e0a110..4a053979d4 100644
--- a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
+++ b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts
@@ -1,9 +1,10 @@
import { resolve4, Resolver } from "node:dns/promises";
-import axios, { AxiosError } from "axios";
+import { AxiosError, isAxiosError } from "axios";
import { TPkiAcmeChallenges } from "@app/db/schemas/pki-acme-challenges";
import { getConfig } from "@app/lib/config/env";
+import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError, NotFoundError } from "@app/lib/errors";
import { isValidIp } from "@app/lib/ip";
@@ -96,7 +97,7 @@ export const pkiAcmeChallengeServiceFactory = ({
// Notice: well, we are in a transaction, ideally we should not hold transaction and perform
// a long running operation for long time. But assuming we are not performing a tons of
// challenge validation at the same time, it should be fine.
- const challengeResponse = await axios.get<string>(challengeUrl.toString(), {
+ const challengeResponse = await request.get<string>(challengeUrl.toString(), {
// In case if we override the host in the development mode, still provide the original host in the header
// to help the upstream server to validate the request
headers: {
@@ -175,7 +176,7 @@ export const pkiAcmeChallengeServiceFactory = ({
try {
// Properly type and inspect the error
- if (axios.isAxiosError(exp)) {
+ if (isAxiosError(exp)) {
const axiosError = exp as AxiosError;
const errorCode = axiosError.code;
const errorMessage = axiosError.message;
diff --git a/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts b/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts
index 8cc7dac4ba..8d30686b25 100644
--- a/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts
+++ b/backend/src/ee/services/secret-rotation/secret-rotation-queue/secret-rotation-queue-fn.ts
@@ -4,14 +4,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-param-reassign */
-import axios from "axios";
-import jmespath from "jmespath";
import knex from "knex";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { verifyHostInputValidity } from "../../dynamic-secret/dynamic-secret-fns";
-import { TAssignOp, TDbProviderClients, TDirectAssignOp, THttpProviderFunction } from "../templates/types";
+import { TDbProviderClients, TDirectAssignOp } from "../templates/types";
import { TSecretRotationData, TSecretRotationDbFn } from "./secret-rotation-queue-types";
const EXTERNAL_REQUEST_TIMEOUT = 10 * 1000;
@@ -86,21 +84,7 @@ const getInterpolationValue = (variables: TSecretRotationData) => (key: string)
return variables[type as keyof TSecretRotationData][keyName];
};
-export const secretRotationHttpFn = async (func: THttpProviderFunction, variables: TSecretRotationData) => {
- // string interpolation
- const headers = interpolate(func.header, getInterpolationValue(variables));
- const url = interpolate(func.url, getInterpolationValue(variables));
- const body = interpolate(func.body, getInterpolationValue(variables));
- // axios will automatically throw error if req status is not between 2xx range
- return axios({
- method: func.method,
- url,
- headers,
- data: body,
- timeout: EXTERNAL_REQUEST_TIMEOUT,
- signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT)
- });
-};
+export const secretRotationHttpFn = async () => {};
export const secretRotationDbFn = async ({
ca,
@@ -142,19 +126,7 @@ export const secretRotationPreSetFn = (op: Record<string, TDirectAssignOp>, vari
});
};
-export const secretRotationHttpSetFn = async (func: THttpProviderFunction, variables: TSecretRotationData) => {
- const getValFn = getInterpolationValue(variables);
- // http setter
- const res = await secretRotationHttpFn(func, variables);
- Object.entries(func.setter || {}).forEach(([key, assignFn]) => {
- const [type, keyName] = key.split(".") as [keyof TSecretRotationData, string];
- if (assignFn.assign === TAssignOp.JmesPath) {
- variables[type][keyName] = jmespath.search(res.data, assignFn.path);
- } else if (assignFn.value) {
- variables[type][keyName] = interpolate(assignFn.value, getValFn);
- }
- });
-};
+export const secretRotationHttpSetFn = async () => {};
export const getDbSetQuery = (db: TDbProviderClients, variables: { username: string; password: string }) => {
if (db === TDbProviderClients.Pg) {
diff --git a/backend/src/lib/config/request.ts b/backend/src/lib/config/request.ts
index b8bd4b282b..e45874db7d 100644
--- a/backend/src/lib/config/request.ts
+++ b/backend/src/lib/config/request.ts
@@ -26,7 +26,7 @@ export function axiosResponseInterceptor(response: AxiosResponse, customLogger:
}
export function createRequestClient(defaults: CreateAxiosDefaults = {}, retry: IAxiosRetryConfig = {}): AxiosInstance {
- const client = axios.create(defaults);
+ const client = axios.create({ ...defaults, maxRedirects: 0 });
client.interceptors.response.use((response) => axiosResponseInterceptor(response, logger));
diff --git a/backend/src/lib/gateway-v2/gateway-v2.ts b/backend/src/lib/gateway-v2/gateway-v2.ts
index 16eb8e8ca7..3a5a7fcc96 100644
--- a/backend/src/lib/gateway-v2/gateway-v2.ts
+++ b/backend/src/lib/gateway-v2/gateway-v2.ts
@@ -1,7 +1,7 @@
import net from "node:net";
import tls from "node:tls";
-import axios from "axios";
+import { isAxiosError } from "axios";
import https from "https";
import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";
@@ -287,7 +287,7 @@ export const withGatewayV2Proxy = async <T>(
}
logger.error("Gateway error:", err instanceof Error ? err.message : String(err));
let errorMessage = relayErrorMessage || (err instanceof Error ? err.message : String(err));
- if (axios.isAxiosError(err) && (err.response?.data as { message?: string })?.message) {
+ if (isAxiosError(err) && (err.response?.data as { message?: string })?.message) {
errorMessage = (err.response?.data as { message: string }).message;
}
diff --git a/backend/src/lib/gateway/gateway.ts b/backend/src/lib/gateway/gateway.ts
index 9a4dd789b1..f5d551fa23 100644
--- a/backend/src/lib/gateway/gateway.ts
+++ b/backend/src/lib/gateway/gateway.ts
@@ -2,7 +2,7 @@
import net from "node:net";
import quicDefault, * as quicModule from "@infisical/quic";
-import axios from "axios";
+import { isAxiosError } from "axios";
import https from "https";
import { crypto } from "@app/lib/crypto/cryptography";
@@ -417,7 +417,7 @@ export const withGatewayProxy = async <T>(
}
logger.error(err, "Failed to do gateway");
let errorMessage = proxyErrorMessage || (err as Error)?.message;
- if (axios.isAxiosError(err) && (err.response?.data as { message?: string })?.message) {
+ if (isAxiosError(err) && (err.response?.data as { message?: string })?.message) {
errorMessage = (err.response?.data as { message: string }).message;
}
diff --git a/backend/src/services/app-connection/dbt/dbt-connection-fns.ts b/backend/src/services/app-connection/dbt/dbt-connection-fns.ts
index 4ce9d3cbb0..d059ece14e 100644
--- a/backend/src/services/app-connection/dbt/dbt-connection-fns.ts
+++ b/backend/src/services/app-connection/dbt/dbt-connection-fns.ts
@@ -1,6 +1,7 @@
/* eslint-disable no-await-in-loop */
-import axios, { AxiosError } from "axios";
+import { AxiosError } from "axios";
+import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
@@ -53,7 +54,7 @@ export const retrieveDbtAccount = async (config: TDbtConnectionConfig) => {
const dbtUrl = await getDbtUrl(config);
- await axios.get(`${dbtUrl}/api/v2/accounts/${credentials.accountId}/`, {
+ await request.get(`${dbtUrl}/api/v2/accounts/${credentials.accountId}/`, {
headers: {
Authorization: `Bearer ${credentials.apiToken}`
}
@@ -90,7 +91,7 @@ export const listDbtProjects = async (config: TDbtConnectionConfig) => {
const dbtUrl = await getDbtUrl(config);
- const res = await axios.get<TDbtListProjectsResponse>(
+ const res = await request.get<TDbtListProjectsResponse>(
`${dbtUrl}/api/v3/accounts/${credentials.accountId}/projects`,
{
headers: {
diff --git a/backend/src/services/certificate-authority/acme/dns-providers/azure-dns.ts b/backend/src/services/certificate-authority/acme/dns-providers/azure-dns.ts
index 6f8e80d154..03fdcee5ed 100644
--- a/backend/src/services/certificate-authority/acme/dns-providers/azure-dns.ts
+++ b/backend/src/services/certificate-authority/acme/dns-providers/azure-dns.ts
@@ -1,4 +1,4 @@
-import axios from "axios";
+import { isAxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { logger } from "@app/lib/logger";
@@ -41,7 +41,7 @@ export const azureDnsInsertTxtRecord = async (
}
);
} catch (error) {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const errorMessage = (error.response?.data?.error?.message || error.message || "Unknown error") as string;
throw new Error(typeof errorMessage === "string" ? errorMessage : String(errorMessage));
@@ -75,7 +75,7 @@ export const azureDnsDeleteTxtRecord = async (
}
);
} catch (error) {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
if (error.response?.status === 404) {
logger.warn({ hostedZoneId, recordName, value }, "TXT record not found for deletion");
return;
diff --git a/backend/src/services/certificate-authority/acme/dns-providers/cloudflare.ts b/backend/src/services/certificate-authority/acme/dns-providers/cloudflare.ts
index 10de8c6c8a..d9b6d088b5 100644
--- a/backend/src/services/certificate-authority/acme/dns-providers/cloudflare.ts
+++ b/backend/src/services/certificate-authority/acme/dns-providers/cloudflare.ts
@@ -1,5 +1,6 @@
/* eslint-disable no-await-in-loop */
-import axios from "axios";
+
+import { isAxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { TCloudflareConnectionConfig } from "@app/services/app-connection/cloudflare/cloudflare-connection-types";
@@ -34,7 +35,7 @@ export const cloudflareInsertTxtRecord = async (
}
);
} catch (error) {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
const firstErrorMessage = (
error.response?.data as {
errors?: { message: string }[];
@@ -125,7 +126,7 @@ export const cloudflareDeleteTxtRecord = async (
}
if (lastError) {
- if (axios.isAxiosError(lastError)) {
+ if (isAxiosError(lastError)) {
const firstErrorMessage = (
lastError.response?.data as {
errors?: { message: string }[];
diff --git a/backend/src/services/certificate-authority/acme/dns-providers/dns-made-easy.ts b/backend/src/services/certificate-authority/acme/dns-providers/dns-made-easy.ts
index cbfb26a2ec..d54c67f293 100644
--- a/backend/src/services/certificate-authority/acme/dns-providers/dns-made-easy.ts
+++ b/backend/src/services/certificate-authority/acme/dns-providers/dns-made-easy.ts
@@ -1,4 +1,4 @@
-import axios from "axios";
+import { isAxiosError } from "axios";
import { request } from "@app/lib/config/request";
import { logger } from "@app/lib/logger";
@@ -38,7 +38,7 @@ export const dnsMadeEasyInsertTxtRecord = async (
}
);
} catch (error) {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
const errorMessage =
(error.response?.data as { error?: string[] | string })?.error?.[0] ||
(error.response?.data as { error?: string[] | string })?.error ||
@@ -93,7 +93,7 @@ export const dnsMadeEasyDeleteTxtRecord = async (
logger.warn({ hostedZoneId, domain, value }, "Record to delete not found");
}
} catch (error) {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
const errorMessage =
(error.response?.data as { error?: string[] | string })?.error?.[0] ||
(error.response?.data as { error?: string[] | string })?.error ||
diff --git a/backend/src/services/external-migration/external-migration-fns/vault.ts b/backend/src/services/external-migration/external-migration-fns/vault.ts
index e84284cdc1..97171bf261 100644
--- a/backend/src/services/external-migration/external-migration-fns/vault.ts
+++ b/backend/src/services/external-migration/external-migration-fns/vault.ts
@@ -1,6 +1,6 @@
import https from "node:https";
-import axios, { AxiosInstance } from "axios";
+import axios, { AxiosInstance, isAxiosError } from "axios";
import { v4 as uuidv4 } from "uuid";
import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";
@@ -51,7 +51,7 @@ const vaultFactory = (gatewayService: Pick<TGatewayServiceFactory, "fnGetGateway
data: Record<string, { accessor: string; options: { version?: string } | null; type: string }>;
}>("/v1/sys/mounts")
.catch((err) => {
- if (axios.isAxiosError(err)) {
+ if (isAxiosError(err)) {
logger.error(err.response?.data, "External migration: Failed to get Vault mounts");
}
throw err;
@@ -87,7 +87,7 @@ const vaultFactory = (gatewayService: Pick<TGatewayServiceFactory, "fnGetGateway
return response.data.data.keys;
} catch (err) {
- if (axios.isAxiosError(err)) {
+ if (isAxiosError(err)) {
logger.error(err.response?.data, "External migration: Failed to get Vault paths");
if (err.response?.status === 404) {
return null;
@@ -117,7 +117,7 @@ const vaultFactory = (gatewayService: Pick<TGatewayServiceFactory, "fnGetGateway
};
}>(`/v1/${mountPath}/data/${secretPath}`)
.catch((err) => {
- if (axios.isAxiosError(err)) {
+ if (isAxiosError(err)) {
// handle soft-deleted secrets (Vault returns 404 with metadata for soft deleted secrets)
const vaultResponse = err.response?.data as { data?: { metadata?: { deletion_time?: string } } };
@@ -152,7 +152,7 @@ const vaultFactory = (gatewayService: Pick<TGatewayServiceFactory, "fnGetGateway
renewable: boolean;
}>(`/v1/${mountPath}/${secretPath}`)
.catch((err) => {
- if (axios.isAxiosError(err)) {
+ if (isAxiosError(err)) {
logger.error(err.response?.data, "External migration: Failed to get Vault secret");
}
throw err;
@@ -285,6 +285,7 @@ const vaultFactory = (gatewayService: Pick<TGatewayServiceFactory, "fnGetGateway
getData
);
} else {
+ await blockLocalAndPrivateIpAddresses(baseUrl);
data = await getData(baseUrl);
}
diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
index b77b94be34..16e22b6fb8 100644
--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts
@@ -2,7 +2,6 @@
import { ForbiddenError, subject } from "@casl/ability";
import { requestContext } from "@fastify/request-context";
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
-import axios from "axios";
import RE2 from "re2";
import { AccessScope, ActionProjectType, IdentityAuthMethod, OrganizationActionScope } from "@app/db/schemas";
@@ -15,6 +14,7 @@ import {
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { getConfig } from "@app/lib/config/env";
+import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto";
import {
BadRequestError,
@@ -67,7 +67,7 @@ const awsRegionFromHeader = (authorizationHeader: string): string | null => {
// SignedHeaders=content-length;content-type;host;x-amz-date,
// Signature=fe5f80f77d5fa3beca038a248ff027d0445342fe2855ddc963176630326f1024
//
- // The credential is in the form of "<your-access-key-id>/<date>/<aws-region>/<aws-service>/aws4_request"
+ // The credential is in the form of "<your-access-key-id>/<date>/<aws-region>/<aws-service>/aws4_request"xi
try {
const fields = authorizationHeader.split(" ");
for (const field of fields) {
@@ -146,7 +146,7 @@ export const identityAwsAuthServiceFactory = ({
GetCallerIdentityResult: { Account, Arn, UserId }
}
}
- }: { data: TGetCallerIdentityResponse } = await axios({
+ }: { data: TGetCallerIdentityResponse } = await request({
method: iamHttpRequestMethod,
url,
headers,
diff --git a/backend/src/services/identity-azure-auth/identity-azure-auth-fns.ts b/backend/src/services/identity-azure-auth/identity-azure-auth-fns.ts
index cb06f3d405..636b6d92e4 100644
--- a/backend/src/services/identity-azure-auth/identity-azure-auth-fns.ts
+++ b/backend/src/services/identity-azure-auth/identity-azure-auth-fns.ts
@@ -1,5 +1,4 @@
-import axios from "axios";
-
+import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto";
import { UnauthorizedError } from "@app/lib/errors";
@@ -20,7 +19,7 @@ export const validateAzureIdentity = async ({
const { kid } = decodedJwt.header;
- const { data }: { data: TAzureJwksUriResponse } = await axios.get(jwksUri);
+ const { data }: { data: TAzureJwksUriResponse } = await request.get(jwksUri);
const signingKeys = data.keys;
const signingKey = signingKeys.find((key) => key.kid === kid);
diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
index 958a54e0ab..4864158608 100644
--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-fns.ts
@@ -1,7 +1,7 @@
-import axios from "axios";
import { OAuth2Client } from "google-auth-library";
import RE2 from "re2";
+import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto";
import { UnauthorizedError } from "@app/lib/errors";
@@ -64,7 +64,7 @@ export const validateIamIdentity = async ({
data: {
[key: string]: string;
};
- } = await axios.get(`https://www.googleapis.com/service_accounts/v1/metadata/x509/${encodeURIComponent(sub)}`);
+ } = await request.get(`https://www.googleapis.com/service_accounts/v1/metadata/x509/${encodeURIComponent(sub)}`);
const publicKey = data[decodedJwt.header.kid];
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 dac0274e09..b1541a4e14 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
@@ -1,6 +1,6 @@
import { ForbiddenError, subject } from "@casl/ability";
import { requestContext } from "@fastify/request-context";
-import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
+import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
import https from "https";
import picomatch from "picomatch";
import RE2 from "re2";
@@ -313,7 +313,7 @@ export const identityKubernetesAuthServiceFactory = ({
const baseUrl = port ? `${host}:${port}` : host;
- const res = await axios
+ const res = await request
.post<TCreateTokenReviewResponse>(
`${baseUrl}/apis/authentication.k8s.io/v1/tokenreviews`,
{
@@ -388,7 +388,7 @@ export const identityKubernetesAuthServiceFactory = ({
"tokenReviewCallbackThroughGateway: Processing kubernetes token review using gateway"
);
- const res = await axios
+ const res = await request
.post<TCreateTokenReviewResponse>(
`${host}:${port}/apis/authentication.k8s.io/v1/tokenreviews`,
{
diff --git a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
index a0f866fd1b..b4bee1889a 100644
--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts
@@ -1,6 +1,5 @@
import { ForbiddenError, subject } from "@casl/ability";
import { requestContext } from "@fastify/request-context";
-import axios from "axios";
import https from "https";
import jwt from "jsonwebtoken";
import { JwksClient } from "jwks-rsa";
@@ -21,6 +20,7 @@ import {
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { getConfig } from "@app/lib/config/env";
+import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto";
import {
BadRequestError,
@@ -114,7 +114,7 @@ export const identityOidcAuthServiceFactory = ({
let discoveryDoc: { jwks_uri: string };
try {
- const response = await axios.get<{ jwks_uri: string }>(
+ const response = await request.get<{ jwks_uri: string }>(
`${identityOidcAuth.oidcDiscoveryUrl}/.well-known/openid-configuration`,
{
httpsAgent: identityOidcAuth.oidcDiscoveryUrl.includes("https") ? requestAgent : undefined
diff --git a/backend/src/services/microsoft-teams/microsoft-teams-fns.ts b/backend/src/services/microsoft-teams/microsoft-teams-fns.ts
index b9e92c72b3..21a91c9b36 100644
--- a/backend/src/services/microsoft-teams/microsoft-teams-fns.ts
+++ b/backend/src/services/microsoft-teams/microsoft-teams-fns.ts
@@ -1,10 +1,11 @@
/* eslint-disable class-methods-use-this */
-import axios from "axios";
+import { isAxiosError } from "axios";
import { TeamsActivityHandler, TurnContext } from "botbuilder";
import { Knex } from "knex";
import { z } from "zod";
import { getConfig } from "@app/lib/config/env";
+import { request } from "@app/lib/config/request";
import { crypto } from "@app/lib/crypto";
import { BadRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
@@ -26,14 +27,14 @@ export const verifyTenantFromCode = async (
clientSecret: string
) => {
const getAccessToken = async (params: URLSearchParams) => {
- const response = await axios
+ const response = await request
.post<{ access_token: string }>(`https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`, params, {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
.catch((err) => {
- if (axios.isAxiosError(err)) {
+ if (isAxiosError(err)) {
if ((err.response?.data as { error_description?: string })?.error_description?.includes(ConsentError)) {
throw new BadRequestError({
message: "Unable to verify tenant, please ensure that you have granted admin consent."
@@ -177,7 +178,7 @@ export const getMicrosoftTeamsAccessToken = async (
}
}
- const tokenResponse = await axios.post<{ access_token: string; expires_in: number }>(
+ const tokenResponse = await request.post<{ access_token: string; expires_in: number }>(
details.uri,
new URLSearchParams({
client_id: clientId,
@@ -235,7 +236,7 @@ export const getMicrosoftTeamsAccessToken = async (
return tokenResponse.data.access_token;
} catch (error) {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
logger.error(
error.response?.data,
`getMicrosoftTeamsAccessToken: Error fetching Microsoft Teams access token [status-code=${error.response?.status}]`
@@ -306,7 +307,7 @@ export const isBotInstalledInTenant = async (
} as const;
}
- const appsResponse = await axios
+ const appsResponse = await request
.get<{ value: { id: string; displayName: string; distributionMethod: string; externalId: string }[] }>(
"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps",
{
@@ -622,7 +623,7 @@ export class TeamsBot extends TeamsActivityHandler {
}
};
- await axios.post(
+ await request.post(
`https://smba.trafficmanager.net/amer/v3/conversations/${channelId}/activities`,
adaptiveCardActivity,
{
@@ -633,7 +634,7 @@ export class TeamsBot extends TeamsActivityHandler {
}
);
} catch (error) {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
logger.error(
error.response?.data,
`sendMessageToChannel: Axios Error, Microsoft Teams Workflow Integration: Failed to send message to channel [channelId=${channelId}] [teamId=${teamId}] [tenantId=${tenantId}]`
@@ -656,7 +657,7 @@ export class TeamsBot extends TeamsActivityHandler {
while (teamsNextLink?.length) {
try {
// eslint-disable-next-line no-await-in-loop
- const response = await axios.get<{
+ const response = await request.get<{
value: { displayName: string; id: string }[];
"@odata.nextLink"?: string;
}>(teamsNextLink, {
@@ -678,7 +679,7 @@ export class TeamsBot extends TeamsActivityHandler {
for await (const team of allTeams) {
try {
// Get installed apps for this team
- const installedAppsResponse = await axios.get<{ value: { teamsAppDefinition: { teamsAppId: string } }[] }>(
+ const installedAppsResponse = await request.get<{ value: { teamsAppDefinition: { teamsAppId: string } }[] }>(
`https://graph.microsoft.com/v1.0/teams/${team.id}/installedApps?$expand=teamsAppDefinition`,
{
headers: {
@@ -702,7 +703,7 @@ export class TeamsBot extends TeamsActivityHandler {
while (channelNextLink?.length) {
// eslint-disable-next-line no-await-in-loop
- const resp = await axios
+ const resp = await request
.get<{
value: { displayName: string; id: string }[];
"@odata.nextLink"?: string;
@@ -712,7 +713,7 @@ export class TeamsBot extends TeamsActivityHandler {
}
})
.catch((error) => {
- if (axios.isAxiosError(error)) {
+ if (isAxiosError(error)) {
logger.error(
error.response?.data,
"getTeamsAndChannels: Axios error, Microsoft Teams Workflow Integration: Failed to fetch channels"