Skip to content

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

use safe request

Thiago Araujo da Silvaccf663e0ea44
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 6421a75669..0aa59a6335 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
@@ -18,11 +18,17 @@ vi.mock("@app/lib/logger", () => ({
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() }
}));
-// Only the hostname check is stubbed, because the real one needs DNS. resolveEventTimestamp
-// stays real so the timestamp assertions exercise actual behaviour.
-vi.mock("../audit-log-stream-fns", async (importOriginal) => ({
- ...(await importOriginal<typeof import("../audit-log-stream-fns")>()),
- blockAuditLogStreamInternalIps: vi.fn(async () => undefined)
+// 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", () => ({
+ safeRequest: {
+ post: async (url: string, data: unknown, options: Record<string, unknown> = {}) => {
+ const { allowPrivateIps, ...axiosOpts } = options;
+ const { request } = await import("@app/lib/config/request");
+
+ return request.request({ ...axiosOpts, method: "POST", url, data });
+ }
+ }
}));
// A real axios instance with a capturing adapter, because the adapter receives `config.data`
diff --git a/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.ts b/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.ts
index c1b16652c3..2d8cf420b1 100644
--- a/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.ts
+++ b/backend/src/ee/services/audit-log-stream/splunk/splunk-provider-factory.ts
@@ -1,11 +1,11 @@
import { RawAxiosRequestHeaders } from "axios";
import { getConfig } from "@app/lib/config/env";
-import { request } from "@app/lib/config/request";
import { BadRequestError } from "@app/lib/errors";
+import { safeRequest } from "@app/lib/validator";
import { AUDIT_LOG_STREAM_BATCH_TIMEOUT, AUDIT_LOG_STREAM_TIMEOUT } from "../../audit-log/audit-log-queue";
-import { blockAuditLogStreamInternalIps, resolveEventTimestamp } from "../audit-log-stream-fns";
+import { resolveEventTimestamp } from "../audit-log-stream-fns";
import {
TLogStreamFactoryBatchStreamLog,
TLogStreamFactoryGetProviderBatchLimit,
@@ -26,7 +26,7 @@ function createPayload(event: Record<string, unknown> & { createdAt?: Date | str
};
}
-async function createSplunkUrl(hostname: string, port?: number) {
+function createSplunkUrl(hostname: string, port?: number) {
let parsedHostname: string;
try {
parsedHostname = new URL(`https://${hostname}`).hostname;
@@ -34,8 +34,6 @@ async function createSplunkUrl(hostname: string, port?: number) {
throw new BadRequestError({ message: `Invalid Splunk hostname provided: ${(error as Error).message}` });
}
- await blockAuditLogStreamInternalIps(`https://${parsedHostname}`);
-
return `https://${parsedHostname}:${port ?? SPLUNK_DEFAULT_HEC_PORT}/services/collector/event`;
}
@@ -45,17 +43,18 @@ export const SplunkProviderFactory = () => {
}) => {
const { hostname, port, token } = credentials;
- const url = await createSplunkUrl(hostname, port);
+ const url = createSplunkUrl(hostname, port);
const streamHeaders: RawAxiosRequestHeaders = {
"Content-Type": "application/json",
Authorization: `Splunk ${token}`
};
- await request
+ await safeRequest
.post(url, createPayload({ ping: "ok" }), {
headers: streamHeaders,
- timeout: AUDIT_LOG_STREAM_TIMEOUT
+ timeout: AUDIT_LOG_STREAM_TIMEOUT,
+ allowPrivateIps: getConfig().AUDIT_LOG_STREAM_ALLOW_INTERNAL_IP
})
.catch((err) => {
throw new BadRequestError({ message: `Failed to connect with Splunk: ${(err as Error)?.message}` });
@@ -72,7 +71,7 @@ export const SplunkProviderFactory = () => {
const { hostname, port, token } = credentials;
- const url = await createSplunkUrl(hostname, port);
+ const url = createSplunkUrl(hostname, port);
const streamHeaders: RawAxiosRequestHeaders = {
"Content-Type": "application/json",
@@ -85,9 +84,10 @@ export const SplunkProviderFactory = () => {
// string that HEC rejects with a 400. Send the bytes we built, untransformed.
const body = auditLogs.map((auditLog) => JSON.stringify(createPayload(auditLog))).join("");
- await request.post(url, body, {
+ await safeRequest.post(url, body, {
headers: streamHeaders,
timeout: AUDIT_LOG_STREAM_BATCH_TIMEOUT,
+ allowPrivateIps: getConfig().AUDIT_LOG_STREAM_ALLOW_INTERNAL_IP,
transformRequest: [(data: unknown) => data]
});
};