# HTTPS certificate non-validation vulnerability in Node.js

DevFeed: [HTTPS certificate non-validation vulnerability in Node.js](<https://devfeed.tech/articles/https-certificate-non-validation-vulnerability-in-node-js-19087.md>)

Original publisher: [Read original article](<https://httptoolkit.com/blog/node-https-vulnerability/>)

Author: HTTP Toolkit; Tim Perry

Published: 2021-08-11T17:00:00Z

Content type: article

Language: en

Sources: [HTTP Toolkit](<https://devfeed.tech/sources/http-toolkit.md>)

Topics: [code security](<https://devfeed.tech/topics/code-security.md>), [Vulnerabilities](<https://devfeed.tech/topics/vulnerabilities.md>), [certificates](<https://devfeed.tech/topics/certificates.md>), [Cryptography](<https://devfeed.tech/topics/cryptography.md>)

Tags: [certificate](<https://devfeed.tech/tags/certificate.md>), [certificates](<https://devfeed.tech/tags/certificates.md>), [cve](<https://devfeed.tech/tags/cve.md>), [http](<https://devfeed.tech/tags/http.md>), [https](<https://devfeed.tech/tags/https.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [security](<https://devfeed.tech/tags/security.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tls](<https://devfeed.tech/tags/tls.md>), [typescript](<https://devfeed.tech/tags/typescript.md>), [typescript-types](<https://devfeed.tech/tags/typescript-types.md>), [v8](<https://devfeed.tech/tags/v8.md>), [validation](<https://devfeed.tech/tags/validation.md>), [verification](<https://devfeed.tech/tags/verification.md>), [vulnerability](<https://devfeed.tech/tags/vulnerability.md>), [vulnerable-code](<https://devfeed.tech/tags/vulnerable-code.md>)

## AI overview

The excerpt describes CVE-2021-22939, where Node.js HTTPS requests could silently skip server certificate verification when `rejectUnauthorized` received a falsey value. Although the option was documented to disable verification only when explicitly set to `false`, values such as `undefined` could also disable it; wrapper code passing an optional setting could therefore appear secure while accepting an unverified server. The article says this can expose TLS traffic to impersonation and reports that Node.js versions since at least v8.0.0 were affected. It recommends updating Node.js, but the excerpt cuts off before giving specific fixed versions or fuller remediation steps.

## Source excerpt

Today Node.js announced and released a security fix for CVE-2021-22939, along with two other high severity issues. They've rated this vulnerability as 'low severity', but I think it's worth a closer look, as (imo) this really understates the risk here, and the potentially widespread impact. In practice, this poses a risk to anybody making TLS connections from Node.js, e.g. anybody making HTTPS requests. Not all usage is vulnerable, but many common use cases are, it's not easy to guarantee that your code is 100% secure, and all Node.js versions since at least v8.0.0 are affected. If you're using TLS/HTTPS in Node.js, you should update ASAP. I reported this issue to Node myself a couple of weeks ago, after running into it during my own development testing HTTP Toolkit. Let's talk through why this is a problem, how it works, and what you should do about it. Everything here applies to TLS in general, but I'm going to focus on HTTPS specifically, since it's by far the most likely use case, and it's simpler and clearer. What's the problem? Here's an example of common but vulnerable code (TypeScript types included for clarity): const https = require('https'); // Any convenient wrapper or library around the HTTPS module. It takes a URL, and // extra optional parameters, including a `verifyCertificates` option, which can // be set to `false` to disable cert verification when necessary. function makeRequest(url: string, options: { verifyCertificates?: boolean } = {}) { // [...Do some custom logic...] // At some point make a request, using the optional verification option: return https.get(url, { rejectUnauthorized: options.verifyCertificates }); } // Later usage looks like it's making a secure HTTPS request, but in fact the certificate // is not being verified at all, so you could be talking to *anybody*: makeRequest("https://google.com"); The key here is rejectUnauthorized. This Node.js option configures whether the request will check that the server's certificate is valid.