Summary
A TLS validation flaw in undici's ProxyAgent causes the requestTls configuration to be ignored when using SOCKS5 proxies, silently falling back to Node.js's default trust store.
Applications that rely on custom CA pinning or strict TLS options through requestTls with a SOCKS5 proxy may unknowingly trust any publicly valid certificate, exposing HTTPS traffic to potential man-in-the-middle attacks.
Affected context
This vulnerability affects Node.js applications that:
- Use undici's ProxyAgent or Socks5ProxyAgent
- Configure a SOCKS5 proxy via
socks5://orsocks://URIs - Depend on
requestTlsoptions (e.g.,ca,cert,key,rejectUnauthorized,servername) for TLS scope restriction or certificate pinning
In these conditions, the intended custom trust configuration is silently ignored and the default Mozilla CA bundle is used instead.
Exploit preconditions
- Attack surface: Outbound HTTPS connections initiated through undici's ProxyAgent/Socks5ProxyAgent with a SOCKS5 proxy.
- Required access: Network-level positioning (e.g., on-path attacker, compromised proxy, or malicious network infrastructure) capable of intercepting and terminating TLS traffic.
- Trigger point: Any HTTPS request made through a SOCKS5-configured ProxyAgent that is expected to enforce
requestTlsconstraints. - Why exploitation is possible: The
requestTlsoptions are dropped on the SOCKS5 code path, so certificate pinning and custom CA trust are not applied; any certificate chaining to a public CA for the target hostname can be accepted.
Why this happens
The root cause is an incorrect handling of TLS configuration parameters in the SOCKS5 proxy path within undici's ProxyAgent.
When a SOCKS5 URI is used, the requestTls structure—intended to carry custom trust anchors and TLS constraints—is not propagated into the TLS handshake configuration.
This behavior falls under CWE-295: Improper Certificate Validation, because the application's configured certificate validation policy is not actually enforced, allowing connections to be established using broader trust than the developer intended.
Potential impact
- TLS certificate pinning can be bypassed for outbound HTTPS requests routed via SOCKS5.
- On-path attackers may read or modify supposedly protected HTTPS traffic.
- Sensitive data, such as credentials, API tokens, or business data, could be exfiltrated.
- Integrity of API calls and responses can be tampered with, potentially leading to data corruption or fraudulent operations.
- Security assumptions about corporate or internal CA–pinned services may no longer hold.
General mitigation guidance
Effective mitigation focuses on enforcing strict TLS validation policies and avoiding reliance on code paths that ignore them:
- Prefer proxy configurations and agent types that correctly honor explicit TLS settings, especially custom CAs and certificate pinning.
- Centralize TLS configuration to reduce the chance that certain routes or agents silently diverge from the desired validation policy.
- Apply least-privilege and segmentation for network paths that carry sensitive HTTPS traffic so that only trusted infrastructure can observe it.
- Use defense-in-depth: combine TLS pinning with application-level integrity checks or signed payloads where practical.
- Regularly exercise and test TLS settings (including CA bundles and pinning) under different proxy and agent configurations to detect unexpected fallbacks.
How teams detect issues like this
Potential detection approaches include:
- Static analysis and code review: Look for usages of undici's
ProxyAgentorSocks5ProxyAgentwhererequestTlsis configured alongsidesocks5://orsocks://proxy URIs; verify that TLS constraints are actually enforced in those paths. - Configuration audits: Inventory outbound HTTP client configurations and highlight cases where certificate pinning or custom CAs are expected, then confirm that behavior by controlled tests.
- Dynamic and integration testing: In staging environments, replace upstream endpoints with services using untrusted or mismatched certificates to ensure that connections fail when pinning is intended.
- Policy enforcement: Incorporate automated checks in CI/CD pipelines that flag proxy configurations known to bypass strict TLS options, and encourage use of vetted HTTP client patterns or wrappers.

