Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(shared): reject DNS-failing hostnames in outbound URL validation (#13512)

Tobias Wochinger849ef156e83d
diff --git a/packages/shared/src/server/llm/baseUrlValidation.ts b/packages/shared/src/server/llm/baseUrlValidation.ts
index b6cbfa467e..c4a91d3360 100644
--- a/packages/shared/src/server/llm/baseUrlValidation.ts
+++ b/packages/shared/src/server/llm/baseUrlValidation.ts
@@ -44,7 +44,6 @@ export async function validateLlmConnectionBaseURL(
await validateOutboundUrlHost({
url,
whitelist: effectiveWhitelist,
- shouldThrowIfDnsResolutionFails: false,
logContext: "LLM base URL",
// Existing LLM validation accepts public IP literals after CIDR checks so
// custom gateways are not forced through DNS at write time.
diff --git a/packages/shared/src/server/outbound-url/validation.ts b/packages/shared/src/server/outbound-url/validation.ts
index 7c6e33f1ca..8e18403211 100644
--- a/packages/shared/src/server/outbound-url/validation.ts
+++ b/packages/shared/src/server/outbound-url/validation.ts
@@ -16,7 +16,6 @@ export interface OutboundUrlValidationWhitelist {
export interface ValidateOutboundUrlHostOptions {
url: URL;
whitelist: OutboundUrlValidationWhitelist;
- shouldThrowIfDnsResolutionFails: boolean;
logContext: string;
shouldSkipDnsCheckForLiteralIps: boolean;
}
@@ -78,7 +77,6 @@ export function parseOutboundUrl(urlString: string): URL {
export async function validateOutboundUrlHost({
url,
whitelist,
- shouldThrowIfDnsResolutionFails,
logContext,
shouldSkipDnsCheckForLiteralIps,
}: ValidateOutboundUrlHostOptions): Promise<void> {
@@ -105,13 +103,11 @@ export async function validateOutboundUrlHost({
if (shouldSkipDnsCheckForLiteralIps) return;
}
- let ips: string[];
- try {
- ips = await resolveHost(hostname);
- } catch (error) {
- if (!shouldThrowIfDnsResolutionFails) return;
- throw error;
- }
+ // DNS-resolution failure is treated as a hard validation error: silently
+ // returning here would let attacker-controlled or split-horizon DNS bypass
+ // the IP blocklist (DNS-rebinding SSRF). Self-hosted gateways that the
+ // validator cannot resolve must be added to the host whitelist above.
+ const ips = await resolveHost(hostname);
for (const ip of ips) {
if (isIPBlocked(ip, whitelist.ips, whitelist.ip_ranges)) {
diff --git a/packages/shared/src/server/webhooks/validation.ts b/packages/shared/src/server/webhooks/validation.ts
index 945a709112..724745a5dc 100644
--- a/packages/shared/src/server/webhooks/validation.ts
+++ b/packages/shared/src/server/webhooks/validation.ts
@@ -42,7 +42,6 @@ export async function validateWebhookURL(
await validateOutboundUrlHost({
url,
whitelist,
- shouldThrowIfDnsResolutionFails: true,
logContext: "Webhook",
// Preserve the existing webhook behavior: public IP literals must still
// pass the same DNS-resolution path as hostname destinations.
diff --git a/web/src/__tests__/server/llm-api-key.servertest.ts b/web/src/__tests__/server/llm-api-key.servertest.ts
index b09457898d..0b3b086f00 100644
--- a/web/src/__tests__/server/llm-api-key.servertest.ts
+++ b/web/src/__tests__/server/llm-api-key.servertest.ts
@@ -108,7 +108,7 @@ describe("llmApiKey.all RPC", () => {
const provider = "openai";
const adapter = LLMAdapter.OpenAI;
const customModels = ["fancy-gpt-3.5-turbo"];
- const baseURL = "https://custom.openai.com/v1";
+ const baseURL = "https://example.com/v1";
const withDefaultModels = false;
await caller.llmApiKey.create({
@@ -200,7 +200,7 @@ describe("llmApiKey.all RPC", () => {
const provider = "openai";
const adapter = LLMAdapter.OpenAI;
const customModels = ["fancy-gpt-3.5-turbo"];
- const baseURL = "https://custom.openai.com/v1";
+ const baseURL = "https://example.com/v1";
const withDefaultModels = false;
await caller.llmApiKey.create({
@@ -490,13 +490,13 @@ describe("llmApiKey.all RPC", () => {
provider: "openai",
adapter: LLMAdapter.OpenAI,
secretKey: "sk-rotated",
- baseURL: "https://new-endpoint.example.com/v1",
+ baseURL: "https://example.net/v1",
});
expect(result).toEqual({ success: true });
expect(mockFetchLLMCompletion).toHaveBeenCalledTimes(1);
const llmConnection = mockFetchLLMCompletion.mock.calls[0][0].llmConnection;
- expect(llmConnection.baseURL).toBe("https://new-endpoint.example.com/v1");
+ expect(llmConnection.baseURL).toBe("https://example.net/v1");
expect(decrypt(llmConnection.secretKey)).toBe("sk-rotated");
expect(llmConnection.extraHeaders).toBeUndefined();
});
@@ -506,7 +506,7 @@ describe("llmApiKey.all RPC", () => {
const provider = "openai";
const adapter = LLMAdapter.OpenAI;
const customModels = ["fancy-gpt-3.5-turbo"];
- const baseURL = "https://custom.openai.com/v1";
+ const baseURL = "https://example.com/v1";
const withDefaultModels = false;
// Create initial key
@@ -539,7 +539,7 @@ describe("llmApiKey.all RPC", () => {
// Update the key
const newSecret = "new-test-secret";
- const newBaseURL = "https://new-custom.openai.com/v1";
+ const newBaseURL = "https://example.org/v1";
const newCustomModels = ["new-fancy-gpt-3.5-turbo"];
const newWithDefaultModels = true;
@@ -858,7 +858,7 @@ describe("llmApiKey.all RPC", () => {
const provider = "openai";
const adapter = LLMAdapter.OpenAI;
const customModels = ["fancy-gpt-3.5-turbo"];
- const baseURL = "https://custom.openai.com/v1";
+ const baseURL = "https://example.com/v1";
const withDefaultModels = false;
// Create initial key
@@ -921,7 +921,7 @@ describe("llmApiKey.all RPC", () => {
const provider = "openai";
const adapter = LLMAdapter.OpenAI;
const customModels = ["fancy-gpt-3.5-turbo"];
- const baseURL = "https://custom.openai.com/v1";
+ const baseURL = "https://example.com/v1";
const withDefaultModels = false;
const extraHeaders = {
"X-Custom-Header": "custom-value",
diff --git a/web/src/server/api/routers/utilities.ts b/web/src/server/api/routers/utilities.ts
index cee796854c..ce4c810f2a 100644
--- a/web/src/server/api/routers/utilities.ts
+++ b/web/src/server/api/routers/utilities.ts
@@ -14,7 +14,6 @@ import {
const MAX_IMAGE_URL_REDIRECTS = 5;
const IMAGE_URL_VALIDATION_OPTIONS = {
whitelist: { hosts: [], ips: [], ip_ranges: [] },
- shouldThrowIfDnsResolutionFails: true,
logContext: "Image URL",
shouldSkipDnsCheckForLiteralIps: true,
} satisfies Omit<ValidateOutboundUrlHostOptions, "url">;
diff --git a/worker/src/__tests__/llm-base-url-validation.test.ts b/worker/src/__tests__/llm-base-url-validation.test.ts
index fe3b77e32a..f3a3d89066 100644
--- a/worker/src/__tests__/llm-base-url-validation.test.ts
+++ b/worker/src/__tests__/llm-base-url-validation.test.ts
@@ -158,14 +158,42 @@ describe("LLM base URL validation", () => {
).resolves.not.toThrow();
});
- it("should allow unresolved public hostnames by default", async () => {
+ it("should reject hostnames that fail DNS resolution to close the SSRF rebinding gap", async () => {
(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;
await expect(
validateLlmConnectionBaseURL("https://gateway.invalid/v1"),
+ ).rejects.toThrow(/DNS lookup failed/);
+ });
+
+ it("should allow unresolved hostnames when explicitly allowlisted", async () => {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;
+
+ const whitelist: LlmBaseUrlValidationWhitelist = {
+ hosts: ["gateway.invalid"],
+ ips: [],
+ ip_ranges: [],
+ };
+
+ await expect(
+ validateLlmConnectionBaseURL("https://gateway.invalid/v1", whitelist),
).resolves.not.toThrow();
});
+ it("should reject unresolved hostnames on Langfuse Cloud regardless of whitelist", async () => {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "US";
+
+ const whitelist: LlmBaseUrlValidationWhitelist = {
+ hosts: ["gateway.invalid"],
+ ips: [],
+ ip_ranges: [],
+ };
+
+ await expect(
+ validateLlmConnectionBaseURL("https://gateway.invalid/v1", whitelist),
+ ).rejects.toThrow(/DNS lookup failed/);
+ });
+
it("should reject non-HTTPS URLs on Langfuse Cloud", async () => {
(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "US";