NODE_TLS_REJECT_UNAUTHORIZED=value
If value equals '0', certificate validation is disabled for TLS connections. This makes TLS, and HTTPS by extension, insecure. The use of this environment variable is strongly discouraged. Command-line API | Node.js v22.8.0 Documentation
(node:10476) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests
insecure by disabling certificate verification.
NODE_EXTRA_CA_CERTS=file
When set, the well known “root” CAs (like VeriSign) will be extended with the extra certificates in file. The file should consist of one or more trusted certificates in PEM format. A message will be emitted (once) with process.emitWarning() if the file is missing or malformed, but any errors are otherwise ignored.
(中略)
The NODE_EXTRA_CA_CERTS environment variable is only read when the Node.js process is first launched. Changing the value at runtime using process.env.NODE_EXTRA_CA_CERTS has no effect on the current process. Command-line API | Node.js v22.7.0 Documentation
rejectUnauthorized
If not false, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails; err.code contains the OpenSSL error code. Default: true. TLS (SSL) | Node.js v22.8.0 Documentation
というわけで tls.createSecureContext() のオプションを見てみると ca プロパティーで証明書を指定できることがわかります。
ca | <string[]> | | <Buffer[]>
Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla’s CAs are completely replaced when CAs are explicitly specified using this option. The value can be a string or Buffer, or an Array of strings and/or Buffers. Any string or Buffer can contain multiple PEM CAs concatenated together. The peer’s certificate must be chainable to a CA trusted by the server for the connection to be authenticated. When using certificates that are not chainable to a well-known CA, the certificate’s CA must be explicitly specified as a trusted or the connection will fail to authenticate. If the peer uses a certificate that doesn’t match or chain to one of the default CAs, use the ca option to provide a CA certificate that the peer’s certificate can match or chain to. For self-signed certificates, the certificate is its own CA, and must be provided. For PEM encoded certificates, supported types are “TRUSTED CERTIFICATE”, “X509 CERTIFICATE”, and “CERTIFICATE”. See also tls.rootCertificates. TLS (SSL) | Node.js v22.8.0 Documentation
import{fetch,Agent}from'undici'constres=awaitfetch('https://example.com',{// Mocks are also supported
dispatcher:newAgent({keepAliveTimeout:10,keepAliveMaxTimeout:10})})constjson=awaitres.json()console.log(json)