undici vulnerable to improper certificate validation via EnvHttpProxyAgent dropping target TLS options
Description
Impact
EnvHttpProxyAgent picks a direct or proxied route for each request from the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables, but applies the application's target TLS options on only one of those routes. Options passed as requestTls (the documented option for TLS to the target) are dropped when a request goes direct, either because no proxy variable is set or because the host matches NO_PROXY. Options passed as connect are dropped when a request is tunnelled through a proxy. In both cases the TLS connection to the target is made without the application's ca, checkServerIdentity, servername, client certificate or rejectUnauthorized settings, falling back to Node.js's default trust store and hostname check, and nothing reports that the options were ignored.
Because the route is selected by the deployment environment rather than the application, the same code and options can enforce a private CA or certificate pinning in one environment and silently accept any publicly trusted certificate in another. An attacker able to present a publicly trusted certificate for the target host, for example through a network position on that route, can then intercept connections the application expected to be pinned or restricted to its own CA. All releases since EnvHttpProxyAgent was introduced in undici 6.14.0 are affected.
Patches
Upgrade to undici 6.29.2, 7.30.4, or 8.14.1. EnvHttpProxyAgent now applies the application's target TLS options on both the direct and proxied routes.
Workarounds
Pass the same target TLS options as both requestTls and connect so they are applied on either route, or use Agent (direct) or ProxyAgent (proxied) explicitly instead of EnvHttpProxyAgent.