diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index 6513e81d8..b7b40500b 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -55,7 +55,10 @@ common.setupOutgoing = function(outgoing, options, req, forward) { } if (isSSL.test(options[forward || 'target'].protocol)) { - outgoing.rejectUnauthorized = (typeof options.secure === "undefined") ? true : options.secure; + // Respect `NODE_TLS_REJECT_UNAUTHORIZED` environment variable (https://nodejs.org/docs/latest/api/cli.html#node_tls_reject_unauthorizedvalue) + var NODE_TLS_REJECT_UNAUTHORIZED = process.env['NODE_TLS_REJECT_UNAUTHORIZED']; + var rejectUnauthorizedEnv = typeof NODE_TLS_REJECT_UNAUTHORIZED !== 'undefined' ? NODE_TLS_REJECT_UNAUTHORIZED.toString() : undefined; + outgoing.rejectUnauthorized = (typeof options.secure === "undefined") ? (rejectUnauthorizedEnv !== '0') : options.secure; }