Skip to content

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

fix(mcp): Allow disabling Host header validation (#15584)

Ben Bachem4622b497c2d5
diff --git a/.env.prod.example b/.env.prod.example
index 1c288d77a2..84730034e3 100644
--- a/.env.prod.example
+++ b/.env.prod.example
@@ -270,6 +270,7 @@ LANGFUSE_ENABLE_BLOB_STORAGE_FILE_LOG=true
# LANGFUSE_API_TRACEBYID_DEFAULT_FIELDS=
# Comma-separated additional hostnames/origins accepted by the MCP endpoint.
+# Set to * to disable Host and Origin validation. This is not recommended.
# LANGFUSE_MCP_ALLOWED_HOSTS=internal-langfuse.example.com,https://api.example.com
# Legacy tracing UI controls
diff --git a/web/src/__tests__/server/unit/mcp-security.servertest.ts b/web/src/__tests__/server/unit/mcp-security.servertest.ts
index 8a279149d1..8bf7646839 100644
--- a/web/src/__tests__/server/unit/mcp-security.servertest.ts
+++ b/web/src/__tests__/server/unit/mcp-security.servertest.ts
@@ -44,4 +44,17 @@ describe("MCP request security", () => {
validateMcpRequestSecurity(mockRequest({ host: "evil.example.com" })),
).toThrow("Invalid Host header: evil.example.com");
});
+
+ it("disables host and origin validation when LANGFUSE_MCP_ALLOWED_HOSTS is *", () => {
+ mockEnv.env.LANGFUSE_MCP_ALLOWED_HOSTS = ["*"];
+
+ expect(
+ validateMcpRequestSecurity(
+ mockRequest({
+ host: "any-host.example.com",
+ origin: "https://any-origin.example.com",
+ }),
+ ),
+ ).toBe("https://any-origin.example.com");
+ });
});
diff --git a/web/src/features/mcp/README.md b/web/src/features/mcp/README.md
index 7e95151707..53b80de3a5 100644
--- a/web/src/features/mcp/README.md
+++ b/web/src/features/mcp/README.md
@@ -144,8 +144,10 @@ This outputs your BasicAuth token (e.g., `cGstbGYt...`).
- If a reverse proxy forwards a different `Host` header than `NEXTAUTH_URL`,
either preserve the public host at the proxy or set
`LANGFUSE_MCP_ALLOWED_HOSTS` to a comma-separated list of exact additional
- hostnames/origins accepted by the MCP endpoint. Wildcards and paths are not
- supported.
+ hostnames/origins accepted by the MCP endpoint. Wildcard host patterns and
+ paths are not supported. To disable Host and Origin validation completely, set
+ `LANGFUSE_MCP_ALLOWED_HOSTS=*`. This is not recommended because it disables
+ DNS rebinding protection for the MCP endpoint.
**Local Development:**
diff --git a/web/src/features/mcp/server/security.ts b/web/src/features/mcp/server/security.ts
index 481f5a4dc6..05852e7ff5 100644
--- a/web/src/features/mcp/server/security.ts
+++ b/web/src/features/mcp/server/security.ts
@@ -68,6 +68,14 @@ function getAllowedMcpOriginsAndHostnames() {
}
export function validateMcpRequestSecurity(req: NextApiRequest): string | null {
+ const originHeader = Array.isArray(req.headers.origin)
+ ? req.headers.origin[0]
+ : req.headers.origin;
+
+ if (env.LANGFUSE_MCP_ALLOWED_HOSTS.includes("*")) {
+ return originHeader ?? null;
+ }
+
const { allowedHostnames, allowedOrigins } =
getAllowedMcpOriginsAndHostnames();
@@ -89,9 +97,6 @@ export function validateMcpRequestSecurity(req: NextApiRequest): string | null {
throw new ForbiddenError(`Invalid Host header: ${hostHeader}`);
}
- const originHeader = Array.isArray(req.headers.origin)
- ? req.headers.origin[0]
- : req.headers.origin;
if (!originHeader) {
return null;
}