//nefariousplan

CVE-2026-45707: n8n-MCP's Router Reads ENABLE_MULTI_TENANT. The Credential Factory Below It Does Not.

vendor

patterns

cve

proof of concept

n8n-MCP's HTTP server reads x-n8n-url and x-n8n-key off each inbound request and uses them to construct a per-tenant client to that tenant's n8n instance. When both headers are absent, the call into getN8nApiClient(undefined) in src/mcp/handlers-n8n-manager.ts does not return null. It returns a client built from the operator's process-level N8N_API_URL and N8N_API_KEY.

CVE-2026-45707 is what happens when the multi-tenant boundary is enforced at the HTTP entry point and the credential factory three call frames below never reads the flag.

The flag turns on at the router. The factory below it does not.

The mode switch is one environment variable: ENABLE_MULTI_TENANT=true. The .env.example in v2.51.1 says, in full, "When enabled, n8n API tools will be available for all sessions, and instance configuration will be determined from HTTP headers." That is the entire pre-patch specification of what the flag does. The line after it reads Default: false (single-tenant mode using environment variables).

Single-tenant mode is the original product. The operator runs n8n-MCP next to their own n8n, sets N8N_API_URL and N8N_API_KEY in the operator's process environment, and every MCP tool call routes through that one credential to that one instance. Multi-tenant mode was added later. It reuses the same handler stack and the same credential factory; the only thing the multi-tenant code path does differently is read tenant identity off the request headers.

Reading the flag is local to src/http-server-single-session.ts. The POST /mcp handler extracts headers['x-n8n-url'] into hasUrl and headers['x-n8n-key'] into hasKey. If hasUrl || hasKey, the handler builds an InstanceContext, validates it with validateInstanceContext(), and passes the context to handleRequest. If neither header is present, instanceContext stays undefined and handleRequest(req, res, undefined) runs anyway.

The handler stack downstream of handleRequest was written for the single-tenant code path. getN8nApiClient(context) in src/mcp/handlers-n8n-manager.ts is one of its entry points. The pre-patch shape, at v2.51.1 line 277:

export function getN8nApiClient(context?: InstanceContext): N8nApiClient | null {
  if (context?.n8nApiUrl && context?.n8nApiKey) {
    // ... build instance-specific client from context ...
    return client;
  }

  // Fall back to default singleton from environment
  logger.info('Falling back to environment configuration for n8n API client');
  const config = getN8nApiConfig();
  // ... build env-derived client ...
  return defaultApiClient;
}

The first branch is the multi-tenant path: a context with both fields builds a per-tenant client. The fall-through is the single-tenant path: no caller config, use the operator's env. The factory has no third branch. It has no parameter for "we are in multi-tenant mode, fail closed instead of falling through." It does not read process.env.ENABLE_MULTI_TENANT. The flag is read above, at the router, where header extraction happens. It is not read here, where the credential decision happens. This is the Fail Open Intercept shape: the gate cannot identify a tenant for the request and forwards the request anyway, against the operator's default client.

When a tenant request lands without headers and getN8nApiClient(undefined) runs, the factory's Falling back to environment configuration log line fires at log level INFO, not WARN, not ERROR, and the function returns a fully constructed N8nApiClient pointing at the operator's n8n with the operator's API key. The tenant's next MCP tool call executes against the operator's instance.

The request flow when both tenant headers are absent

Exploitation requires no exploit primitive. The PoC is the absence of two HTTP headers.

The tenant authenticates to whichever bearer the multi-tenant deployment uses to identify tenants on its frontend (the bearer is per-tenant identity, not per-instance credential). It then sends:

POST /mcp HTTP/1.1
Authorization: Bearer <tenant-token>
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"n8n_list_workflows","arguments":{}}}

No x-n8n-url. No x-n8n-key. extractMultiTenantHeaders(req) returns both as undefined. The pre-patch HTTP handler's if (hasUrl || hasKey) branch is skipped. instanceContext is undefined. handleRequest dispatches the tool call to handleListWorkflows(args, undefined). That handler calls ensureApiConfigured(undefined), which calls getN8nApiClient(undefined), which falls through to env and returns the operator's client.

The server then issues GET https://operator-n8n.example.com/api/v1/workflows with X-N8N-API-KEY: <operator-api-key> and hands every workflow on the operator's instance back to the tenant. Subsequent tool calls run against the same client: n8n_create_workflow, n8n_delete_workflow, n8n_manage_credentials, n8n_trigger_webhook. The operator's n8n audit log records the requests as the operator's own MCP service session.

n8n_create_workflow is the obvious primitive. n8n workflows can perform arbitrary HTTP calls, run JavaScript in Code nodes, exfiltrate credentials stored in n8n's credential store, and trigger any webhook the operator's instance exposes. CVE-2026-45707 rates as CVSS 8.1 with PR:L because the precondition is "authenticated MCP tenant." Every other condition the design assumed (the headers will always be there; tenants will never call without them) was documentation.

The single-header case fails the same way. If a request arrives with x-n8n-url set and x-n8n-key absent, the HTTP handler enters the if (hasUrl || hasKey) branch and builds a candidate context with n8nApiUrl set and n8nApiKey undefined. validateInstanceContext() only validates fields that are not undefined; the undefined key field is skipped, validation passes, the partial context flows to handleRequest. The factory's first branch (context?.n8nApiUrl && context?.n8nApiKey) requires both, so it falls through to env. The operator's credentials authorize the call again. The "supplied only one of them" failure mode the advisory names lives at the factory, not at the HTTP edge; the post-patch flag check in getN8nApiClient is what catches it.

The two-layer fix was three commits

The merge commit on v2.51.2 is titled "Merge commit from fork" and squashes three security commits authored in response to GHSA-jxx9-px88-pj69. The first commit closes the bug. The second and third close the bug again, in different files, after the reviewer reading each patch noticed one more leak path.

Commit 1, the two-layer fix. The HTTP edge gets the explicit guard:

if (process.env.ENABLE_MULTI_TENANT === 'true' && !hasUrl && !hasKey) {
  logger.warn('Multi-tenant request missing tenant headers', {
    hasUrl: false,
    hasKey: false
  });
  res.status(400).json({
    jsonrpc: '2.0',
    error: {
      code: -32602,
      message: 'Multi-tenant headers required'
    },
    id: req.body?.id ?? null
  });
  return;
}

That is layer one. Layer two is getN8nApiClient, with the factory finally reading the flag the router was already reading:

// SECURITY (GHSA-jxx9-px88-pj69): never fall back to process-level credentials
// when multi-tenant mode is enabled. A missing or incomplete tenant context
// must result in no client, not the operator's N8N_API_KEY.
if (process.env.ENABLE_MULTI_TENANT === 'true') {
  logger.warn('Refusing env-credential fallback in multi-tenant mode');
  return null;
}

The commit message names layer two as "protecting every caller of the factory." That phrasing presumes the codebase has more callers than the documented HTTP flow. It does.

Commit 2, the reviewer reads the response payloads. The follow-up commit lists two paths the first fix did not touch. src/triggers/handlers/base-handler.ts has its own context-or-env fallback in getBaseUrl() and getApiKey(), the same shape as the factory, written separately for the trigger-handler code path. In multi-tenant mode without context, both methods returned the operator's URL and key. The fix adds the same flag check to both. The commit message calls this "the latent footgun any future caller that instantiates a handler outside ensureApiConfigured() would otherwise reintroduce."

The same commit identifies four MCP tool handlers, handleHealthCheck, handleDiagnostic, handleDeployTemplate, and handleAuditInstance, that called getN8nApiConfig()?.baseUrl and put the result in their response payloads. In multi-tenant mode with tenant context, the response leaked the operator's URL where the tenant's URL was the correct answer; without context, it leaked the operator's URL period. The fix is a new helper, resolveN8nApiConfigForResponse(context), that centralizes the decision and falls back to env only in single-tenant mode. The four call sites get rewritten to use the helper.

Commit 3, the reviewer reads the response payload one more time. The third commit message begins, "Reviewer caught a third leak path the prior commit (f3c9371) missed: handleDiagnostic's response includes a verbatim copy of process.env.N8N_API_URL and a boolean derived from N8N_API_KEY under data.environment.*, separate from data.apiConfiguration.* that the helper already covers." The previous commit had centralized one of the two leak paths inside handleDiagnostic. The other path, a dictionary literal named envVars that read directly from process.env, was visually adjacent to the rewritten code and was not rewritten:

const isMultiTenant = process.env.ENABLE_MULTI_TENANT === 'true';
const envVars = {
  N8N_API_URL: isMultiTenant ? null : (process.env.N8N_API_URL || null),
  N8N_API_KEY: isMultiTenant ? null : (process.env.N8N_API_KEY ? '***configured***' : null),
  NODE_ENV: process.env.NODE_ENV || 'production',
  // ...
};

The same commit notes that the existing regression test only stringified data.apiConfiguration and therefore missed the second leak. The test is strengthened to stringify the full result.data and to assert against both 'https://n8n.test.com' and '***configured***'.

Three commits. Four code paths. One pattern. The fall-through to process.env reflex was written once into the single-tenant codebase and duplicated, with minor variation, across the credential factory, the trigger-handler base class, the helper that fills response payloads, and the dictionary literal that fills one specific response payload twice. Each reviewer pass found one. The patch is not one place. The patch is every place.

The trust artifact is the operator's N8N_API_KEY

n8n-MCP's multi-tenant mode is an MCP server that brokers AI-assistant access to many tenants' n8n instances through one deployed service. The operator runs the service. The operator pays the bills. The operator also wires their own n8n into the process environment, because the documentation says the way to give the server a working n8n connection is N8N_API_URL and N8N_API_KEY. Setting those variables is how the operator stands up the deployment.

That credential is the trust artifact. It authorizes the MCP server to manage workflows on the operator's n8n. The operator's threat model places it inside the trust boundary of the deployment, not on the tenant-facing edge. When a tenant request lands without headers and the factory falls through, the operator's own credential is what authorizes the tenant's next workflow creation, credential read, or audit-log review.

This is not credential theft. The operator's API key is being used by the MCP server, which is the system the operator deployed and the system that holds the key. The bug is that the system was supposed to use that key on behalf of the operator and instead uses it on behalf of whichever tenant sent the empty headers. The trust the operator placed in their own n8n by exporting N8N_API_KEY to the process environment was inverted into a tenant primitive at the moment ENABLE_MULTI_TENANT=true flipped the same factory function from "the operator is the only caller" to "anyone is a possible caller, and missing context still means the operator." This is the Trust Inversion shape applied to a credential the operator exported into a process that they no longer control single-handed.

The pre-patch .env.example documents what multi-tenant does. It does not document what multi-tenant does when the headers are missing. Neither did the code. The post-patch .env.example adds three sentences that should have been there from the first commit that named the flag:

Requests MUST supply both x-n8n-url and x-n8n-key headers; requests without complete tenant headers are rejected with HTTP 400. The process-level N8N_API_URL / N8N_API_KEY are NOT used as a fallback.

The documentation update is the testimony. The pre-patch behavior was unspecified because the developer assumed the headers would always be there. The factory was unguarded because the flag was assumed to be a routing concern. The gate that should have ended the request at the HTTP edge instead ran the request as the operator, and four call sites in the same codebase repeated the same single-tenant-fallback reflex on the same flag the router was already reading.

PoC: GHSA-jxx9-px88-pj69.

A multi-tenant gate that falls back to single-tenant defaults when the tenant cannot be identified is not a multi-tenant gate. It is a single-tenant gate with a per-request preference.