Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
chore(deps): move the invalid-URL message fix into the shared request client
Vlad Ligai2079a4c72113
diff --git a/Dockerfile.fips.standalone-infisical b/Dockerfile.fips.standalone-infisicalindex 04d1e5edca..682fdbdeda 100644--- a/Dockerfile.fips.standalone-infisical+++ b/Dockerfile.fips.standalone-infisical@@ -6,7 +6,8 @@ ARG INFISICAL_CLI_VERSION=0.43.142FROM node:26.10.0-trixie-slim AS base-# The npm bundled with Node 26.10.0 (11.19.1) carries outdated dependencies; 12.x still does.+# Node 26.10.0 bundles npm 11.19.1, whose own dependencies are outdated. 11.21.1 updates+# them; npm 12.2.0 still bundles the old ones.RUN npm install -g [email protected] && npm cache clean --forceFROM base AS frontend-dependenciesdiff --git a/Dockerfile.standalone-infisical b/Dockerfile.standalone-infisicalindex 224476317e..79fb9a9189 100644--- a/Dockerfile.standalone-infisical+++ b/Dockerfile.standalone-infisical@@ -6,7 +6,8 @@ ARG INFISICAL_CLI_VERSION=0.43.142FROM node:26.10.0-trixie-slim AS base-# The npm bundled with Node 26.10.0 (11.19.1) carries outdated dependencies; 12.x still does.+# Node 26.10.0 bundles npm 11.19.1, whose own dependencies are outdated. 11.21.1 updates+# them; npm 12.2.0 still bundles the old ones.RUN npm install -g [email protected] && npm cache clean --forceFROM base AS frontend-dependenciesdiff --git a/backend/src/lib/config/request.test.ts b/backend/src/lib/config/request.test.tsindex 0b2494bb01..136b3e84c3 100644--- a/backend/src/lib/config/request.test.ts+++ b/backend/src/lib/config/request.test.ts@@ -1,6 +1,9 @@+import http from "node:http";+import { AddressInfo } from "node:net";+import { AxiosError } from "axios";-import { isRetryableRequestError } from "./request";+import { createRequestClient, isRetryableRequestError } from "./request";const responseError = (status: number) => ({ code: "ERR_BAD_RESPONSE", response: { status } }) as unknown as AxiosError;@@ -19,3 +22,30 @@ describe("isRetryableRequestError", () => {expect(isRetryableRequestError(responseError(404))).toBe(false);});});++describe("createRequestClient", () => {+ const client = createRequestClient({}, { retries: 0 });++ test("drops the URL from axios's missing-slashes error and keeps its code", async () => {+ const err = (await client.post("http:example.com/hooks/s3cret", {}).catch((e: unknown) => e)) as AxiosError;+ expect(err).toBeInstanceOf(AxiosError);+ expect(err.code).toBe(AxiosError.ERR_INVALID_URL);+ expect(err.message).toBe('Invalid URL: missing "//" after protocol');+ expect(err.stack).not.toContain("s3cret");+ });++ test("passes other request errors through unchanged", async () => {+ const server = http.createServer((_req, res) => {+ res.statusCode = 500;+ res.end();+ });+ await new Promise<void>((resolve) => {+ server.listen(0, "127.0.0.1", resolve);+ });+ const { port } = server.address() as AddressInfo;+ const err = (await client.get(`http://127.0.0.1:${port}/`).catch((e: unknown) => e)) as AxiosError;+ server.close();+ expect(err.message).toBe("Request failed with status code 500");+ expect(err.response?.status).toBe(500);+ });+});diff --git a/backend/src/lib/config/request.ts b/backend/src/lib/config/request.tsindex 32dbe898ce..ecbd01dcfc 100644--- a/backend/src/lib/config/request.ts+++ b/backend/src/lib/config/request.ts@@ -1,5 +1,6 @@-import axios, { AxiosError, AxiosInstance, AxiosResponse, CreateAxiosDefaults } from "axios";+import axios, { AxiosError, AxiosInstance, AxiosResponse, CreateAxiosDefaults, isAxiosError } from "axios";import axiosRetry, { IAxiosRetryConfig } from "axios-retry";+import RE2 from "re2";import { CustomLogger, logger } from "../logger/logger";import { sanitizeUrlForLog } from "../logger/sanitize-url";@@ -28,6 +29,18 @@ export function axiosResponseInterceptor(response: AxiosResponse, customLogger:return response;}+// Axios quotes the requested URL, path included, in its "missing //" error message, and a+// path can carry a token (webhook URLs). Drop the quoted URL from the message; config still has it.+const QUOTED_INVALID_URL = new RE2('^Invalid URL "(?:[^"\\\\]|\\\\.)*"');++const withoutUrlInMessage = (err: unknown): unknown => {+ if (isAxiosError(err) && err.code === AxiosError.ERR_INVALID_URL && QUOTED_INVALID_URL.test(err.message)) {+ const message = err.message.replace(QUOTED_INVALID_URL, "Invalid URL");+ return new AxiosError(message, err.code, err.config, err.request, err.response);+ }+ return err;+};+export const isRetryableRequestError = (error: AxiosError): boolean =>error.response?.status === 429 || axiosRetry.isNetworkError(error) || axiosRetry.isRetryableError(error);@@ -48,6 +61,10 @@ export function createRequestClient(defaults: CreateAxiosDefaults = {}, retry: I...retry});+ client.interceptors.response.use(undefined, (err: unknown) => {+ throw withoutUrlInMessage(err);+ });+return client;}diff --git a/backend/src/lib/validator/safe-request.test.ts b/backend/src/lib/validator/safe-request.test.tsindex 399db1f9be..95ea89017a 100644--- a/backend/src/lib/validator/safe-request.test.ts+++ b/backend/src/lib/validator/safe-request.test.ts@@ -2,7 +2,6 @@import type { AgentOptions as HttpAgentOptions } from "node:http";import type { Agent as HttpsAgent } from "node:https";-import { AxiosError } from "axios";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { buildSsrfSafeAgent, getSharedHttpsAgent, safeRequest, validateAndPinUrl } from "./safe-request";@@ -471,27 +470,6 @@ describe("safe-request SSRF helpers", () => {expect(args.httpAgent).toBeDefined();});- it.each([- ["post", (url: string) => safeRequest.post(url, {})],- ["request", (url: string) => safeRequest.request({ method: "POST", url })]- ])("safeRequest.%s drops the URL from Axios's missing-slashes error, keeping its code", async (_name, send) => {- const url = "http:example.com/hooks/s3cret";- requestRequestMock.mockRejectedValueOnce(- new AxiosError(`Invalid URL ${JSON.stringify(url)}: missing "//" after protocol`, AxiosError.ERR_INVALID_URL)- );- const err = (await send(url).catch((e: unknown) => e)) as AxiosError;- expect(err).toBeInstanceOf(AxiosError);- expect(err.code).toBe(AxiosError.ERR_INVALID_URL);- expect(err.message).toBe('Invalid URL: missing "//" after protocol');- expect(err.stack).not.toContain("s3cret");- });-- it("rethrows other request errors unchanged", async () => {- const networkError = new AxiosError("connect ECONNREFUSED", "ECONNREFUSED");- requestRequestMock.mockRejectedValueOnce(networkError);- await expect(safeRequest.get("https://example.com")).rejects.toBe(networkError);- });-it("plumbs validateStatus through dispatch", async () => {requestRequestMock.mockResolvedValueOnce({ data: undefined, status: 401, headers: {} });const validateStatus = (s: number) => s < 500;diff --git a/backend/src/lib/validator/safe-request.ts b/backend/src/lib/validator/safe-request.tsindex e408e14e1a..640a26874e 100644--- a/backend/src/lib/validator/safe-request.ts+++ b/backend/src/lib/validator/safe-request.ts@@ -4,7 +4,7 @@ import http from "node:http";import https from "node:https";import { LookupFunction } from "node:net";-import { AxiosError, AxiosRequestConfig, isAxiosError } from "axios";+import { AxiosRequestConfig } from "axios";import { isIP } from "net";import { verifyHostInputValidity } from "@app/ee/services/dynamic-secret/dynamic-secret-fns";@@ -386,17 +386,6 @@ const resolveBaseUrl = (url: string, baseURL?: string): string => {return combineURLs(baseURL, url);};-// Axios embeds the requested URL, path included, in this error's message, and a-// path can carry a secret (webhook tokens). Rethrow it without the URL.-const MISSING_SLASHES_SUFFIX = 'missing "//" after protocol';--const withoutUrlInMessage = (err: unknown): unknown => {- if (isAxiosError(err) && err.code === AxiosError.ERR_INVALID_URL && err.message.endsWith(MISSING_SLASHES_SUFFIX)) {- return new AxiosError(`Invalid URL: ${MISSING_SLASHES_SUFFIX}`, err.code, err.config, err.request, err.response);- }- return err;-};-const logDispatch = (method: string, effectiveUrl: string, validated: TValidatedHost | undefined) => {const pinned = validated ? formatEntries(validated.entries) : "none";logger.debug(@@ -418,22 +407,18 @@ const dispatch = async <T>(const agent = buildPinnedAgent(validated, protocol, { addressFamily, ca, rejectUnauthorized, servername });logDispatch(method, effectiveUrl, validated);- return request- .request<T>({- ...axiosOpts,- method,- url,- ...(data !== undefined && { data }),- maxRedirects: 0,- // Force direct egress so an ambient HTTP(S)_PROXY can't route around the- // pinned agent (the proxy would re-resolve the target, defeating the pin).- ...(appCfg.SAFE_REQUEST_FORCE_DIRECT_EGRESS && { proxy: false as const }),- httpAgent: protocol === "http:" ? (agent as http.Agent | undefined) : undefined,- httpsAgent: protocol === "https:" ? (agent as https.Agent | undefined) : undefined- })- .catch((err: unknown) => {- throw withoutUrlInMessage(err);- });+ return request.request<T>({+ ...axiosOpts,+ method,+ url,+ ...(data !== undefined && { data }),+ maxRedirects: 0,+ // Force direct egress so an ambient HTTP(S)_PROXY can't route around the+ // pinned agent (the proxy would re-resolve the target, defeating the pin).+ ...(appCfg.SAFE_REQUEST_FORCE_DIRECT_EGRESS && { proxy: false as const }),+ httpAgent: protocol === "http:" ? (agent as http.Agent | undefined) : undefined,+ httpsAgent: protocol === "https:" ? (agent as https.Agent | undefined) : undefined+ });};const dispatchFull = async <T>(config: TSafeRequestFullConfig) => {@@ -445,20 +430,16 @@ const dispatchFull = async <T>(config: TSafeRequestFullConfig) => {const agent = buildPinnedAgent(validated, protocol, { addressFamily, ca, rejectUnauthorized, servername });logDispatch(axiosOpts.method ?? "GET", effectiveUrl, validated);- return request- .request<T>({- ...axiosOpts,- url,- maxRedirects: 0,- // Force direct egress so an ambient HTTP(S)_PROXY can't route around the- // pinned agent (the proxy would re-resolve the target, defeating the pin).- ...(appCfg.SAFE_REQUEST_FORCE_DIRECT_EGRESS && { proxy: false as const }),- httpAgent: protocol === "http:" ? (agent as http.Agent | undefined) : undefined,- httpsAgent: protocol === "https:" ? (agent as https.Agent | undefined) : undefined- })- .catch((err: unknown) => {- throw withoutUrlInMessage(err);- });+ return request.request<T>({+ ...axiosOpts,+ url,+ maxRedirects: 0,+ // Force direct egress so an ambient HTTP(S)_PROXY can't route around the+ // pinned agent (the proxy would re-resolve the target, defeating the pin).+ ...(appCfg.SAFE_REQUEST_FORCE_DIRECT_EGRESS && { proxy: false as const }),+ httpAgent: protocol === "http:" ? (agent as http.Agent | undefined) : undefined,+ httpsAgent: protocol === "https:" ? (agent as https.Agent | undefined) : undefined+ });};// HTTP client that validates the URL, pins the connection to the validated