Spot the bug in the TLS client

from TLS connections
Node 24 intermediate 8 min 3 issues to find

Find the security and lifecycle bugs in this generated TLS client.

JavaScript
import { connect } from "node:tls";

export function openInternal(address, token) {
  return new Promise((resolve, reject) => {
    const socket = connect({
      host: address,
      port: 443,
      rejectUnauthorized: false,
    }, () => {
      socket.write(`Authorization: Bearer ${token}\n`);
      resolve(socket);
    });
    socket.on("error", reject);
  });
}
Open in playground
Report an error