The hostname check of a TLS connection is replaced by one that accepts every host

tx0/ts:hostname-check-disabledrecommendedwarningsecurity, cwe-297

What it finds

Node's TLS client calls checkServerIdentity to make sure the certificate was issued for the host it connects to; it reports a mismatch by returning an error. A function that returns nothing accepts a valid certificate for any other host, so an attacker with a certificate for their own domain can stand in for the server.

Reported is the option checkServerIdentity given a function whose body is empty or is undefined.

From the rule's source, hostname_check_disabled.rs.

Example from the rule's tests
import tls from "tls";export function connect(host: string) {  const a = tls.connect({ host, checkServerIdentity: () => undefined });tx0 reports: accepts a certificate for any host  const b = tls.connect({ host, checkServerIdentity: function () {} });tx0 reports: accepts a certificate for any host  const c = tls.connect({ host, checkServerIdentity: (name, cert) => tls.checkServerIdentity(name, cert) });  return [a, b, c];}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:hostname-check-disabled" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:hostname-check-disabled] reason="..."

tx0 explain tx0/ts:hostname-check-disabled shows the same in the terminal. Found a false positive? Report it.