From 0f15745927441f86b16b3f519b71b65dfaaa5f62 Mon Sep 17 00:00:00 2001 From: beary Date: Wed, 17 May 2023 12:36:56 +0800 Subject: [PATCH] Respect `NODE_TLS_REJECT_UNAUTHORIZED` environment variable --- lib/http-proxy/common.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; }