Summary
A flaw in undici's BalancedPool can discard function-valued TLS options while cloning connection settings, preventing application-defined certificate checks from reaching the TLS layer. When a peer passes Node.js's default hostname and certificate-chain validation but should be rejected by a custom callback, the connection may be accepted.
Affected context
The issue occurs in undici's BalancedPool when applications provide function-valued options through the connect or TLS configuration. It affects relevant 7.x and 8.x releases within the described version ranges; Client, Pool, and Agent dispatchers are not affected because they extract these options before the internal cloning step. Risk depends on the application relying on custom certificate validation or connector callbacks to enforce additional trust decisions.
Exploit preconditions
- Attack surface: Outbound HTTPS or TLS connections created through undici's BalancedPool
- Required access: The ability to influence or position a peer that presents a certificate accepted by default TLS checks but rejected by the application's custom validation logic
- Trigger point: Construction or use of a BalancedPool with function-valued connect or TLS options
- Why exploitation is possible: The internal JSON-based clone removes functions before the options reach the TLS layer, causing custom validation behavior to be silently omitted
Why this happens
BalancedPool passes its complete options object through a deep-cloning process that serializes and reparses values as JSON. JSON serialization cannot preserve functions, so callbacks such as checkServerIdentity and function-valued connector options are discarded without an explicit error. This creates an insecure divergence between the validation policy intended by the application and the policy actually applied by the TLS layer, mapping to CWE-295: Improper Certificate Validation.
Potential impact
- A server with a certificate rejected by custom application policy may be accepted
- Sensitive outbound requests or credentials could be exposed to an unintended peer
- Application-level trust boundaries could be bypassed
- Service-to-service authentication decisions could be weakened
- An attacker could gain access to data or operations available through the affected connection
General mitigation guidance
Mitigation generally focuses on preserving certificate-validation policy across connection configuration boundaries and avoiding silent transformation of security-sensitive options.
Common defensive patterns include:
- Use a dispatcher path that preserves connect and TLS options before cloning occurs
- Ensure security-sensitive callbacks are not passed through JSON-based cloning or serialization
- Prefer secure-by-default TLS verification and avoid disabling built-in hostname or chain validation
- Treat custom certificate policies as explicit, testable configuration rather than optional callbacks
- Restrict outbound connection privileges and limit the data and operations available to each service
- Maintain dependency versions containing the vendor's corrective changes as part of normal dependency governance
How teams detect issues like this
Organizations can detect this class of issue through:
- Static analysis that identifies JSON serialization or deep-cloning of TLS and connector configuration
- Code review checks for function-valued security options crossing serialization boundaries
- Integration tests confirming that custom certificate rejection policies remain active through each supported dispatcher
- Dependency and API policy checks that distinguish BalancedPool behavior from Client, Pool, and Agent behavior
- Runtime telemetry for unexpected successful TLS connections to peers that should fail application-defined validation
Automated review tools can help flag serialization of security-sensitive connection settings during development.

