Skip to content

Commit a66befe

Browse files
Ensure that the value of strictSSL is respected even if a proxy isn't set
1 parent f57b8b0 commit a66befe

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export function getBinPath() {
2525
return path.resolve(getExtensionPath(), "bin");
2626
}
2727

28+
export function isBoolean(obj: any): obj is boolean {
29+
return obj === true || obj === false;
30+
}
31+
2832
export function buildPromiseChain<T, TResult>(array: T[], builder: (item: T) => Promise<TResult>): Promise<TResult> {
2933
return array.reduce(
3034
(promise, n) => promise.then(() => builder(n)),

src/packages.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ function downloadFile(urlString: string, pkg: Package, logger: Logger, status: S
173173
const options: https.RequestOptions = {
174174
host: url.host,
175175
path: url.path,
176-
agent: getProxyAgent(url, proxy, strictSSL)
176+
agent: getProxyAgent(url, proxy, strictSSL),
177+
rejectUnauthorized: util.isBoolean(strictSSL) ? strictSSL : true
177178
};
178179

179180
return new Promise<void>((resolve, reject) => {

src/proxy.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77

88
import { Url, parse as parseUrl } from 'url';
9+
import { isBoolean } from './common';
910
import HttpProxyAgent = require('http-proxy-agent');
1011
import HttpsProxyAgent = require('https-proxy-agent');
1112

@@ -32,15 +33,11 @@ export function getProxyAgent(requestURL: Url, proxy: string, strictSSL: boolean
3233
return null;
3334
}
3435

35-
if (strictSSL === undefined) {
36-
strictSSL = true;
37-
}
38-
3936
const opts = {
4037
host: proxyEndpoint.hostname,
4138
port: Number(proxyEndpoint.port),
4239
auth: proxyEndpoint.auth,
43-
rejectUnauthorized: strictSSL
40+
rejectUnauthorized: isBoolean(strictSSL) ? strictSSL : true
4441
};
4542

4643
return requestURL.protocol === 'http:' ? new HttpProxyAgent(opts) : new HttpsProxyAgent(opts);

0 commit comments

Comments
 (0)