Skip to content

Commit ca1740c

Browse files
fix: Resolve security vulnerabilities
Signed-off-by: Anurag Rajawat <anurag@stepsecurity.io>
1 parent 59f68db commit ca1740c

4 files changed

Lines changed: 409 additions & 209 deletions

File tree

dist/main.js

Lines changed: 191 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -103904,8 +103904,8 @@ prototype.toString = function toString(encoder) {
103904103904
};
103905103905

103906103906
/**
103907-
* It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
103908-
* URI encoded counterparts
103907+
* It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
103908+
* their plain counterparts (`:`, `$`, `,`, `+`).
103909103909
*
103910103910
* @param {string} val The value to be encoded.
103911103911
*
@@ -104471,16 +104471,49 @@ var parseHeaders = (rawHeaders) => {
104471104471

104472104472
const $internals = Symbol('internals');
104473104473

104474+
const isValidHeaderValue = (value) => !/[\r\n]/.test(value);
104475+
104476+
function assertValidHeaderValue(value, header) {
104477+
if (value === false || value == null) {
104478+
return;
104479+
}
104480+
104481+
if (utils$1.isArray(value)) {
104482+
value.forEach((v) => assertValidHeaderValue(v, header));
104483+
return;
104484+
}
104485+
104486+
if (!isValidHeaderValue(String(value))) {
104487+
throw new Error(`Invalid character in header content ["${header}"]`);
104488+
}
104489+
}
104490+
104474104491
function normalizeHeader(header) {
104475104492
return header && String(header).trim().toLowerCase();
104476104493
}
104477104494

104495+
function stripTrailingCRLF(str) {
104496+
let end = str.length;
104497+
104498+
while (end > 0) {
104499+
const charCode = str.charCodeAt(end - 1);
104500+
104501+
if (charCode !== 10 && charCode !== 13) {
104502+
break;
104503+
}
104504+
104505+
end -= 1;
104506+
}
104507+
104508+
return end === str.length ? str : str.slice(0, end);
104509+
}
104510+
104478104511
function normalizeValue(value) {
104479104512
if (value === false || value == null) {
104480104513
return value;
104481104514
}
104482104515

104483-
return utils$1.isArray(value) ? value.map(normalizeValue) : String(value);
104516+
return utils$1.isArray(value) ? value.map(normalizeValue) : stripTrailingCRLF(String(value));
104484104517
}
104485104518

104486104519
function parseTokens(str) {
@@ -104562,6 +104595,7 @@ let AxiosHeaders$1 = class AxiosHeaders {
104562104595
_rewrite === true ||
104563104596
(_rewrite === undefined && self[key] !== false)
104564104597
) {
104598+
assertValidHeaderValue(_value, _header);
104565104599
self[key || _header] = normalizeValue(_value);
104566104600
}
104567104601
}
@@ -104933,11 +104967,7 @@ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
104933104967
return requestedURL;
104934104968
}
104935104969

104936-
var proxyFromEnv = {};
104937-
104938-
var parseUrl$1 = Url.parse;
104939-
104940-
var DEFAULT_PORTS = {
104970+
var DEFAULT_PORTS$1 = {
104941104971
ftp: 21,
104942104972
gopher: 70,
104943104973
http: 80,
@@ -104946,18 +104976,22 @@ var DEFAULT_PORTS = {
104946104976
wss: 443,
104947104977
};
104948104978

104949-
var stringEndsWith = String.prototype.endsWith || function(s) {
104950-
return s.length <= this.length &&
104951-
this.indexOf(s, this.length - s.length) !== -1;
104952-
};
104979+
function parseUrl$1(urlString) {
104980+
try {
104981+
return new URL(urlString);
104982+
} catch {
104983+
return null;
104984+
}
104985+
}
104953104986

104954104987
/**
104955-
* @param {string|object} url - The URL, or the result from url.parse.
104988+
* @param {string|object|URL} url - The URL as a string or URL instance, or a
104989+
* compatible object (such as the result from legacy url.parse).
104956104990
* @return {string} The URL of the proxy that should handle the request to the
104957104991
* given URL. If no proxy is set, this will be an empty string.
104958104992
*/
104959104993
function getProxyForUrl(url) {
104960-
var parsedUrl = typeof url === 'string' ? parseUrl$1(url) : url || {};
104994+
var parsedUrl = (typeof url === 'string' ? parseUrl$1(url) : url) || {};
104961104995
var proto = parsedUrl.protocol;
104962104996
var hostname = parsedUrl.host;
104963104997
var port = parsedUrl.port;
@@ -104969,16 +105003,12 @@ function getProxyForUrl(url) {
104969105003
// Stripping ports in this way instead of using parsedUrl.hostname to make
104970105004
// sure that the brackets around IPv6 addresses are kept.
104971105005
hostname = hostname.replace(/:\d*$/, '');
104972-
port = parseInt(port) || DEFAULT_PORTS[proto] || 0;
105006+
port = parseInt(port) || DEFAULT_PORTS$1[proto] || 0;
104973105007
if (!shouldProxy(hostname, port)) {
104974105008
return ''; // Don't proxy URLs that match NO_PROXY.
104975105009
}
104976105010

104977-
var proxy =
104978-
getEnv('npm_config_' + proto + '_proxy') ||
104979-
getEnv(proto + '_proxy') ||
104980-
getEnv('npm_config_proxy') ||
104981-
getEnv('all_proxy');
105011+
var proxy = getEnv(proto + '_proxy') || getEnv('all_proxy');
104982105012
if (proxy && proxy.indexOf('://') === -1) {
104983105013
// Missing scheme in proxy, default to the requested URL's scheme.
104984105014
proxy = proto + '://' + proxy;
@@ -104995,8 +105025,7 @@ function getProxyForUrl(url) {
104995105025
* @private
104996105026
*/
104997105027
function shouldProxy(hostname, port) {
104998-
var NO_PROXY =
104999-
(getEnv('npm_config_no_proxy') || getEnv('no_proxy')).toLowerCase();
105028+
var NO_PROXY = getEnv('no_proxy').toLowerCase();
105000105029
if (!NO_PROXY) {
105001105030
return true; // Always proxy if NO_PROXY is not set.
105002105031
}
@@ -105025,7 +105054,7 @@ function shouldProxy(hostname, port) {
105025105054
parsedProxyHostname = parsedProxyHostname.slice(1);
105026105055
}
105027105056
// Stop proxying if the hostname ends with the no_proxy host.
105028-
return !stringEndsWith.call(hostname, parsedProxyHostname);
105057+
return !hostname.endsWith(parsedProxyHostname);
105029105058
});
105030105059
}
105031105060

@@ -105040,8 +105069,6 @@ function getEnv(key) {
105040105069
return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';
105041105070
}
105042105071

105043-
proxyFromEnv.getProxyForUrl = getProxyForUrl;
105044-
105045105072
var followRedirectsExports = {};
105046105073
var followRedirects = {
105047105074
get exports(){ return followRedirectsExports; },
@@ -106976,7 +107003,7 @@ function escapeRegex(regex) {
106976107003
followRedirects.exports = wrap({ http: http, https: https });
106977107004
followRedirectsExports.wrap = wrap;
106978107005

106979-
const VERSION$1 = "1.13.6";
107006+
const VERSION$1 = "1.15.0";
106980107007

106981107008
function parseProtocol(url) {
106982107009
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
@@ -107355,6 +107382,113 @@ const callbackify = (fn, reducer) => {
107355107382

107356107383
var callbackify$1 = callbackify;
107357107384

107385+
const DEFAULT_PORTS = {
107386+
http: 80,
107387+
https: 443,
107388+
ws: 80,
107389+
wss: 443,
107390+
ftp: 21,
107391+
};
107392+
107393+
const parseNoProxyEntry = (entry) => {
107394+
let entryHost = entry;
107395+
let entryPort = 0;
107396+
107397+
if (entryHost.charAt(0) === '[') {
107398+
const bracketIndex = entryHost.indexOf(']');
107399+
107400+
if (bracketIndex !== -1) {
107401+
const host = entryHost.slice(1, bracketIndex);
107402+
const rest = entryHost.slice(bracketIndex + 1);
107403+
107404+
if (rest.charAt(0) === ':' && /^\d+$/.test(rest.slice(1))) {
107405+
entryPort = Number.parseInt(rest.slice(1), 10);
107406+
}
107407+
107408+
return [host, entryPort];
107409+
}
107410+
}
107411+
107412+
const firstColon = entryHost.indexOf(':');
107413+
const lastColon = entryHost.lastIndexOf(':');
107414+
107415+
if (
107416+
firstColon !== -1 &&
107417+
firstColon === lastColon &&
107418+
/^\d+$/.test(entryHost.slice(lastColon + 1))
107419+
) {
107420+
entryPort = Number.parseInt(entryHost.slice(lastColon + 1), 10);
107421+
entryHost = entryHost.slice(0, lastColon);
107422+
}
107423+
107424+
return [entryHost, entryPort];
107425+
};
107426+
107427+
const normalizeNoProxyHost = (hostname) => {
107428+
if (!hostname) {
107429+
return hostname;
107430+
}
107431+
107432+
if (hostname.charAt(0) === '[' && hostname.charAt(hostname.length - 1) === ']') {
107433+
hostname = hostname.slice(1, -1);
107434+
}
107435+
107436+
return hostname.replace(/\.+$/, '');
107437+
};
107438+
107439+
function shouldBypassProxy(location) {
107440+
let parsed;
107441+
107442+
try {
107443+
parsed = new URL(location);
107444+
} catch (_err) {
107445+
return false;
107446+
}
107447+
107448+
const noProxy = (process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
107449+
107450+
if (!noProxy) {
107451+
return false;
107452+
}
107453+
107454+
if (noProxy === '*') {
107455+
return true;
107456+
}
107457+
107458+
const port =
107459+
Number.parseInt(parsed.port, 10) || DEFAULT_PORTS[parsed.protocol.split(':', 1)[0]] || 0;
107460+
107461+
const hostname = normalizeNoProxyHost(parsed.hostname.toLowerCase());
107462+
107463+
return noProxy.split(/[\s,]+/).some((entry) => {
107464+
if (!entry) {
107465+
return false;
107466+
}
107467+
107468+
let [entryHost, entryPort] = parseNoProxyEntry(entry);
107469+
107470+
entryHost = normalizeNoProxyHost(entryHost);
107471+
107472+
if (!entryHost) {
107473+
return false;
107474+
}
107475+
107476+
if (entryPort && entryPort !== port) {
107477+
return false;
107478+
}
107479+
107480+
if (entryHost.charAt(0) === '*') {
107481+
entryHost = entryHost.slice(1);
107482+
}
107483+
107484+
if (entryHost.charAt(0) === '.') {
107485+
return hostname.endsWith(entryHost);
107486+
}
107487+
107488+
return hostname === entryHost;
107489+
});
107490+
}
107491+
107358107492
/**
107359107493
* Calculate data maxRate
107360107494
* @param {Number} [samplesCount= 10]
@@ -107650,6 +107784,9 @@ class Http2Sessions {
107650107784
} else {
107651107785
entries.splice(i, 1);
107652107786
}
107787+
if (!session.closed) {
107788+
session.close();
107789+
}
107653107790
return;
107654107791
}
107655107792
}
@@ -107729,9 +107866,11 @@ function dispatchBeforeRedirect(options, responseDetails) {
107729107866
function setProxy(options, configProxy, location) {
107730107867
let proxy = configProxy;
107731107868
if (!proxy && proxy !== false) {
107732-
const proxyUrl = proxyFromEnv.getProxyForUrl(location);
107869+
const proxyUrl = getProxyForUrl(location);
107733107870
if (proxyUrl) {
107734-
proxy = new URL(proxyUrl);
107871+
if (!shouldBypassProxy(location)) {
107872+
proxy = new URL(proxyUrl);
107873+
}
107735107874
}
107736107875
}
107737107876
if (proxy) {
@@ -108205,7 +108344,6 @@ var httpAdapter = isHttpAdapterSupported &&
108205108344
protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path
108206108345
);
108207108346
}
108208-
108209108347
let transport;
108210108348
const isHttpsRequest = isHttps.test(options.protocol);
108211108349
options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
@@ -109121,15 +109259,19 @@ const factory = (env) => {
109121109259
test(() => {
109122109260
let duplexAccessed = false;
109123109261

109262+
const body = new ReadableStream$1();
109263+
109124109264
const hasContentType = new Request(platform.origin, {
109125-
body: new ReadableStream$1(),
109265+
body,
109126109266
method: 'POST',
109127109267
get duplex() {
109128109268
duplexAccessed = true;
109129109269
return 'half';
109130109270
},
109131109271
}).headers.has('Content-Type');
109132109272

109273+
body.cancel();
109274+
109133109275
return duplexAccessed && !hasContentType;
109134109276
});
109135109277

@@ -109722,13 +109864,29 @@ let Axios$1 = class Axios {
109722109864
Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
109723109865

109724109866
// slice off the Error: ... line
109725-
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
109867+
const stack = (() => {
109868+
if (!dummy.stack) {
109869+
return '';
109870+
}
109871+
109872+
const firstNewlineIndex = dummy.stack.indexOf('\n');
109873+
109874+
return firstNewlineIndex === -1 ? '' : dummy.stack.slice(firstNewlineIndex + 1);
109875+
})();
109726109876
try {
109727109877
if (!err.stack) {
109728109878
err.stack = stack;
109729109879
// match without the 2 top stack lines
109730-
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
109731-
err.stack += '\n' + stack;
109880+
} else if (stack) {
109881+
const firstNewlineIndex = stack.indexOf('\n');
109882+
const secondNewlineIndex =
109883+
firstNewlineIndex === -1 ? -1 : stack.indexOf('\n', firstNewlineIndex + 1);
109884+
const stackWithoutTwoTopLines =
109885+
secondNewlineIndex === -1 ? '' : stack.slice(secondNewlineIndex + 1);
109886+
109887+
if (!String(err.stack).endsWith(stackWithoutTwoTopLines)) {
109888+
err.stack += '\n' + stack;
109889+
}
109732109890
}
109733109891
} catch (e) {
109734109892
// ignore the case where "stack" is an un-writable property
@@ -109910,8 +110068,6 @@ utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoDa
109910110068
});
109911110069

109912110070
utils$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
109913-
/*eslint func-names:0*/
109914-
109915110071
function generateHTTPMethod(isForm) {
109916110072
return function httpMethod(url, data, config) {
109917110073
return this.request(

0 commit comments

Comments
 (0)