undici vulnerable to proxy credential disclosure via a shared ProxyAgent headers object
Description
Impact
ProxyAgent adds the proxy credentials (from auth, token, or the username and password in the proxy URL) as a proxy-authorization entry directly on the headers object passed in its options, rather than on a copy. Every other agent holding that same object then sends those credentials to its own proxy, and they stay in the application's object afterwards.
EnvHttpProxyAgent hands the same headers object to both the ProxyAgent it creates for HTTP_PROXY and the one it creates for HTTPS_PROXY. When an application sets the headers option and the two variables name different proxies:
- if only one proxy URL contains credentials, the other proxy receives them with every request it handles;
- if both contain credentials, the
HTTPS_PROXYcredentials overwrite theHTTP_PROXYones, so the HTTP proxy receives the HTTPS proxy's credentials instead of its own.
The same happens when an application passes one headers object to several ProxyAgent instances. The operator of one proxy can then capture credentials meant for another. Applications that do not use the headers option are not affected.
ProxyAgent has written credentials into the caller's headers object since custom proxy headers were added in undici 5.16.0. EnvHttpProxyAgent, available since 6.14.0, shares that object between its two proxies whenever the option is set.
Patches
Upgrade to undici 6.29.2, 7.30.4, or 8.14.1. ProxyAgent now copies the headers option before adding credentials, so each agent sends only its own credentials and the application's object is left unchanged.
Workarounds
Give each ProxyAgent its own headers object and do not reuse it elsewhere. With EnvHttpProxyAgent, do not set the headers option when HTTP_PROXY and HTTPS_PROXY name different proxies and either one carries credentials; create a separate ProxyAgent for each proxy instead.