Skip to content

fix(mcp): support NODE_EXTRA_CA_CERTS for enterprise MITM proxies#2271

Merged
fahreddinozcan merged 2 commits intoupstash:masterfrom
mvanhorn:fix/node-extra-ca-certs-support
Mar 19, 2026
Merged

fix(mcp): support NODE_EXTRA_CA_CERTS for enterprise MITM proxies#2271
fahreddinozcan merged 2 commits intoupstash:masterfrom
mvanhorn:fix/node-extra-ca-certs-support

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

  • Reads custom CA certificates from NODE_EXTRA_CA_CERTS and injects them into undici's global dispatcher at runtime
  • Handles both transparent proxy (no explicit HTTPS_PROXY) and explicit proxy scenarios
  • Leverages the existing setGlobalDispatcher + undici pattern already used for HTTP proxy support

Problem

Behind enterprise MITM proxies (Zscaler, corporate VPNs), Node's default fetch() TLS context does not trust the corporate CA certificate. Even when NODE_EXTRA_CA_CERTS is set, many MCP client launchers (npx, background daemons) strip or inject the env var too late for Node to pick it up at startup, causing UNABLE_TO_VERIFY_LEAF_SIGNATURE errors.

Solution

Explicitly read the CA cert file at module load time and pass it to undici's Agent or ProxyAgent via the connect.ca option. This bypasses Node's frozen TLS context and works regardless of when the env var was set.

Three cases are handled:

  1. Explicit proxy + custom CA: ProxyAgent gets both the proxy URI and the CA cert
  2. No proxy + custom CA (transparent MITM): A plain Agent with the CA cert is set as the global dispatcher
  3. No custom CA: Existing behavior is unchanged

Fixes #2268

This contribution was developed with AI assistance (Claude Code).

When NODE_EXTRA_CA_CERTS is set, reads the CA certificate file and
injects it into undici's global dispatcher. This fixes fetch failures
behind enterprise transparent SSL intercept proxies (Zscaler, etc.)
where the default TLS context does not trust the corporate CA.

The CA certs are also passed through when an explicit HTTPS_PROXY is
configured, so both proxy modes work with custom certificates.

Fixes upstash#2268

This contribution was developed with AI assistance (Claude Code).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fahreddinozcan fahreddinozcan merged commit 2070cb1 into upstash:master Mar 19, 2026
1 of 2 checks passed
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Thanks for the quick review and merge on both PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TypeError: fetch failed behind enterprise MITM proxies (NODE_EXTRA_CA_CERTS ignored)

2 participants