# Built-in TLS module unexpectedly treats "rejectUnauthorized: undefined" as "rejectUnauthorized: false", disabling all certificate validation

Node.js tls.connect treated explicit rejectUnauthorized:undefined as false, silently disabling TLS certificate validation for any code that built options dynamically.

- Payout: $150
- Severity: low
- Program: Node.js
- Found by: pimterry
- Disclosed: 2021-09-10
- CVE: CVE-2021-22939
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1278254
- Library page: https://bugbountylibrary.com/r/h1%3A1278254
- Tags: area:oss domain:oss impact:data-leak impact:integrity kind:bounty platform:hackerone sev:low tech:nodejs technique:source-review vuln:misconfiguration

**Target:** Node.js built-in tls/https module (tls.connect options)
**Root cause:** The TLS option handling only checked whether rejectUnauthorized was strictly false vs. truthy, so an explicit undefined was coerced into the insecure path instead of falling back to the documented default of true.
**Steps:**
1. Run `https.get('https://expired.badssl.com', { rejectUnauthorized: undefined })`
2. Observe the request succeeds despite the expired certificate
3. Remove the option or set it to `true` and observe the request fails with a certificate error
**How found:** Researcher noticed the docs claim only the literal false disables verification, then tested an explicit undefined value against expired.badssl.com and saw the request succeed; traced the practical impact to global-agent which constructs options objects with explicit undefined fields.
**Exploitation:** An attacker able to MITM the TCP connection (e.g. on-path, malicious proxy, hostile network) can present any certificate and intercept/alter all HTTPS traffic from a Node.js client that passes rejectUnauthorized:undefined, since validation is silently skipped.
**Escalation:** Real-world amplification: the npm package global-agent builds options with explicit undefineds, so all its users were by default not validating TLS certificates for every connection.
**Insight:** When auditing TLS/security defaults, test explicit undefined/null values against a known-bad cert endpoint (expired.badssl.com) — libraries that build options dynamically often inject undefined keys, and truthiness checks can silently flip secure defaults.

## Proof of concept (copied exactly from the original report)

**HTTPS request to expired cert with rejectUnauthorized undefined**

```
const https = require('https');
const request = https.get('https://expired.badssl.com', { rejectUnauthorized: undefined });
request.on('error', (e) => console.log('Request failed:', e.message));
request.on('response', (e) => console.log('Request succeeded'));
```

