From add12dd144a6595043ec6bf88b18f78c06ad64da Mon Sep 17 00:00:00 2001 From: Mark Wolff Date: Wed, 29 Apr 2020 22:10:35 -0400 Subject: [PATCH 1/2] use globalAgent --- Library/QuickPulseSender.ts | 8 ++++++++ Library/Sender.ts | 4 ++-- Library/Util.ts | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Library/QuickPulseSender.ts b/Library/QuickPulseSender.ts index 5b4694fb..79c59405 100644 --- a/Library/QuickPulseSender.ts +++ b/Library/QuickPulseSender.ts @@ -2,6 +2,7 @@ import https = require("https"); import Config = require("./Config"); import AutoCollectHttpDependencies = require("../AutoCollection/HttpDependencies"); import Logging = require("./Logging"); +import Util = require("./Util"); // Types import * as http from "http"; @@ -50,6 +51,13 @@ class QuickPulseSender { } }; + // HTTPS only + if (this._config.httpsAgent) { + (options).agent = this._config.httpsAgent; + } else { + (options).agent = https.globalAgent || Util.tlsRestrictedAgent; + } + const req = https.request(options, (res: http.IncomingMessage) => { const shouldPOSTData = res.headers[QuickPulseConfig.subscribed] === "true"; this._consecutiveErrors = 0; diff --git a/Library/Sender.ts b/Library/Sender.ts index a930fc16..3df5517b 100644 --- a/Library/Sender.ts +++ b/Library/Sender.ts @@ -223,7 +223,7 @@ class Sender { if (Sender.ACL_IDENTITY) { return callback(null, Sender.ACL_IDENTITY); } - var psProc = child_process.spawn(Sender.POWERSHELL_PATH, + var psProc = child_process.spawn(Sender.POWERSHELL_PATH, ["-Command", "[System.Security.Principal.WindowsIdentity]::GetCurrent().Name"], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] // Needed to prevent hanging on Win 7 @@ -245,7 +245,7 @@ class Sender { } // Some very old versions of Node (< 0.11) don't have this if (child_process.spawnSync) { - var psProc = child_process.spawnSync(Sender.POWERSHELL_PATH, + var psProc = child_process.spawnSync(Sender.POWERSHELL_PATH, ["-Command", "[System.Security.Principal.WindowsIdentity]::GetCurrent().Name"], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] // Needed to prevent hanging on Win 7 diff --git a/Library/Util.ts b/Library/Util.ts index bd9ec0df..d0569aa7 100644 --- a/Library/Util.ts +++ b/Library/Util.ts @@ -326,7 +326,8 @@ class Util { options.agent = config.httpAgent; } else if (isHttps) { // HTTPS without a passed in agent. Use one that enforces our TLS rules - options.agent = Util.tlsRestrictedAgent; + // @todo: globalAgent is always defined (node0.5.9+), is tlsRestrictedAgent still required? + options.agent = https.globalAgent || Util.tlsRestrictedAgent; } if (isHttps) { From 6471ea262d25efd63793d90a6916594f8eb9a5d5 Mon Sep 17 00:00:00 2001 From: Mark Wolff Date: Thu, 7 May 2020 11:03:35 -0400 Subject: [PATCH 2/2] do not use globalAgent --- Library/QuickPulseSender.ts | 2 +- Library/Util.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/QuickPulseSender.ts b/Library/QuickPulseSender.ts index 79c59405..d3217014 100644 --- a/Library/QuickPulseSender.ts +++ b/Library/QuickPulseSender.ts @@ -55,7 +55,7 @@ class QuickPulseSender { if (this._config.httpsAgent) { (options).agent = this._config.httpsAgent; } else { - (options).agent = https.globalAgent || Util.tlsRestrictedAgent; + (options).agent = Util.tlsRestrictedAgent; } const req = https.request(options, (res: http.IncomingMessage) => { diff --git a/Library/Util.ts b/Library/Util.ts index d0569aa7..bd9ec0df 100644 --- a/Library/Util.ts +++ b/Library/Util.ts @@ -326,8 +326,7 @@ class Util { options.agent = config.httpAgent; } else if (isHttps) { // HTTPS without a passed in agent. Use one that enforces our TLS rules - // @todo: globalAgent is always defined (node0.5.9+), is tlsRestrictedAgent still required? - options.agent = https.globalAgent || Util.tlsRestrictedAgent; + options.agent = Util.tlsRestrictedAgent; } if (isHttps) {