@coana-tech/cli 14.12.41 → 14.12.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +1193 -1174
- package/package.json +1 -1
- package/reachability-analyzers-cli.mjs +23 -15
- package/repos/coana-tech/alucard/alucard.jar +0 -0
- package/repos/coana-tech/goana/bin/goana-darwin-amd64.gz +0 -0
- package/repos/coana-tech/goana/bin/goana-darwin-arm64.gz +0 -0
- package/repos/coana-tech/goana/bin/goana-linux-amd64.gz +0 -0
- package/repos/coana-tech/goana/bin/goana-linux-arm64.gz +0 -0
- package/repos/coana-tech/mambalade/dist/mambalade-0.3.12-py3-none-any.whl +0 -0
package/cli.mjs
CHANGED
|
@@ -207483,7 +207483,29 @@ import { existsSync as existsSync11 } from "fs";
|
|
|
207483
207483
|
import { readFile as readFile16, writeFile as writeFile6 } from "fs/promises";
|
|
207484
207484
|
function applyUpgradesToPackageJson(packageJsonContent, upgrades, rangeStyle) {
|
|
207485
207485
|
let modifiedContent = packageJsonContent;
|
|
207486
|
-
for (const upgrade of upgrades) {
|
|
207486
|
+
for (const upgrade of sortUpgradesByOffset(upgrades)) {
|
|
207487
|
+
if (upgrade.manifestRef?.start !== void 0 && upgrade.manifestRef?.end !== void 0) {
|
|
207488
|
+
const { start, end: end2 } = upgrade.manifestRef;
|
|
207489
|
+
const originalVersionString = modifiedContent.substring(start, end2);
|
|
207490
|
+
let newVersionString;
|
|
207491
|
+
if (rangeStyle === "pin") {
|
|
207492
|
+
const quotedContent = originalVersionString.slice(1, -1);
|
|
207493
|
+
if (quotedContent.startsWith("npm:") && quotedContent.includes("@")) {
|
|
207494
|
+
const atIndex = quotedContent.lastIndexOf("@");
|
|
207495
|
+
const packageRef = quotedContent.substring(0, atIndex + 1);
|
|
207496
|
+
newVersionString = `"${packageRef}${upgrade.upgradeVersion}"`;
|
|
207497
|
+
} else {
|
|
207498
|
+
newVersionString = `"${upgrade.upgradeVersion}"`;
|
|
207499
|
+
}
|
|
207500
|
+
} else {
|
|
207501
|
+
const quotedContent = originalVersionString.slice(1, -1);
|
|
207502
|
+
const specifierMatch = quotedContent.match(/^([^\d]*)/);
|
|
207503
|
+
const specifier = specifierMatch ? specifierMatch[1] : "";
|
|
207504
|
+
newVersionString = `"${specifier}${upgrade.upgradeVersion}"`;
|
|
207505
|
+
}
|
|
207506
|
+
modifiedContent = modifiedContent.substring(0, start) + newVersionString + modifiedContent.substring(end2);
|
|
207507
|
+
continue;
|
|
207508
|
+
}
|
|
207487
207509
|
const escapedPackageName = upgrade.packageName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
207488
207510
|
const depSection = upgrade.isDev ? "devDependencies" : "dependencies";
|
|
207489
207511
|
const pattern = new RegExp(`("${escapedPackageName}"\\s*:\\s*")([^"]*)"`, "g");
|
|
@@ -207603,10 +207625,12 @@ var NpmSocketUpgradeManager = class {
|
|
|
207603
207625
|
const upgradesWithPackageNames = upgradesToDirectDependencies.map(
|
|
207604
207626
|
(upgrade) => {
|
|
207605
207627
|
const artifact = artifacts[upgrade.idx];
|
|
207628
|
+
const manifestRef = artifact.manifestFiles?.find((manifest) => manifest.file === packageJsonPath);
|
|
207606
207629
|
return {
|
|
207607
207630
|
packageName: artifact.namespace ? `${artifact.namespace}/${artifact.name}` : artifact.name,
|
|
207608
207631
|
upgradeVersion: upgrade.upgradeVersion,
|
|
207609
|
-
isDev: artifact.dev ?? false
|
|
207632
|
+
isDev: artifact.dev ?? false,
|
|
207633
|
+
manifestRef
|
|
207610
207634
|
};
|
|
207611
207635
|
}
|
|
207612
207636
|
);
|
|
@@ -207633,7 +207657,25 @@ function getPackageMangerForDirectory(directory) {
|
|
|
207633
207657
|
} else if (existsSync11(join9(directory, "package-lock.json"))) {
|
|
207634
207658
|
return "NPM";
|
|
207635
207659
|
}
|
|
207636
|
-
throw new Error(
|
|
207660
|
+
throw new Error(
|
|
207661
|
+
`Upgrading packages is currently only supported for NPM projects using a lock file. Failed to find a lock file in ${directory}`
|
|
207662
|
+
);
|
|
207663
|
+
}
|
|
207664
|
+
function sortUpgradesByOffset(upgrades) {
|
|
207665
|
+
return [...upgrades].sort((a4, b) => {
|
|
207666
|
+
const aStart = a4.manifestRef?.start;
|
|
207667
|
+
const bStart = b.manifestRef?.start;
|
|
207668
|
+
if (aStart !== void 0 && bStart !== void 0) {
|
|
207669
|
+
return bStart - aStart;
|
|
207670
|
+
}
|
|
207671
|
+
if (aStart !== void 0 && bStart === void 0) {
|
|
207672
|
+
return -1;
|
|
207673
|
+
}
|
|
207674
|
+
if (aStart === void 0 && bStart !== void 0) {
|
|
207675
|
+
return 1;
|
|
207676
|
+
}
|
|
207677
|
+
return 0;
|
|
207678
|
+
});
|
|
207637
207679
|
}
|
|
207638
207680
|
|
|
207639
207681
|
// ../fixing-management/src/fixing-management/npm/rush-fixing-manager.ts
|
|
@@ -212347,362 +212389,995 @@ ${detailsString}` : ""}`;
|
|
|
212347
212389
|
}
|
|
212348
212390
|
};
|
|
212349
212391
|
|
|
212350
|
-
//
|
|
212351
|
-
|
|
212352
|
-
|
|
212353
|
-
|
|
212354
|
-
|
|
212355
|
-
|
|
212356
|
-
|
|
212357
|
-
|
|
212358
|
-
|
|
212359
|
-
|
|
212360
|
-
|
|
212361
|
-
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
|
212362
|
-
isTTY = process.stdout && process.stdout.isTTY;
|
|
212363
|
-
}
|
|
212364
|
-
var $ = {
|
|
212365
|
-
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY),
|
|
212366
|
-
// modifiers
|
|
212367
|
-
reset: init(0, 0),
|
|
212368
|
-
bold: init(1, 22),
|
|
212369
|
-
dim: init(2, 22),
|
|
212370
|
-
italic: init(3, 23),
|
|
212371
|
-
underline: init(4, 24),
|
|
212372
|
-
inverse: init(7, 27),
|
|
212373
|
-
hidden: init(8, 28),
|
|
212374
|
-
strikethrough: init(9, 29),
|
|
212375
|
-
// colors
|
|
212376
|
-
black: init(30, 39),
|
|
212377
|
-
red: init(31, 39),
|
|
212378
|
-
green: init(32, 39),
|
|
212379
|
-
yellow: init(33, 39),
|
|
212380
|
-
blue: init(34, 39),
|
|
212381
|
-
magenta: init(35, 39),
|
|
212382
|
-
cyan: init(36, 39),
|
|
212383
|
-
white: init(37, 39),
|
|
212384
|
-
gray: init(90, 39),
|
|
212385
|
-
grey: init(90, 39),
|
|
212386
|
-
// background colors
|
|
212387
|
-
bgBlack: init(40, 49),
|
|
212388
|
-
bgRed: init(41, 49),
|
|
212389
|
-
bgGreen: init(42, 49),
|
|
212390
|
-
bgYellow: init(43, 49),
|
|
212391
|
-
bgBlue: init(44, 49),
|
|
212392
|
-
bgMagenta: init(45, 49),
|
|
212393
|
-
bgCyan: init(46, 49),
|
|
212394
|
-
bgWhite: init(47, 49)
|
|
212395
|
-
};
|
|
212396
|
-
function run(arr, str) {
|
|
212397
|
-
let i7 = 0, tmp, beg = "", end2 = "";
|
|
212398
|
-
for (; i7 < arr.length; i7++) {
|
|
212399
|
-
tmp = arr[i7];
|
|
212400
|
-
beg += tmp.open;
|
|
212401
|
-
end2 += tmp.close;
|
|
212402
|
-
if (!!~str.indexOf(tmp.close)) {
|
|
212403
|
-
str = str.replace(tmp.rgx, tmp.close + tmp.open);
|
|
212392
|
+
// ../utils/src/promise-queue.ts
|
|
212393
|
+
var PromiseQueue = class {
|
|
212394
|
+
/*
|
|
212395
|
+
* @param maxConcurrency The maximum number of tasks that can run in parallel.
|
|
212396
|
+
* @param maxQueueLength The maximum number of tasks that can be queued. If the queue is full, the oldest task is removed.
|
|
212397
|
+
*/
|
|
212398
|
+
constructor(maxConcurrency, maxQueueLength) {
|
|
212399
|
+
this.maxConcurrency = maxConcurrency;
|
|
212400
|
+
this.maxQueueLength = maxQueueLength;
|
|
212401
|
+
if (maxQueueLength && maxQueueLength < 1) {
|
|
212402
|
+
throw new Error("maxQueueLength must be at least 1");
|
|
212404
212403
|
}
|
|
212404
|
+
this.maxConcurrency = maxConcurrency;
|
|
212405
212405
|
}
|
|
212406
|
-
|
|
212407
|
-
|
|
212408
|
-
|
|
212409
|
-
|
|
212410
|
-
|
|
212411
|
-
|
|
212412
|
-
|
|
212413
|
-
|
|
212414
|
-
|
|
212415
|
-
|
|
212416
|
-
|
|
212417
|
-
|
|
212418
|
-
|
|
212419
|
-
|
|
212420
|
-
|
|
212421
|
-
|
|
212422
|
-
|
|
212423
|
-
|
|
212424
|
-
|
|
212425
|
-
|
|
212426
|
-
|
|
212427
|
-
|
|
212428
|
-
|
|
212429
|
-
ctx.bgRed = $.bgRed.bind(ctx);
|
|
212430
|
-
ctx.bgGreen = $.bgGreen.bind(ctx);
|
|
212431
|
-
ctx.bgYellow = $.bgYellow.bind(ctx);
|
|
212432
|
-
ctx.bgBlue = $.bgBlue.bind(ctx);
|
|
212433
|
-
ctx.bgMagenta = $.bgMagenta.bind(ctx);
|
|
212434
|
-
ctx.bgCyan = $.bgCyan.bind(ctx);
|
|
212435
|
-
ctx.bgWhite = $.bgWhite.bind(ctx);
|
|
212436
|
-
return ctx;
|
|
212437
|
-
}
|
|
212438
|
-
function init(open, close) {
|
|
212439
|
-
let blk = {
|
|
212440
|
-
open: `\x1B[${open}m`,
|
|
212441
|
-
close: `\x1B[${close}m`,
|
|
212442
|
-
rgx: new RegExp(`\\x1b\\[${close}m`, "g")
|
|
212443
|
-
};
|
|
212444
|
-
return function(txt) {
|
|
212445
|
-
if (this !== void 0 && this.has !== void 0) {
|
|
212446
|
-
!!~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk));
|
|
212447
|
-
return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + "";
|
|
212406
|
+
queue = [];
|
|
212407
|
+
activeTasks = 0;
|
|
212408
|
+
idleResolver = null;
|
|
212409
|
+
idleRejector = null;
|
|
212410
|
+
error = null;
|
|
212411
|
+
async runNextTask() {
|
|
212412
|
+
if (this.activeTasks >= this.maxConcurrency) {
|
|
212413
|
+
return;
|
|
212414
|
+
}
|
|
212415
|
+
const task = this.queue.shift();
|
|
212416
|
+
if (task) {
|
|
212417
|
+
this.activeTasks++;
|
|
212418
|
+
try {
|
|
212419
|
+
await task();
|
|
212420
|
+
} catch (e) {
|
|
212421
|
+
this.error = e;
|
|
212422
|
+
} finally {
|
|
212423
|
+
this.activeTasks--;
|
|
212424
|
+
this.runNextTask();
|
|
212425
|
+
this.checkIdle();
|
|
212426
|
+
}
|
|
212427
|
+
} else {
|
|
212428
|
+
this.checkIdle();
|
|
212448
212429
|
}
|
|
212449
|
-
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + "";
|
|
212450
|
-
};
|
|
212451
|
-
}
|
|
212452
|
-
var kleur_default = $;
|
|
212453
|
-
|
|
212454
|
-
// ../../node_modules/.pnpm/yoctocolors@2.1.2/node_modules/yoctocolors/base.js
|
|
212455
|
-
import tty from "node:tty";
|
|
212456
|
-
var hasColors = tty?.WriteStream?.prototype?.hasColors?.() ?? false;
|
|
212457
|
-
var format5 = (open, close) => {
|
|
212458
|
-
if (!hasColors) {
|
|
212459
|
-
return (input) => input;
|
|
212460
212430
|
}
|
|
212461
|
-
|
|
212462
|
-
|
|
212463
|
-
|
|
212464
|
-
|
|
212465
|
-
|
|
212466
|
-
|
|
212467
|
-
|
|
212431
|
+
checkIdle() {
|
|
212432
|
+
if (!this.idleResolver || !this.idleRejector) return;
|
|
212433
|
+
const shouldResolve = this.queue.length === 0 && this.activeTasks === 0;
|
|
212434
|
+
if (this.error) this.idleRejector(this.error);
|
|
212435
|
+
else if (shouldResolve) this.idleResolver();
|
|
212436
|
+
const resolvedOrRejected = !!this.error || shouldResolve;
|
|
212437
|
+
if (resolvedOrRejected) {
|
|
212438
|
+
this.error = null;
|
|
212439
|
+
this.idleResolver = null;
|
|
212440
|
+
this.idleRejector = null;
|
|
212468
212441
|
}
|
|
212469
|
-
|
|
212470
|
-
|
|
212471
|
-
|
|
212472
|
-
|
|
212473
|
-
while (index2 !== -1) {
|
|
212474
|
-
result += string.slice(lastIndex, index2) + replaceCode;
|
|
212475
|
-
lastIndex = index2 + closeCode.length;
|
|
212476
|
-
index2 = string.indexOf(closeCode, lastIndex);
|
|
212442
|
+
}
|
|
212443
|
+
enqueueTask(task) {
|
|
212444
|
+
if (this.maxQueueLength && this.queue.length >= this.maxQueueLength) {
|
|
212445
|
+
this.queue.shift();
|
|
212477
212446
|
}
|
|
212478
|
-
|
|
212479
|
-
|
|
212480
|
-
}
|
|
212447
|
+
this.queue.push(task);
|
|
212448
|
+
this.runNextTask();
|
|
212449
|
+
}
|
|
212450
|
+
async onIdle() {
|
|
212451
|
+
return new Promise((resolve36, reject) => {
|
|
212452
|
+
if (this.error) {
|
|
212453
|
+
reject(this.error);
|
|
212454
|
+
this.error = null;
|
|
212455
|
+
} else if (this.queue.length === 0 && this.activeTasks === 0) {
|
|
212456
|
+
resolve36();
|
|
212457
|
+
} else {
|
|
212458
|
+
this.idleResolver = resolve36;
|
|
212459
|
+
this.idleRejector = reject;
|
|
212460
|
+
}
|
|
212461
|
+
});
|
|
212462
|
+
}
|
|
212481
212463
|
};
|
|
212482
|
-
var reset = format5(0, 0);
|
|
212483
|
-
var bold = format5(1, 22);
|
|
212484
|
-
var dim = format5(2, 22);
|
|
212485
|
-
var italic = format5(3, 23);
|
|
212486
|
-
var underline = format5(4, 24);
|
|
212487
|
-
var overline = format5(53, 55);
|
|
212488
|
-
var inverse = format5(7, 27);
|
|
212489
|
-
var hidden = format5(8, 28);
|
|
212490
|
-
var strikethrough = format5(9, 29);
|
|
212491
|
-
var black = format5(30, 39);
|
|
212492
|
-
var red = format5(31, 39);
|
|
212493
|
-
var green = format5(32, 39);
|
|
212494
|
-
var yellow = format5(33, 39);
|
|
212495
|
-
var blue = format5(34, 39);
|
|
212496
|
-
var magenta = format5(35, 39);
|
|
212497
|
-
var cyan = format5(36, 39);
|
|
212498
|
-
var white = format5(37, 39);
|
|
212499
|
-
var gray = format5(90, 39);
|
|
212500
|
-
var bgBlack = format5(40, 49);
|
|
212501
|
-
var bgRed = format5(41, 49);
|
|
212502
|
-
var bgGreen = format5(42, 49);
|
|
212503
|
-
var bgYellow = format5(43, 49);
|
|
212504
|
-
var bgBlue = format5(44, 49);
|
|
212505
|
-
var bgMagenta = format5(45, 49);
|
|
212506
|
-
var bgCyan = format5(46, 49);
|
|
212507
|
-
var bgWhite = format5(47, 49);
|
|
212508
|
-
var bgGray = format5(100, 49);
|
|
212509
|
-
var redBright = format5(91, 39);
|
|
212510
|
-
var greenBright = format5(92, 39);
|
|
212511
|
-
var yellowBright = format5(93, 39);
|
|
212512
|
-
var blueBright = format5(94, 39);
|
|
212513
|
-
var magentaBright = format5(95, 39);
|
|
212514
|
-
var cyanBright = format5(96, 39);
|
|
212515
|
-
var whiteBright = format5(97, 39);
|
|
212516
|
-
var bgRedBright = format5(101, 49);
|
|
212517
|
-
var bgGreenBright = format5(102, 49);
|
|
212518
|
-
var bgYellowBright = format5(103, 49);
|
|
212519
|
-
var bgBlueBright = format5(104, 49);
|
|
212520
|
-
var bgMagentaBright = format5(105, 49);
|
|
212521
|
-
var bgCyanBright = format5(106, 49);
|
|
212522
|
-
var bgWhiteBright = format5(107, 49);
|
|
212523
212464
|
|
|
212524
|
-
// dist/cli-
|
|
212525
|
-
|
|
212526
|
-
import os from "os";
|
|
212527
|
-
import { join as join26, relative as relative14, resolve as resolve33 } from "path";
|
|
212465
|
+
// dist/cli-upgrade-purl.js
|
|
212466
|
+
import { join as join25, relative as relative14, resolve as resolve32 } from "node:path";
|
|
212528
212467
|
|
|
212529
|
-
// ../utils/src/
|
|
212530
|
-
|
|
212531
|
-
|
|
212532
|
-
|
|
212533
|
-
|
|
212534
|
-
|
|
212535
|
-
|
|
212536
|
-
|
|
212537
|
-
|
|
212538
|
-
|
|
212539
|
-
|
|
212540
|
-
|
|
212541
|
-
|
|
212542
|
-
|
|
212543
|
-
|
|
212544
|
-
|
|
212545
|
-
|
|
212546
|
-
|
|
212547
|
-
|
|
212548
|
-
return
|
|
212549
|
-
repoUrl,
|
|
212550
|
-
projectName,
|
|
212551
|
-
cliVersion,
|
|
212552
|
-
commitSha,
|
|
212553
|
-
branchName,
|
|
212554
|
-
cliOptions,
|
|
212555
|
-
apiKey,
|
|
212556
|
-
cliRunEnv
|
|
212557
|
-
);
|
|
212558
|
-
}
|
|
212559
|
-
}
|
|
212560
|
-
async sendErrorReport(apiKey, stackTrace, shouldLogSharing, reportId, repoUrl, projectName, logContent) {
|
|
212561
|
-
if (this.disableAnalyticsSharing) {
|
|
212562
|
-
return;
|
|
212563
|
-
}
|
|
212564
|
-
if (this.socketMode) {
|
|
212565
|
-
await this.socketAPI.sendErrorReportToSocketDashboard(stackTrace, shouldLogSharing, reportId, logContent);
|
|
212566
|
-
} else {
|
|
212567
|
-
await this.coanaAPI.sendErrorReportToCoanaDashboard(
|
|
212568
|
-
apiKey,
|
|
212569
|
-
stackTrace,
|
|
212570
|
-
shouldLogSharing,
|
|
212571
|
-
reportId,
|
|
212572
|
-
repoUrl,
|
|
212573
|
-
projectName,
|
|
212574
|
-
logContent
|
|
212575
|
-
);
|
|
212468
|
+
// ../web-compat-utils/src/assertions.ts
|
|
212469
|
+
function assertDefined(value) {
|
|
212470
|
+
if (value === void 0 || value === null) throw new Error("Expected value to be defined");
|
|
212471
|
+
return value;
|
|
212472
|
+
}
|
|
212473
|
+
|
|
212474
|
+
// dist/cli-upgrade-purl.js
|
|
212475
|
+
var import_packageurl_js3 = __toESM(require_packageurl_js(), 1);
|
|
212476
|
+
|
|
212477
|
+
// dist/internal/socket-mode-helpers-socket-dependency-trees.js
|
|
212478
|
+
var import_packageurl_js2 = __toESM(require_packageurl_js(), 1);
|
|
212479
|
+
var import_picomatch4 = __toESM(require_picomatch2(), 1);
|
|
212480
|
+
import { basename as basename10, dirname as dirname13, join as join24, sep as sep5 } from "path";
|
|
212481
|
+
var REQUIREMENTS_FILES_SEARCH_DEPTH2 = 3;
|
|
212482
|
+
function inferWorkspaceFromManifestPath(ecosystem, manifestPath, properPythonProjects) {
|
|
212483
|
+
switch (ecosystem) {
|
|
212484
|
+
case "NPM": {
|
|
212485
|
+
const base = basename10(manifestPath);
|
|
212486
|
+
const dir = dirname13(manifestPath);
|
|
212487
|
+
return base === "package.json" ? dir || "." : void 0;
|
|
212576
212488
|
}
|
|
212577
|
-
|
|
212578
|
-
|
|
212579
|
-
if (this.disableAnalyticsSharing) {
|
|
212580
|
-
return;
|
|
212489
|
+
case "MAVEN": {
|
|
212490
|
+
return ".";
|
|
212581
212491
|
}
|
|
212582
|
-
|
|
212583
|
-
|
|
212584
|
-
|
|
212585
|
-
|
|
212492
|
+
case "PIP": {
|
|
212493
|
+
const base = basename10(manifestPath);
|
|
212494
|
+
const dir = dirname13(manifestPath);
|
|
212495
|
+
const workspaceDir = dir === "" ? "." : dir;
|
|
212496
|
+
if (properPythonProjects.includes(workspaceDir)) {
|
|
212497
|
+
return workspaceDir;
|
|
212498
|
+
}
|
|
212499
|
+
if (base === "poetry.lock" || base === "Pipfile.lock" || base === "uv.lock") {
|
|
212500
|
+
return workspaceDir;
|
|
212501
|
+
}
|
|
212502
|
+
if (base.endsWith(".txt")) {
|
|
212503
|
+
const properProjectDirs = properPythonProjects.filter((properProjectDir) => (properProjectDir === "." || workspaceDir === "." || workspaceDir.startsWith(properProjectDir)) && workspaceDir.replace(properProjectDir, "").split(sep5).length <= REQUIREMENTS_FILES_SEARCH_DEPTH2);
|
|
212504
|
+
const longestProperProjectDir = l5(properProjectDirs, [(d4) => d4.length, "desc"]);
|
|
212505
|
+
if (longestProperProjectDir) {
|
|
212506
|
+
return longestProperProjectDir;
|
|
212507
|
+
}
|
|
212508
|
+
return workspaceDir;
|
|
212509
|
+
}
|
|
212510
|
+
logger.warn(`No workspace found for manifest file ${manifestPath}`);
|
|
212511
|
+
return void 0;
|
|
212586
212512
|
}
|
|
212587
|
-
|
|
212588
|
-
|
|
212589
|
-
if (this.disableAnalyticsSharing) {
|
|
212590
|
-
return;
|
|
212513
|
+
case "NUGET": {
|
|
212514
|
+
return ".";
|
|
212591
212515
|
}
|
|
212592
|
-
|
|
212593
|
-
|
|
212594
|
-
} else {
|
|
212595
|
-
await this.coanaAPI.registerCLIProgressCoana(cliProgressEvent, isStartEvent, reportId, apiKey);
|
|
212516
|
+
case "RUST": {
|
|
212517
|
+
return dirname13(manifestPath) || ".";
|
|
212596
212518
|
}
|
|
212597
|
-
|
|
212598
|
-
|
|
212599
|
-
|
|
212600
|
-
return;
|
|
212519
|
+
case "GO": {
|
|
212520
|
+
const base = basename10(manifestPath);
|
|
212521
|
+
const dir = dirname13(manifestPath);
|
|
212522
|
+
return base === "go.mod" ? dir || "." : void 0;
|
|
212601
212523
|
}
|
|
212602
|
-
|
|
212603
|
-
|
|
212604
|
-
subprojectPath,
|
|
212605
|
-
workspacePath,
|
|
212606
|
-
ecosystem,
|
|
212607
|
-
analysisMetadata,
|
|
212608
|
-
reportId
|
|
212609
|
-
);
|
|
212610
|
-
} else {
|
|
212611
|
-
await this.coanaAPI.registerAnalysisMetadataCoana(
|
|
212612
|
-
subprojectPath,
|
|
212613
|
-
workspacePath,
|
|
212614
|
-
ecosystem,
|
|
212615
|
-
analysisMetadata,
|
|
212616
|
-
reportId,
|
|
212617
|
-
apiKey
|
|
212618
|
-
);
|
|
212524
|
+
default: {
|
|
212525
|
+
return ".";
|
|
212619
212526
|
}
|
|
212620
212527
|
}
|
|
212621
|
-
|
|
212622
|
-
|
|
212623
|
-
|
|
212624
|
-
|
|
212625
|
-
|
|
212626
|
-
|
|
212627
|
-
|
|
212628
|
-
|
|
212629
|
-
|
|
212630
|
-
apiKey
|
|
212631
|
-
);
|
|
212528
|
+
}
|
|
212529
|
+
function inferProjectFromManifestPath(ecosystem, manifestPath) {
|
|
212530
|
+
switch (ecosystem) {
|
|
212531
|
+
case "NPM": {
|
|
212532
|
+
const filename = basename10(manifestPath);
|
|
212533
|
+
if (["package-lock.json", "pnpm-lock.yaml", "pnpm-lock.yml", "yarn.lock"].includes(filename)) {
|
|
212534
|
+
return dirname13(manifestPath) || ".";
|
|
212535
|
+
}
|
|
212536
|
+
return void 0;
|
|
212632
212537
|
}
|
|
212633
212538
|
}
|
|
212634
|
-
}
|
|
212635
|
-
|
|
212636
|
-
|
|
212637
|
-
|
|
212638
|
-
|
|
212639
|
-
|
|
212640
|
-
|
|
212641
|
-
*/
|
|
212642
|
-
constructor(maxConcurrency, maxQueueLength) {
|
|
212643
|
-
this.maxConcurrency = maxConcurrency;
|
|
212644
|
-
this.maxQueueLength = maxQueueLength;
|
|
212645
|
-
if (maxQueueLength && maxQueueLength < 1) {
|
|
212646
|
-
throw new Error("maxQueueLength must be at least 1");
|
|
212539
|
+
}
|
|
212540
|
+
function getAllToplevelAncestors(artifactMap, artifactId) {
|
|
212541
|
+
const visited = /* @__PURE__ */ new Set();
|
|
212542
|
+
const toplevelAncestors = /* @__PURE__ */ new Set();
|
|
212543
|
+
function findAncestors(currentId) {
|
|
212544
|
+
if (visited.has(currentId)) {
|
|
212545
|
+
return;
|
|
212647
212546
|
}
|
|
212648
|
-
|
|
212649
|
-
|
|
212650
|
-
|
|
212651
|
-
activeTasks = 0;
|
|
212652
|
-
idleResolver = null;
|
|
212653
|
-
idleRejector = null;
|
|
212654
|
-
error = null;
|
|
212655
|
-
async runNextTask() {
|
|
212656
|
-
if (this.activeTasks >= this.maxConcurrency) {
|
|
212547
|
+
visited.add(currentId);
|
|
212548
|
+
const artifact = artifactMap.get(currentId);
|
|
212549
|
+
if (!artifact) {
|
|
212657
212550
|
return;
|
|
212658
212551
|
}
|
|
212659
|
-
|
|
212660
|
-
|
|
212661
|
-
|
|
212662
|
-
|
|
212663
|
-
await task();
|
|
212664
|
-
} catch (e) {
|
|
212665
|
-
this.error = e;
|
|
212666
|
-
} finally {
|
|
212667
|
-
this.activeTasks--;
|
|
212668
|
-
this.runNextTask();
|
|
212669
|
-
this.checkIdle();
|
|
212552
|
+
if (artifact.toplevelAncestors && artifact.toplevelAncestors.length > 0) {
|
|
212553
|
+
for (const ancestorId of artifact.toplevelAncestors) {
|
|
212554
|
+
toplevelAncestors.add(ancestorId);
|
|
212555
|
+
findAncestors(ancestorId);
|
|
212670
212556
|
}
|
|
212671
|
-
} else {
|
|
212672
|
-
this.checkIdle();
|
|
212673
212557
|
}
|
|
212674
212558
|
}
|
|
212675
|
-
|
|
212676
|
-
|
|
212677
|
-
|
|
212678
|
-
|
|
212679
|
-
|
|
212680
|
-
|
|
212681
|
-
|
|
212682
|
-
|
|
212683
|
-
|
|
212684
|
-
|
|
212559
|
+
findAncestors(artifactId);
|
|
212560
|
+
return Array.from(toplevelAncestors);
|
|
212561
|
+
}
|
|
212562
|
+
async function fetchArtifactsFromSocket(rootWorkingDirectory, manifestsTarHash, mode) {
|
|
212563
|
+
logger.info("Fetching artifacts from Socket backend using manifests tar hash", manifestsTarHash);
|
|
212564
|
+
try {
|
|
212565
|
+
const { artifacts } = await fetchArtifactsFromManifestsTarHash(manifestsTarHash);
|
|
212566
|
+
const properPythonProjects = [];
|
|
212567
|
+
const pipArtifactToRepresentativeManifest = {};
|
|
212568
|
+
for (const artifact of artifacts) {
|
|
212569
|
+
if (artifact.type === "pypi" && artifact.manifestFiles) {
|
|
212570
|
+
pipArtifactToRepresentativeManifest[simplePurl(artifact.type, artifact.namespace ?? "", artifact.name, artifact.version ?? "")] = artifact;
|
|
212571
|
+
}
|
|
212685
212572
|
}
|
|
212686
|
-
|
|
212687
|
-
|
|
212688
|
-
|
|
212689
|
-
|
|
212573
|
+
const venvExcludes = [
|
|
212574
|
+
"venv",
|
|
212575
|
+
".venv",
|
|
212576
|
+
"env",
|
|
212577
|
+
".env",
|
|
212578
|
+
"virtualenv",
|
|
212579
|
+
".virtualenv",
|
|
212580
|
+
"venvs",
|
|
212581
|
+
".venvs",
|
|
212582
|
+
"envs",
|
|
212583
|
+
".envs",
|
|
212584
|
+
"__pycache__",
|
|
212585
|
+
".tox",
|
|
212586
|
+
".nox",
|
|
212587
|
+
".pytest_cache",
|
|
212588
|
+
"site-packages",
|
|
212589
|
+
"dist-packages",
|
|
212590
|
+
"conda-meta",
|
|
212591
|
+
"conda-bld",
|
|
212592
|
+
".mypy_cache",
|
|
212593
|
+
".ruff_cache",
|
|
212594
|
+
".hypothesis"
|
|
212595
|
+
];
|
|
212596
|
+
const allFiles = await getFilesRelative(rootWorkingDirectory, venvExcludes);
|
|
212597
|
+
for (const file of allFiles) {
|
|
212598
|
+
const base = basename10(file);
|
|
212599
|
+
const workspaceDir = dirname13(file) || ".";
|
|
212600
|
+
if (base === "pyproject.toml" || base === "setup.py" && await isSetupPySetuptools(join24(rootWorkingDirectory, file))) {
|
|
212601
|
+
if (!properPythonProjects.includes(workspaceDir)) {
|
|
212602
|
+
properPythonProjects.push(workspaceDir);
|
|
212603
|
+
}
|
|
212604
|
+
}
|
|
212605
|
+
}
|
|
212606
|
+
const artifactMap = new Map(artifacts.map((a4) => [a4.id, a4]));
|
|
212607
|
+
const ecosystemToWorkspaceToAnalysisData = {};
|
|
212608
|
+
const ecosystemWorkspaceVulnIds = /* @__PURE__ */ new Set();
|
|
212609
|
+
const ecosystemToWorkspaceToVulnerabilities = {};
|
|
212610
|
+
const purlsFailedToFindWorkspace = /* @__PURE__ */ new Set();
|
|
212611
|
+
for (const artifact of artifacts) {
|
|
212612
|
+
let processToplevelAncestors2 = function(artifact2) {
|
|
212613
|
+
const allAncestorIds = getAllToplevelAncestors(artifactMap, artifact2.id);
|
|
212614
|
+
allAncestorIds.forEach((ancestorId) => artifactMap.get(ancestorId)?.manifestFiles?.forEach((ref) => manifestFiles.push(ref.file)));
|
|
212615
|
+
};
|
|
212616
|
+
var processToplevelAncestors = processToplevelAncestors2;
|
|
212617
|
+
const ecosystem = getAdvisoryEcosystemFromPurlType(artifact.type);
|
|
212618
|
+
if (!ecosystem)
|
|
212619
|
+
continue;
|
|
212620
|
+
const manifestFiles = [];
|
|
212621
|
+
switch (ecosystem) {
|
|
212622
|
+
case "MAVEN": {
|
|
212623
|
+
manifestFiles.push(...(await getFilesRelative(rootWorkingDirectory)).filter((file) => (0, import_picomatch4.default)("{{*-*.,}pom{.xml,},gradle.lockfile}")(basename10(file))));
|
|
212624
|
+
break;
|
|
212625
|
+
}
|
|
212626
|
+
case "NUGET": {
|
|
212627
|
+
manifestFiles.push(...(await getFilesRelative(rootWorkingDirectory)).filter((file) => (0, import_picomatch4.default)("{*.csproj,packages.lock.json}")(basename10(file))));
|
|
212628
|
+
break;
|
|
212629
|
+
}
|
|
212630
|
+
case "PIP": {
|
|
212631
|
+
const sPurl = simplePurl(artifact.type, artifact.namespace ?? "", artifact.name, artifact.version ?? "");
|
|
212632
|
+
if (pipArtifactToRepresentativeManifest[sPurl]) {
|
|
212633
|
+
manifestFiles.push(...(pipArtifactToRepresentativeManifest[sPurl].manifestFiles ?? []).map((ref) => ref.file));
|
|
212634
|
+
}
|
|
212635
|
+
processToplevelAncestors2(artifact);
|
|
212636
|
+
break;
|
|
212637
|
+
}
|
|
212638
|
+
default: {
|
|
212639
|
+
artifact.manifestFiles?.forEach((ref) => manifestFiles.push(ref.file));
|
|
212640
|
+
processToplevelAncestors2(artifact);
|
|
212641
|
+
break;
|
|
212642
|
+
}
|
|
212643
|
+
}
|
|
212644
|
+
const workspaceToManifestFiles = {};
|
|
212645
|
+
manifestFiles.forEach((manifestFile) => {
|
|
212646
|
+
const workspace = inferWorkspaceFromManifestPath(ecosystem, manifestFile, properPythonProjects);
|
|
212647
|
+
if (!workspace)
|
|
212648
|
+
return;
|
|
212649
|
+
(workspaceToManifestFiles[workspace] ??= []).push(manifestFile);
|
|
212650
|
+
});
|
|
212651
|
+
if (Object.keys(workspaceToManifestFiles).length === 0) {
|
|
212652
|
+
manifestFiles.forEach((manifestFile) => {
|
|
212653
|
+
const workspace = inferProjectFromManifestPath(ecosystem, manifestFile);
|
|
212654
|
+
if (!workspace)
|
|
212655
|
+
return;
|
|
212656
|
+
(workspaceToManifestFiles[workspace] ??= []).push(manifestFile);
|
|
212657
|
+
});
|
|
212658
|
+
}
|
|
212659
|
+
if (Object.keys(workspaceToManifestFiles).length === 0 && artifact.vulnerabilities && artifact.vulnerabilities.length > 0) {
|
|
212660
|
+
const purl = new import_packageurl_js2.PackageURL(artifact.type, artifact.namespace, artifact.name, artifact.version, artifact.qualifiers).toString();
|
|
212661
|
+
purlsFailedToFindWorkspace.add(purl);
|
|
212662
|
+
}
|
|
212663
|
+
for (const [workspace, manifestFiles2] of Object.entries(workspaceToManifestFiles)) {
|
|
212664
|
+
const workspaceData = (ecosystemToWorkspaceToAnalysisData[ecosystem] ??= {})[workspace] ??= {
|
|
212665
|
+
type: "socket",
|
|
212666
|
+
data: {
|
|
212667
|
+
type: ecosystem,
|
|
212668
|
+
manifestFiles: manifestFiles2,
|
|
212669
|
+
artifacts: []
|
|
212670
|
+
}
|
|
212671
|
+
};
|
|
212672
|
+
workspaceData.type;
|
|
212673
|
+
workspaceData.data.artifacts.push(artifact);
|
|
212674
|
+
}
|
|
212675
|
+
if (artifact.vulnerabilities && artifact.vulnerabilities.length > 0) {
|
|
212676
|
+
for (const workspace of Object.keys(workspaceToManifestFiles)) {
|
|
212677
|
+
for (const vuln of artifact.vulnerabilities) {
|
|
212678
|
+
const vulnerability = {
|
|
212679
|
+
url: vuln.ghsaId,
|
|
212680
|
+
purlType: artifact.type,
|
|
212681
|
+
range: vuln.range,
|
|
212682
|
+
name: artifact.name ?? "",
|
|
212683
|
+
dependency: artifact.name ?? "",
|
|
212684
|
+
vulnChainDetails: computeVulnChainDetails(artifacts, artifact.id),
|
|
212685
|
+
vulnerabilityAccessPaths: vuln.reachabilityData?.undeterminableReachability ? vuln.reachabilityData.publicComment ?? "" : vuln.reachabilityData?.pattern ?? null,
|
|
212686
|
+
ecosystem,
|
|
212687
|
+
artifactId: artifact.id
|
|
212688
|
+
};
|
|
212689
|
+
const vulnId = `${ecosystem}-${workspace}-${vulnerability.url}`;
|
|
212690
|
+
if (!ecosystemWorkspaceVulnIds.has(vulnId)) {
|
|
212691
|
+
ecosystemWorkspaceVulnIds.add(vulnId);
|
|
212692
|
+
((ecosystemToWorkspaceToVulnerabilities[ecosystem] ??= {})[workspace] ??= []).push(vulnerability);
|
|
212693
|
+
}
|
|
212694
|
+
}
|
|
212695
|
+
}
|
|
212696
|
+
}
|
|
212697
|
+
}
|
|
212698
|
+
if (purlsFailedToFindWorkspace.size > 0) {
|
|
212699
|
+
logger.warn(`Failed to find workspace for the following purls with vulnerabilities: ${Array.from(purlsFailedToFindWorkspace).join(", ")}.
|
|
212700
|
+
${mode === "reachability" ? "This means that we will not do a full reachability analysis for these vulnerabilities, but fallback to the results from the pre-computed reachability analysis." : ""}`);
|
|
212701
|
+
}
|
|
212702
|
+
return {
|
|
212703
|
+
artifacts,
|
|
212704
|
+
ecosystemToWorkspaceToAnalysisData,
|
|
212705
|
+
ecosystemToWorkspaceToVulnerabilities
|
|
212706
|
+
};
|
|
212707
|
+
} catch (error) {
|
|
212708
|
+
logger.error("Failed to fetch artifacts from Socket backend", error);
|
|
212709
|
+
throw error;
|
|
212710
|
+
}
|
|
212711
|
+
}
|
|
212712
|
+
function computeVulnChainDetails(artifacts, vulnerableArtifactId) {
|
|
212713
|
+
const artifactMap = new Map(artifacts.map((a4) => [a4.id, a4]));
|
|
212714
|
+
const parentsMap = /* @__PURE__ */ new Map();
|
|
212715
|
+
for (const artifact of artifacts) {
|
|
212716
|
+
if (artifact.dependencies) {
|
|
212717
|
+
for (const depId of artifact.dependencies) {
|
|
212718
|
+
if (!parentsMap.has(depId)) {
|
|
212719
|
+
parentsMap.set(depId, []);
|
|
212720
|
+
}
|
|
212721
|
+
parentsMap.get(depId).push(artifact.id);
|
|
212722
|
+
}
|
|
212723
|
+
}
|
|
212724
|
+
}
|
|
212725
|
+
const res = {
|
|
212726
|
+
packageName: "root",
|
|
212727
|
+
version: "0.0.0",
|
|
212728
|
+
children: [],
|
|
212729
|
+
transitiveDependencies: {}
|
|
212730
|
+
};
|
|
212731
|
+
function addNode(currentId, childId, visited) {
|
|
212732
|
+
if (visited.has(currentId))
|
|
212733
|
+
return;
|
|
212734
|
+
const currentArtifact = artifactMap.get(currentId);
|
|
212735
|
+
if (!currentArtifact)
|
|
212736
|
+
return;
|
|
212737
|
+
const parents4 = parentsMap.get(currentId);
|
|
212738
|
+
const newCurrentNode = {
|
|
212739
|
+
packageName: getNameFromNamespaceAndName(currentArtifact.type, currentArtifact.namespace, currentArtifact.name),
|
|
212740
|
+
version: currentArtifact.version ?? void 0,
|
|
212741
|
+
children: []
|
|
212742
|
+
};
|
|
212743
|
+
res.transitiveDependencies[currentId] = newCurrentNode;
|
|
212744
|
+
if (childId && !newCurrentNode.children.includes(childId)) {
|
|
212745
|
+
newCurrentNode.children.push(childId);
|
|
212746
|
+
}
|
|
212747
|
+
if (currentId === vulnerableArtifactId) {
|
|
212748
|
+
newCurrentNode.vulnerable = true;
|
|
212749
|
+
}
|
|
212750
|
+
if (currentArtifact.direct && !res.children.includes(currentId)) {
|
|
212751
|
+
res.children.push(currentId);
|
|
212752
|
+
}
|
|
212753
|
+
visited.add(currentId);
|
|
212754
|
+
if (parents4) {
|
|
212755
|
+
for (const parentId of parents4) {
|
|
212756
|
+
addNode(parentId, currentId, visited);
|
|
212757
|
+
}
|
|
212758
|
+
}
|
|
212759
|
+
}
|
|
212760
|
+
addNode(vulnerableArtifactId, void 0, /* @__PURE__ */ new Set());
|
|
212761
|
+
return res;
|
|
212762
|
+
}
|
|
212763
|
+
|
|
212764
|
+
// dist/cli-upgrade-purl.js
|
|
212765
|
+
var ECOSYSTEMS_WITH_SOCKET_UPGRADES = ["NPM", "MAVEN", "NUGET", "GO", "RUST"];
|
|
212766
|
+
async function upgradePurl(rootDir, upgrades, options, logFile, cliFixRunId) {
|
|
212767
|
+
if (options.rangeStyle && options.rangeStyle !== "pin") {
|
|
212768
|
+
throw new Error('Range style must be "pin"');
|
|
212769
|
+
}
|
|
212770
|
+
logger.initWinstonLogger(options.debug);
|
|
212771
|
+
logger.silent = options.silent;
|
|
212772
|
+
let cliRunId = cliFixRunId;
|
|
212773
|
+
if (!cliRunId && options.manifestsTarHash) {
|
|
212774
|
+
cliRunId = await getSocketAPI().registerAutofixOrUpgradePurlRun(options.manifestsTarHash, options, "upgrade-purls");
|
|
212775
|
+
}
|
|
212776
|
+
const upgradePurlRunId = cliRunId && await getSocketAPI().registerUpgradePurlRun(cliRunId, upgrades);
|
|
212777
|
+
Spinner.instance({
|
|
212778
|
+
text: "Running Coana Upgrade Purl CLI",
|
|
212779
|
+
isSilent: options.silentSpinner ?? options.silent
|
|
212780
|
+
}).start();
|
|
212781
|
+
try {
|
|
212782
|
+
logger.info(`Upgrading purls for ${rootDir}:
|
|
212783
|
+
${upgrades.map(({ purl, upgradeVersion }) => ` ${prettyPrintPurlUpgrade(purl, upgradeVersion)}`).join("\n")}`);
|
|
212784
|
+
if (options.manifestsTarHash) {
|
|
212785
|
+
const { supportedUpgrades, unsupportedUpgrades } = upgrades.reduce((acc, upgrade) => {
|
|
212786
|
+
const ecosystem = getAdvisoryEcosystemFromPurl(upgrade.purl);
|
|
212787
|
+
const target = ECOSYSTEMS_WITH_SOCKET_UPGRADES.includes(ecosystem) ? "supportedUpgrades" : "unsupportedUpgrades";
|
|
212788
|
+
acc[target].push(upgrade);
|
|
212789
|
+
return acc;
|
|
212790
|
+
}, { supportedUpgrades: [], unsupportedUpgrades: [] });
|
|
212791
|
+
if (unsupportedUpgrades.length > 0) {
|
|
212792
|
+
logger.warn(`The following upgrades are not supported due to missing support for upgrading their ecosystem: ${unsupportedUpgrades.map(({ purl, upgradeVersion }) => ` ${prettyPrintPurlUpgrade(purl, upgradeVersion)}`).join("\n")}`);
|
|
212793
|
+
}
|
|
212794
|
+
if (supportedUpgrades.length === 0) {
|
|
212795
|
+
return "fixed-none";
|
|
212796
|
+
}
|
|
212797
|
+
try {
|
|
212798
|
+
const purlToUpgradeVersion = new Map(supportedUpgrades.map((upgrade) => [upgrade.purl, upgrade.upgradeVersion]));
|
|
212799
|
+
const [manifestFiles, artifacts] = await Promise.all([
|
|
212800
|
+
fetchManifestFilesFromManifestsTarHash(options.manifestsTarHash),
|
|
212801
|
+
(await fetchArtifactsFromSocket(rootDir, options.manifestsTarHash, "upgrade-purls")).artifacts
|
|
212802
|
+
]);
|
|
212803
|
+
const ecosystemToSocketArtifactUpgrades = /* @__PURE__ */ new Map();
|
|
212804
|
+
artifacts.forEach((artifact, idx) => {
|
|
212805
|
+
if (!artifact.name)
|
|
212806
|
+
return;
|
|
212807
|
+
if (!artifact.version)
|
|
212808
|
+
return;
|
|
212809
|
+
const purl = new import_packageurl_js3.PackageURL(artifact.type, artifact.namespace, artifact.name, artifact.version, artifact.qualifiers).toString();
|
|
212810
|
+
const upgradeVersion = purlToUpgradeVersion.get(purl);
|
|
212811
|
+
if (!upgradeVersion)
|
|
212812
|
+
return;
|
|
212813
|
+
const ecosystem = getAdvisoryEcosystemFromPurlType(artifact.type);
|
|
212814
|
+
if (!ecosystemToSocketArtifactUpgrades.has(ecosystem)) {
|
|
212815
|
+
ecosystemToSocketArtifactUpgrades.set(ecosystem, /* @__PURE__ */ new Map());
|
|
212816
|
+
}
|
|
212817
|
+
const currentUpgradeVersion = ecosystemToSocketArtifactUpgrades.get(ecosystem).get(idx);
|
|
212818
|
+
if (currentUpgradeVersion === void 0) {
|
|
212819
|
+
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, upgradeVersion);
|
|
212820
|
+
} else {
|
|
212821
|
+
const versions = sortVersions(ecosystem, [artifact.version, currentUpgradeVersion, upgradeVersion]);
|
|
212822
|
+
if (versionSatisfiesRelation(ecosystem, artifact.version, "=", versions[0])) {
|
|
212823
|
+
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, versions[versions.length - 1]);
|
|
212824
|
+
} else if (versionSatisfiesRelation(ecosystem, artifact.version, "=", versions[versions.length - 1])) {
|
|
212825
|
+
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, versions[0]);
|
|
212826
|
+
} else {
|
|
212827
|
+
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, versions[versions.length - 1]);
|
|
212828
|
+
}
|
|
212829
|
+
}
|
|
212830
|
+
});
|
|
212831
|
+
let anyErrors = false;
|
|
212832
|
+
for (const [ecosystem, upgrades2] of ecosystemToSocketArtifactUpgrades) {
|
|
212833
|
+
if (options.rangeStyle && !["NPM", "MAVEN", "NUGET", "RUST"].includes(ecosystem)) {
|
|
212834
|
+
logger.warn(`Range style is not supported for ${ecosystem}, skipping upgrades`);
|
|
212835
|
+
continue;
|
|
212836
|
+
}
|
|
212837
|
+
const statusUpdater = (update2) => {
|
|
212838
|
+
const statusIcons = {
|
|
212839
|
+
success: "\u2705",
|
|
212840
|
+
skipped: "\u26AA",
|
|
212841
|
+
warn: "\u26A0\uFE0F",
|
|
212842
|
+
error: "\u274C"
|
|
212843
|
+
};
|
|
212844
|
+
logger.info(`${statusIcons[update2.status]} ${update2.message} \u2500 ${relative14(rootDir, resolve32(rootDir, update2.file))}`);
|
|
212845
|
+
update2.artifacts.forEach((idx, i7) => {
|
|
212846
|
+
logger.info(`${" ".repeat(3)}${i7 === update2.artifacts.length - 1 ? "\u2514\u2500" : "\u251C\u2500"} ${prettyPrintSocketFactArtifactUpgrade(artifacts[idx], upgrades2.get(idx))}`);
|
|
212847
|
+
});
|
|
212848
|
+
for (const detail of update2.details ?? []) {
|
|
212849
|
+
logger.debug(detail);
|
|
212850
|
+
}
|
|
212851
|
+
if (update2.patch)
|
|
212852
|
+
logger.debug(update2.patch);
|
|
212853
|
+
if (update2.status === "error")
|
|
212854
|
+
anyErrors = true;
|
|
212855
|
+
};
|
|
212856
|
+
const ctxt = {
|
|
212857
|
+
manifestFiles,
|
|
212858
|
+
upgrades: upgrades2,
|
|
212859
|
+
artifacts,
|
|
212860
|
+
rangeStyle: options.rangeStyle,
|
|
212861
|
+
statusUpdater
|
|
212862
|
+
};
|
|
212863
|
+
await applySocketUpgrades(ecosystem, rootDir, ctxt);
|
|
212864
|
+
}
|
|
212865
|
+
if (upgradePurlRunId) {
|
|
212866
|
+
await getSocketAPI().finalizeUpgradePurlRun(upgradePurlRunId, "succeeded");
|
|
212867
|
+
}
|
|
212868
|
+
return unsupportedUpgrades.length === 0 && !anyErrors ? "fixed-all" : "fixed-some";
|
|
212869
|
+
} catch (error) {
|
|
212870
|
+
if (upgradePurlRunId) {
|
|
212871
|
+
await getSocketAPI().finalizeUpgradePurlRun(
|
|
212872
|
+
upgradePurlRunId,
|
|
212873
|
+
"error",
|
|
212874
|
+
!cliFixRunId ? error.stack : void 0,
|
|
212875
|
+
// do not send stack trace and logContent for computeFixes runs, as that will be handled by that command.
|
|
212876
|
+
!cliFixRunId && logFile ? await logger.getLogContent(logFile) : void 0
|
|
212877
|
+
);
|
|
212878
|
+
}
|
|
212879
|
+
throw error;
|
|
212880
|
+
}
|
|
212881
|
+
}
|
|
212882
|
+
const otherModulesCommunicator = new OtherModulesCommunicator(rootDir, options, {
|
|
212883
|
+
type: "missing"
|
|
212884
|
+
});
|
|
212885
|
+
const ecosystems = upgrades.map((upgrade) => getAdvisoryEcosystemFromPurl(upgrade.purl));
|
|
212886
|
+
const manager = await ProjectManager.create(rootDir, otherModulesCommunicator, ecosystems);
|
|
212887
|
+
const { reachabilitySupport, traditionalScaSupport } = manager.getSubprojectsWithWorkspacePaths();
|
|
212888
|
+
const supportedSubprojects = reachabilitySupport.concat(traditionalScaSupport).filter((p3) => getPackageManagerSupport(p3.packageManagerName).supportsApplyingFixes);
|
|
212889
|
+
if (supportedSubprojects.length === 0) {
|
|
212890
|
+
throw new Error(`No supported projects found in ${rootDir}.`);
|
|
212891
|
+
}
|
|
212892
|
+
const subprojectPromiseQueue = new PromiseQueue(Number(options.concurrency));
|
|
212893
|
+
supportedSubprojects.forEach((subproject) => {
|
|
212894
|
+
subprojectPromiseQueue.enqueueTask(async () => {
|
|
212895
|
+
const workspacePathsMatchingGlob = subproject.workspacePaths.filter((wsPath) => minimatch(join25(subproject.subprojectPath, wsPath), options.globPattern ?? "**"));
|
|
212896
|
+
if (workspacePathsMatchingGlob.length === 0)
|
|
212897
|
+
return;
|
|
212898
|
+
logger.info(`Found workspaces for subproject ${subproject.subprojectPath}${options.globPattern ? `matching glob ${options.globPattern}` : ""}:
|
|
212899
|
+
${workspacePathsMatchingGlob.map((wsPath) => ` ${wsPath}`).join("\n")}`);
|
|
212900
|
+
const fixingData = await otherModulesCommunicator.getFixingData(subproject.packageManagerName, subproject.subprojectPath, workspacePathsMatchingGlob);
|
|
212901
|
+
const workspaceToFixes = {};
|
|
212902
|
+
Object.entries(fixingData.dependencyTrees).forEach(([wsPath, depTree]) => {
|
|
212903
|
+
const vulnerabilityFixes = [];
|
|
212904
|
+
const simplePurlToDepId = getPurlStrings(depTree);
|
|
212905
|
+
upgrades.forEach((upgrade) => {
|
|
212906
|
+
const purl = import_packageurl_js3.PackageURL.fromString(upgrade.purl);
|
|
212907
|
+
if (purl.version === void 0)
|
|
212908
|
+
throw Error(`Undefined version for purl ${upgrade.purl}`);
|
|
212909
|
+
const simplePurl2 = `pkg:${purl.type}/${purl.namespace ? `${purl.namespace}/` : ""}${purl.name}${purl.version ? `@${purl.version}` : ""}`;
|
|
212910
|
+
for (const depIdMatchingPurl of simplePurlToDepId[simplePurl2] ?? []) {
|
|
212911
|
+
const node = depTree.transitiveDependencies[depIdMatchingPurl];
|
|
212912
|
+
if (!node)
|
|
212913
|
+
throw Error("should not happen!");
|
|
212914
|
+
vulnerabilityFixes.push({
|
|
212915
|
+
dependencyName: node.packageName,
|
|
212916
|
+
currentVersion: assertDefined(node.version),
|
|
212917
|
+
dependencyIdentifier: depIdMatchingPurl,
|
|
212918
|
+
fixedVersion: upgrade.upgradeVersion
|
|
212919
|
+
});
|
|
212920
|
+
}
|
|
212921
|
+
});
|
|
212922
|
+
if (vulnerabilityFixes.length === 0)
|
|
212923
|
+
return;
|
|
212924
|
+
logger.info(`Found ${vulnerabilityFixes.length} ${vulnerabilityFixes.length === 1 ? "dependency" : "dependencies"} matching upgrade specs for ${join25(subproject.subprojectPath, wsPath)}`);
|
|
212925
|
+
workspaceToFixes[wsPath] = [
|
|
212926
|
+
{
|
|
212927
|
+
fixId: "dummy",
|
|
212928
|
+
vulnerabilityFixes
|
|
212929
|
+
}
|
|
212930
|
+
];
|
|
212931
|
+
});
|
|
212932
|
+
if (Object.entries(workspaceToFixes).length === 0) {
|
|
212933
|
+
logger.info(`No dependencies matching upgrade specs found for subproject ${subproject.subprojectPath}`);
|
|
212934
|
+
return;
|
|
212935
|
+
}
|
|
212936
|
+
await applySecurityFixes(subproject.packageManagerName, rootDir, relative14(rootDir, subproject.subprojectPath) || ".", otherModulesCommunicator, workspaceToFixes, fixingData, signalFixApplied);
|
|
212937
|
+
});
|
|
212938
|
+
});
|
|
212939
|
+
await subprojectPromiseQueue.onIdle();
|
|
212940
|
+
} finally {
|
|
212941
|
+
Spinner.instance().stop();
|
|
212942
|
+
}
|
|
212943
|
+
}
|
|
212944
|
+
var signalFixApplied = (_fixId, subprojectPath, workspacePath, vulnerabilityFixes) => {
|
|
212945
|
+
logger.info(`Successfully upgraded purls for: ${join25(subprojectPath, workspacePath)}`);
|
|
212946
|
+
logger.info(`Upgraded:
|
|
212947
|
+
${vulnerabilityFixes.map((fix) => ` ${fix.dependencyName} from ${fix.currentVersion} to ${fix.fixedVersion}`).join("\n")}`);
|
|
212948
|
+
};
|
|
212949
|
+
|
|
212950
|
+
// dist/cli-compute-fixes-and-upgrade-purls.js
|
|
212951
|
+
async function computeFixesAndUpgradePurls(path2, options, logFile) {
|
|
212952
|
+
const autofixRunId = options.manifestsTarHash && await getSocketAPI().registerAutofixOrUpgradePurlRun(options.manifestsTarHash, options, "autofix");
|
|
212953
|
+
const { artifacts, ghsaToVulnerableArtifactIds } = await computeInputForComputingFixes(path2, options);
|
|
212954
|
+
if (Object.keys(ghsaToVulnerableArtifactIds).length === 0) {
|
|
212955
|
+
logger.info("No vulnerabilities to compute fixes for");
|
|
212956
|
+
return { type: "no-vulnerabilities-found" };
|
|
212957
|
+
}
|
|
212958
|
+
if (options.applyFixesTo.length === 0) {
|
|
212959
|
+
logger.info("Vulnerabilities found:", Object.keys(ghsaToVulnerableArtifactIds).join(", "));
|
|
212960
|
+
logger.info("Run again with --apply-fixes-to GHSA_IDS to fix those vulnerabilities by computing packages to upgrade and apply them");
|
|
212961
|
+
return { type: "no-ghsas-fix-requested", ghsas: Object.keys(ghsaToVulnerableArtifactIds) };
|
|
212962
|
+
}
|
|
212963
|
+
const ghsaToVulnerableArtifactIdsToApply = options.applyFixesTo.includes("all") ? ghsaToVulnerableArtifactIds : Object.fromEntries(Object.entries(ghsaToVulnerableArtifactIds).filter(([ghsa]) => options.applyFixesTo.includes(ghsa)));
|
|
212964
|
+
const computedFix = await useSocketComputeFixEndpoint(autofixRunId, artifacts, ghsaToVulnerableArtifactIdsToApply, {
|
|
212965
|
+
noMajorUpdates: options.disableMajorUpdates,
|
|
212966
|
+
minimumReleaseAgeInMinutes: options.minimumReleaseAgeInMinutes
|
|
212967
|
+
});
|
|
212968
|
+
if (computedFix.type !== "success") {
|
|
212969
|
+
throw new Error(`No fix found for the given vulnerabilities`);
|
|
212970
|
+
}
|
|
212971
|
+
const ghsasFailedToFix = Object.keys(ghsaToVulnerableArtifactIdsToApply).filter((ghsa) => {
|
|
212972
|
+
const artifactIds = ghsaToVulnerableArtifactIdsToApply[ghsa];
|
|
212973
|
+
if (!artifactIds)
|
|
212974
|
+
return false;
|
|
212975
|
+
return artifactIds.some((artifactId) => computedFix.ghsaToResult[ghsa].failedArtifacts?.includes(artifactId));
|
|
212976
|
+
});
|
|
212977
|
+
if (ghsasFailedToFix.length > 0) {
|
|
212978
|
+
logger.info("Failed to compute fixes for the following vulnerabilities:");
|
|
212979
|
+
}
|
|
212980
|
+
for (const ghsa of ghsasFailedToFix) {
|
|
212981
|
+
logger.info(` - ${ghsa} (${ghsaToVulnerableArtifactIdsToApply[ghsa].map((id) => simplePurl(artifacts[id].type, artifacts[id].namespace ?? null, artifacts[id].name ?? "", artifacts[id].version ?? null)).join(", ")})`);
|
|
212982
|
+
}
|
|
212983
|
+
const fixesFound = Object.entries(computedFix.ghsaToResult).filter(([_, result]) => result.failedArtifacts === void 0 || result.failedArtifacts.length === 0);
|
|
212984
|
+
if (options.onlyDirectDependencyUpgrades) {
|
|
212985
|
+
return computeDirectDependencyUpgrades(artifacts, fixesFound);
|
|
212986
|
+
}
|
|
212987
|
+
const combinedFixes = fixesFound.flatMap(([_, result]) => result.fixes);
|
|
212988
|
+
if (options.dryRun) {
|
|
212989
|
+
logger.info("Fixes found:");
|
|
212990
|
+
for (const [ghsa, result] of fixesFound) {
|
|
212991
|
+
logger.info(` - ${ghsa}:`);
|
|
212992
|
+
for (const fix of result.fixes) {
|
|
212993
|
+
logger.info(` - ${fix.purl} -> ${fix.fixedVersion}`);
|
|
212994
|
+
}
|
|
212995
|
+
}
|
|
212996
|
+
return {
|
|
212997
|
+
type: "dry-run-result",
|
|
212998
|
+
fixes: Object.fromEntries(fixesFound.map(([ghsa, result]) => [ghsa, result.fixes])),
|
|
212999
|
+
...ghsasFailedToFix.length > 0 && { failedToFix: ghsasFailedToFix }
|
|
213000
|
+
};
|
|
213001
|
+
}
|
|
213002
|
+
if (combinedFixes.length === 0) {
|
|
213003
|
+
if (autofixRunId) {
|
|
213004
|
+
await getSocketAPI().finalizeAutofixRun(autofixRunId, "fixed-none");
|
|
213005
|
+
}
|
|
213006
|
+
throw new Error("Failed to find a fix for the given vulnerabilities");
|
|
213007
|
+
}
|
|
213008
|
+
try {
|
|
213009
|
+
const applyFixesStatus = await upgradePurl(path2, T3(combinedFixes, (fix) => `${fix.purl}${fix.fixedVersion}`).map((fix) => ({
|
|
213010
|
+
purl: fix.purl,
|
|
213011
|
+
upgradeVersion: fix.fixedVersion
|
|
213012
|
+
})), {
|
|
213013
|
+
debug: options.debug,
|
|
213014
|
+
silent: options.silent,
|
|
213015
|
+
runWithoutDocker: options.runWithoutDocker,
|
|
213016
|
+
manifestsTarHash: options.manifestsTarHash,
|
|
213017
|
+
concurrency: "1",
|
|
213018
|
+
globPattern: options.globPattern,
|
|
213019
|
+
rangeStyle: options.rangeStyle
|
|
213020
|
+
}, void 0, autofixRunId) ?? "fixed-all";
|
|
213021
|
+
if (autofixRunId) {
|
|
213022
|
+
await getSocketAPI().finalizeAutofixRun(autofixRunId, ghsasFailedToFix.length === 0 && applyFixesStatus === "fixed-all" ? "fixed-all" : ghsasFailedToFix.length === Object.keys(ghsaToVulnerableArtifactIdsToApply).length || applyFixesStatus === "fixed-none" ? "fixed-none" : "fixed-some");
|
|
213023
|
+
}
|
|
213024
|
+
return {
|
|
213025
|
+
type: "applied-fixes",
|
|
213026
|
+
fixes: Object.fromEntries(fixesFound.map(([ghsa, result]) => [ghsa, result.fixes]))
|
|
213027
|
+
};
|
|
213028
|
+
} catch (error) {
|
|
213029
|
+
if (autofixRunId) {
|
|
213030
|
+
await getSocketAPI().finalizeAutofixRun(autofixRunId, "error", error.stack, await logger.getLogContent(logFile));
|
|
213031
|
+
}
|
|
213032
|
+
logger.error("Error applying fixes:", error);
|
|
213033
|
+
throw error;
|
|
213034
|
+
}
|
|
213035
|
+
}
|
|
213036
|
+
async function computeInputForComputingFixes(path2, options) {
|
|
213037
|
+
if (options.manifestsTarHash) {
|
|
213038
|
+
const { artifacts } = await fetchArtifactsFromSocket(path2, options.manifestsTarHash, "autofix");
|
|
213039
|
+
const ghsaToVulnerableArtifactIds = {};
|
|
213040
|
+
for (const [index2, artifact] of artifacts.entries()) {
|
|
213041
|
+
if (!artifact.vulnerabilities)
|
|
213042
|
+
continue;
|
|
213043
|
+
for (const vulnerability of artifact.vulnerabilities) {
|
|
213044
|
+
if (!(ghsaToVulnerableArtifactIds[vulnerability.ghsaId] ??= []).includes(index2)) {
|
|
213045
|
+
ghsaToVulnerableArtifactIds[vulnerability.ghsaId].push(index2);
|
|
213046
|
+
}
|
|
213047
|
+
}
|
|
213048
|
+
}
|
|
213049
|
+
const sbomTaskArtifacts = artifacts.map((artifact) => ({
|
|
213050
|
+
type: artifact.type,
|
|
213051
|
+
name: artifact.name ?? "",
|
|
213052
|
+
version: artifact.version ?? "",
|
|
213053
|
+
namespace: artifact.namespace ?? void 0,
|
|
213054
|
+
adj: artifact.dependencies?.map((dep) => artifacts.findIndex((a4) => a4.id === dep)) ?? [],
|
|
213055
|
+
direct: artifact.direct,
|
|
213056
|
+
topLevelAncestors: artifact.toplevelAncestors?.map((ancestor) => artifacts.findIndex((a4) => a4.id === ancestor)) ?? []
|
|
213057
|
+
}));
|
|
213058
|
+
return { artifacts: sbomTaskArtifacts, ghsaToVulnerableArtifactIds };
|
|
213059
|
+
}
|
|
213060
|
+
throw new Error("Fixes are only supported when using --manifests-tar-hash");
|
|
213061
|
+
}
|
|
213062
|
+
async function computeDirectDependencyUpgrades(artifacts, fixesFound) {
|
|
213063
|
+
const purlToArtifact = Object.fromEntries(artifacts.map((a4) => [simplePurl(a4.type, a4.namespace ?? null, a4.name ?? "", a4.version ?? null), a4]));
|
|
213064
|
+
const packageFixes = {};
|
|
213065
|
+
for (const [ghsa, result2] of fixesFound) {
|
|
213066
|
+
const directUpdates = {};
|
|
213067
|
+
for (const directFix of result2.fixes.filter((fix) => purlToArtifact[fix.purl]?.direct)) {
|
|
213068
|
+
directUpdates[directFix.purl] = { fixedVersion: directFix.fixedVersion };
|
|
213069
|
+
}
|
|
213070
|
+
const directUpdatePurls = Object.keys(directUpdates);
|
|
213071
|
+
for (const indirectFix of result2.fixes.filter((fix) => !purlToArtifact[fix.purl]?.direct)) {
|
|
213072
|
+
const directDependencies = purlToArtifact[indirectFix.purl]?.topLevelAncestors;
|
|
213073
|
+
for (const directDependency of directDependencies) {
|
|
213074
|
+
const artifact = artifacts[directDependency];
|
|
213075
|
+
const purl = simplePurl(artifact.type, artifact.namespace ?? null, artifact.name ?? "", artifact.version ?? null);
|
|
213076
|
+
if (directUpdatePurls.includes(purl))
|
|
213077
|
+
continue;
|
|
213078
|
+
if (directUpdates[purl]) {
|
|
213079
|
+
(directUpdates[purl].transitiveFixes ??= []).push(indirectFix);
|
|
213080
|
+
} else {
|
|
213081
|
+
directUpdates[purl] = { transitiveFixes: [indirectFix] };
|
|
213082
|
+
}
|
|
213083
|
+
directUpdates[purl] = { transitiveFixes: [indirectFix] };
|
|
213084
|
+
}
|
|
213085
|
+
}
|
|
213086
|
+
packageFixes[ghsa] = {
|
|
213087
|
+
directDependencies: Object.entries(directUpdates).map(([purl, update2]) => ({ purl, ...update2 }))
|
|
213088
|
+
};
|
|
213089
|
+
}
|
|
213090
|
+
const result = {
|
|
213091
|
+
type: "only-direct-dependency-upgrades",
|
|
213092
|
+
fixes: packageFixes
|
|
213093
|
+
};
|
|
213094
|
+
logger.info("Affected direct dependencies and upgrades to fix (--show-affected-direct-dependencies does not apply the upgrades):", JSON.stringify(result, null, 2));
|
|
213095
|
+
return result;
|
|
213096
|
+
}
|
|
213097
|
+
|
|
213098
|
+
// dist/cli-core.js
|
|
213099
|
+
import { writeFileSync as writeFileSync3 } from "fs";
|
|
213100
|
+
import { mkdir as mkdir2, writeFile as writeFile10 } from "fs/promises";
|
|
213101
|
+
|
|
213102
|
+
// ../../node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
|
|
213103
|
+
var FORCE_COLOR;
|
|
213104
|
+
var NODE_DISABLE_COLORS;
|
|
213105
|
+
var NO_COLOR;
|
|
213106
|
+
var TERM;
|
|
213107
|
+
var isTTY = true;
|
|
213108
|
+
if (typeof process !== "undefined") {
|
|
213109
|
+
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
|
213110
|
+
isTTY = process.stdout && process.stdout.isTTY;
|
|
213111
|
+
}
|
|
213112
|
+
var $ = {
|
|
213113
|
+
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY),
|
|
213114
|
+
// modifiers
|
|
213115
|
+
reset: init(0, 0),
|
|
213116
|
+
bold: init(1, 22),
|
|
213117
|
+
dim: init(2, 22),
|
|
213118
|
+
italic: init(3, 23),
|
|
213119
|
+
underline: init(4, 24),
|
|
213120
|
+
inverse: init(7, 27),
|
|
213121
|
+
hidden: init(8, 28),
|
|
213122
|
+
strikethrough: init(9, 29),
|
|
213123
|
+
// colors
|
|
213124
|
+
black: init(30, 39),
|
|
213125
|
+
red: init(31, 39),
|
|
213126
|
+
green: init(32, 39),
|
|
213127
|
+
yellow: init(33, 39),
|
|
213128
|
+
blue: init(34, 39),
|
|
213129
|
+
magenta: init(35, 39),
|
|
213130
|
+
cyan: init(36, 39),
|
|
213131
|
+
white: init(37, 39),
|
|
213132
|
+
gray: init(90, 39),
|
|
213133
|
+
grey: init(90, 39),
|
|
213134
|
+
// background colors
|
|
213135
|
+
bgBlack: init(40, 49),
|
|
213136
|
+
bgRed: init(41, 49),
|
|
213137
|
+
bgGreen: init(42, 49),
|
|
213138
|
+
bgYellow: init(43, 49),
|
|
213139
|
+
bgBlue: init(44, 49),
|
|
213140
|
+
bgMagenta: init(45, 49),
|
|
213141
|
+
bgCyan: init(46, 49),
|
|
213142
|
+
bgWhite: init(47, 49)
|
|
213143
|
+
};
|
|
213144
|
+
function run(arr, str) {
|
|
213145
|
+
let i7 = 0, tmp, beg = "", end2 = "";
|
|
213146
|
+
for (; i7 < arr.length; i7++) {
|
|
213147
|
+
tmp = arr[i7];
|
|
213148
|
+
beg += tmp.open;
|
|
213149
|
+
end2 += tmp.close;
|
|
213150
|
+
if (!!~str.indexOf(tmp.close)) {
|
|
213151
|
+
str = str.replace(tmp.rgx, tmp.close + tmp.open);
|
|
213152
|
+
}
|
|
213153
|
+
}
|
|
213154
|
+
return beg + str + end2;
|
|
213155
|
+
}
|
|
213156
|
+
function chain(has2, keys) {
|
|
213157
|
+
let ctx = { has: has2, keys };
|
|
213158
|
+
ctx.reset = $.reset.bind(ctx);
|
|
213159
|
+
ctx.bold = $.bold.bind(ctx);
|
|
213160
|
+
ctx.dim = $.dim.bind(ctx);
|
|
213161
|
+
ctx.italic = $.italic.bind(ctx);
|
|
213162
|
+
ctx.underline = $.underline.bind(ctx);
|
|
213163
|
+
ctx.inverse = $.inverse.bind(ctx);
|
|
213164
|
+
ctx.hidden = $.hidden.bind(ctx);
|
|
213165
|
+
ctx.strikethrough = $.strikethrough.bind(ctx);
|
|
213166
|
+
ctx.black = $.black.bind(ctx);
|
|
213167
|
+
ctx.red = $.red.bind(ctx);
|
|
213168
|
+
ctx.green = $.green.bind(ctx);
|
|
213169
|
+
ctx.yellow = $.yellow.bind(ctx);
|
|
213170
|
+
ctx.blue = $.blue.bind(ctx);
|
|
213171
|
+
ctx.magenta = $.magenta.bind(ctx);
|
|
213172
|
+
ctx.cyan = $.cyan.bind(ctx);
|
|
213173
|
+
ctx.white = $.white.bind(ctx);
|
|
213174
|
+
ctx.gray = $.gray.bind(ctx);
|
|
213175
|
+
ctx.grey = $.grey.bind(ctx);
|
|
213176
|
+
ctx.bgBlack = $.bgBlack.bind(ctx);
|
|
213177
|
+
ctx.bgRed = $.bgRed.bind(ctx);
|
|
213178
|
+
ctx.bgGreen = $.bgGreen.bind(ctx);
|
|
213179
|
+
ctx.bgYellow = $.bgYellow.bind(ctx);
|
|
213180
|
+
ctx.bgBlue = $.bgBlue.bind(ctx);
|
|
213181
|
+
ctx.bgMagenta = $.bgMagenta.bind(ctx);
|
|
213182
|
+
ctx.bgCyan = $.bgCyan.bind(ctx);
|
|
213183
|
+
ctx.bgWhite = $.bgWhite.bind(ctx);
|
|
213184
|
+
return ctx;
|
|
213185
|
+
}
|
|
213186
|
+
function init(open, close) {
|
|
213187
|
+
let blk = {
|
|
213188
|
+
open: `\x1B[${open}m`,
|
|
213189
|
+
close: `\x1B[${close}m`,
|
|
213190
|
+
rgx: new RegExp(`\\x1b\\[${close}m`, "g")
|
|
213191
|
+
};
|
|
213192
|
+
return function(txt) {
|
|
213193
|
+
if (this !== void 0 && this.has !== void 0) {
|
|
213194
|
+
!!~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk));
|
|
213195
|
+
return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + "";
|
|
213196
|
+
}
|
|
213197
|
+
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + "";
|
|
213198
|
+
};
|
|
213199
|
+
}
|
|
213200
|
+
var kleur_default = $;
|
|
213201
|
+
|
|
213202
|
+
// ../../node_modules/.pnpm/yoctocolors@2.1.2/node_modules/yoctocolors/base.js
|
|
213203
|
+
import tty from "node:tty";
|
|
213204
|
+
var hasColors = tty?.WriteStream?.prototype?.hasColors?.() ?? false;
|
|
213205
|
+
var format5 = (open, close) => {
|
|
213206
|
+
if (!hasColors) {
|
|
213207
|
+
return (input) => input;
|
|
213208
|
+
}
|
|
213209
|
+
const openCode = `\x1B[${open}m`;
|
|
213210
|
+
const closeCode = `\x1B[${close}m`;
|
|
213211
|
+
return (input) => {
|
|
213212
|
+
const string = input + "";
|
|
213213
|
+
let index2 = string.indexOf(closeCode);
|
|
213214
|
+
if (index2 === -1) {
|
|
213215
|
+
return openCode + string + closeCode;
|
|
213216
|
+
}
|
|
213217
|
+
let result = openCode;
|
|
213218
|
+
let lastIndex = 0;
|
|
213219
|
+
const reopenOnNestedClose = close === 22;
|
|
213220
|
+
const replaceCode = (reopenOnNestedClose ? closeCode : "") + openCode;
|
|
213221
|
+
while (index2 !== -1) {
|
|
213222
|
+
result += string.slice(lastIndex, index2) + replaceCode;
|
|
213223
|
+
lastIndex = index2 + closeCode.length;
|
|
213224
|
+
index2 = string.indexOf(closeCode, lastIndex);
|
|
213225
|
+
}
|
|
213226
|
+
result += string.slice(lastIndex) + closeCode;
|
|
213227
|
+
return result;
|
|
213228
|
+
};
|
|
213229
|
+
};
|
|
213230
|
+
var reset = format5(0, 0);
|
|
213231
|
+
var bold = format5(1, 22);
|
|
213232
|
+
var dim = format5(2, 22);
|
|
213233
|
+
var italic = format5(3, 23);
|
|
213234
|
+
var underline = format5(4, 24);
|
|
213235
|
+
var overline = format5(53, 55);
|
|
213236
|
+
var inverse = format5(7, 27);
|
|
213237
|
+
var hidden = format5(8, 28);
|
|
213238
|
+
var strikethrough = format5(9, 29);
|
|
213239
|
+
var black = format5(30, 39);
|
|
213240
|
+
var red = format5(31, 39);
|
|
213241
|
+
var green = format5(32, 39);
|
|
213242
|
+
var yellow = format5(33, 39);
|
|
213243
|
+
var blue = format5(34, 39);
|
|
213244
|
+
var magenta = format5(35, 39);
|
|
213245
|
+
var cyan = format5(36, 39);
|
|
213246
|
+
var white = format5(37, 39);
|
|
213247
|
+
var gray = format5(90, 39);
|
|
213248
|
+
var bgBlack = format5(40, 49);
|
|
213249
|
+
var bgRed = format5(41, 49);
|
|
213250
|
+
var bgGreen = format5(42, 49);
|
|
213251
|
+
var bgYellow = format5(43, 49);
|
|
213252
|
+
var bgBlue = format5(44, 49);
|
|
213253
|
+
var bgMagenta = format5(45, 49);
|
|
213254
|
+
var bgCyan = format5(46, 49);
|
|
213255
|
+
var bgWhite = format5(47, 49);
|
|
213256
|
+
var bgGray = format5(100, 49);
|
|
213257
|
+
var redBright = format5(91, 39);
|
|
213258
|
+
var greenBright = format5(92, 39);
|
|
213259
|
+
var yellowBright = format5(93, 39);
|
|
213260
|
+
var blueBright = format5(94, 39);
|
|
213261
|
+
var magentaBright = format5(95, 39);
|
|
213262
|
+
var cyanBright = format5(96, 39);
|
|
213263
|
+
var whiteBright = format5(97, 39);
|
|
213264
|
+
var bgRedBright = format5(101, 49);
|
|
213265
|
+
var bgGreenBright = format5(102, 49);
|
|
213266
|
+
var bgYellowBright = format5(103, 49);
|
|
213267
|
+
var bgBlueBright = format5(104, 49);
|
|
213268
|
+
var bgMagentaBright = format5(105, 49);
|
|
213269
|
+
var bgCyanBright = format5(106, 49);
|
|
213270
|
+
var bgWhiteBright = format5(107, 49);
|
|
213271
|
+
|
|
213272
|
+
// dist/cli-core.js
|
|
213273
|
+
var import_lodash15 = __toESM(require_lodash(), 1);
|
|
213274
|
+
import os from "os";
|
|
213275
|
+
import { join as join27, relative as relative15, resolve as resolve34 } from "path";
|
|
213276
|
+
|
|
213277
|
+
// ../utils/src/dashboard-api/shared-api.ts
|
|
213278
|
+
var DashboardAPI = class {
|
|
213279
|
+
socketMode;
|
|
213280
|
+
coanaAPI;
|
|
213281
|
+
socketAPI;
|
|
213282
|
+
disableAnalyticsSharing;
|
|
213283
|
+
constructor(socketMode, disableAnalyticsSharing) {
|
|
213284
|
+
this.socketMode = socketMode;
|
|
213285
|
+
this.disableAnalyticsSharing = disableAnalyticsSharing;
|
|
213286
|
+
this.coanaAPI = getCoanaAPI();
|
|
213287
|
+
this.socketAPI = getSocketAPI();
|
|
213288
|
+
}
|
|
213289
|
+
async createReport(repoUrl, projectName, cliVersion, commitSha, branchName, cliOptions, apiKey, cliRunEnv) {
|
|
213290
|
+
if (this.disableAnalyticsSharing) {
|
|
213291
|
+
return;
|
|
213292
|
+
}
|
|
213293
|
+
if (this.socketMode) {
|
|
213294
|
+
return (await this.socketAPI.createSocketTier1Scan(cliOptions, cliVersion)).tier1_reachability_scan_id;
|
|
213295
|
+
} else {
|
|
213296
|
+
return await this.coanaAPI.createCoanaReport(
|
|
213297
|
+
repoUrl,
|
|
213298
|
+
projectName,
|
|
213299
|
+
cliVersion,
|
|
213300
|
+
commitSha,
|
|
213301
|
+
branchName,
|
|
213302
|
+
cliOptions,
|
|
213303
|
+
apiKey,
|
|
213304
|
+
cliRunEnv
|
|
213305
|
+
);
|
|
212690
213306
|
}
|
|
212691
|
-
this.queue.push(task);
|
|
212692
|
-
this.runNextTask();
|
|
212693
213307
|
}
|
|
212694
|
-
async
|
|
212695
|
-
|
|
212696
|
-
|
|
212697
|
-
|
|
212698
|
-
|
|
212699
|
-
|
|
212700
|
-
|
|
212701
|
-
|
|
212702
|
-
|
|
212703
|
-
|
|
212704
|
-
|
|
212705
|
-
|
|
213308
|
+
async sendErrorReport(apiKey, stackTrace, shouldLogSharing, reportId, repoUrl, projectName, logContent) {
|
|
213309
|
+
if (this.disableAnalyticsSharing) {
|
|
213310
|
+
return;
|
|
213311
|
+
}
|
|
213312
|
+
if (this.socketMode) {
|
|
213313
|
+
await this.socketAPI.sendErrorReportToSocketDashboard(stackTrace, shouldLogSharing, reportId, logContent);
|
|
213314
|
+
} else {
|
|
213315
|
+
await this.coanaAPI.sendErrorReportToCoanaDashboard(
|
|
213316
|
+
apiKey,
|
|
213317
|
+
stackTrace,
|
|
213318
|
+
shouldLogSharing,
|
|
213319
|
+
reportId,
|
|
213320
|
+
repoUrl,
|
|
213321
|
+
projectName,
|
|
213322
|
+
logContent
|
|
213323
|
+
);
|
|
213324
|
+
}
|
|
213325
|
+
}
|
|
213326
|
+
async registerSubprojects(subprojects, reportId, apiKey) {
|
|
213327
|
+
if (this.disableAnalyticsSharing) {
|
|
213328
|
+
return;
|
|
213329
|
+
}
|
|
213330
|
+
if (this.socketMode) {
|
|
213331
|
+
await this.socketAPI.registerSubprojectsSocket(subprojects, reportId);
|
|
213332
|
+
} else {
|
|
213333
|
+
await this.coanaAPI.registerSubprojectsCoana(subprojects, reportId, apiKey);
|
|
213334
|
+
}
|
|
213335
|
+
}
|
|
213336
|
+
async registerCLIProgress(cliProgressEvent, isStartEvent, reportId, apiKey) {
|
|
213337
|
+
if (this.disableAnalyticsSharing) {
|
|
213338
|
+
return;
|
|
213339
|
+
}
|
|
213340
|
+
if (this.socketMode) {
|
|
213341
|
+
await this.socketAPI.registerCLIProgressSocket(isStartEvent, cliProgressEvent, reportId);
|
|
213342
|
+
} else {
|
|
213343
|
+
await this.coanaAPI.registerCLIProgressCoana(cliProgressEvent, isStartEvent, reportId, apiKey);
|
|
213344
|
+
}
|
|
213345
|
+
}
|
|
213346
|
+
async registerAnalysisMetadata(subprojectPath, workspacePath, ecosystem, analysisMetadata, reportId, apiKey) {
|
|
213347
|
+
if (this.disableAnalyticsSharing) {
|
|
213348
|
+
return;
|
|
213349
|
+
}
|
|
213350
|
+
if (this.socketMode) {
|
|
213351
|
+
await this.socketAPI.registerAnalysisMetadataSocket(
|
|
213352
|
+
subprojectPath,
|
|
213353
|
+
workspacePath,
|
|
213354
|
+
ecosystem,
|
|
213355
|
+
analysisMetadata,
|
|
213356
|
+
reportId
|
|
213357
|
+
);
|
|
213358
|
+
} else {
|
|
213359
|
+
await this.coanaAPI.registerAnalysisMetadataCoana(
|
|
213360
|
+
subprojectPath,
|
|
213361
|
+
workspacePath,
|
|
213362
|
+
ecosystem,
|
|
213363
|
+
analysisMetadata,
|
|
213364
|
+
reportId,
|
|
213365
|
+
apiKey
|
|
213366
|
+
);
|
|
213367
|
+
}
|
|
213368
|
+
}
|
|
213369
|
+
async getBucketsForLastReport(subprojectPath, workspacePath, ecosystem, reportId, apiKey) {
|
|
213370
|
+
if (this.socketMode) {
|
|
213371
|
+
return await this.socketAPI.getLatestBucketsSocket(subprojectPath, workspacePath);
|
|
213372
|
+
} else {
|
|
213373
|
+
return await this.coanaAPI.getBucketsForLastReport(
|
|
213374
|
+
subprojectPath,
|
|
213375
|
+
workspacePath,
|
|
213376
|
+
ecosystem,
|
|
213377
|
+
reportId,
|
|
213378
|
+
apiKey
|
|
213379
|
+
);
|
|
213380
|
+
}
|
|
212706
213381
|
}
|
|
212707
213382
|
};
|
|
212708
213383
|
|
|
@@ -212845,13 +213520,13 @@ var DEFAULT_REPORT_FILENAME_BASE = "coana-report";
|
|
|
212845
213520
|
// dist/internal/exclude-dirs-from-configuration-files.js
|
|
212846
213521
|
import { existsSync as existsSync20 } from "fs";
|
|
212847
213522
|
import { readFile as readFile27 } from "fs/promises";
|
|
212848
|
-
import { basename as
|
|
213523
|
+
import { basename as basename11, resolve as resolve33 } from "path";
|
|
212849
213524
|
var import_yaml2 = __toESM(require_dist11(), 1);
|
|
212850
213525
|
async function inferExcludeDirsFromConfigurationFiles(rootWorkingDir) {
|
|
212851
|
-
const socketYmlConfigFile =
|
|
213526
|
+
const socketYmlConfigFile = resolve33(rootWorkingDir, "socket.yml");
|
|
212852
213527
|
if (existsSync20(socketYmlConfigFile))
|
|
212853
213528
|
return inferExcludeDirsFromSocketConfig(socketYmlConfigFile);
|
|
212854
|
-
const socketYamlConfigFile =
|
|
213529
|
+
const socketYamlConfigFile = resolve33(rootWorkingDir, "socket.yaml");
|
|
212855
213530
|
if (existsSync20(socketYamlConfigFile))
|
|
212856
213531
|
return inferExcludeDirsFromSocketConfig(socketYamlConfigFile);
|
|
212857
213532
|
return void 0;
|
|
@@ -212865,398 +213540,111 @@ async function inferExcludeDirsFromSocketConfig(socketConfigFile) {
|
|
|
212865
213540
|
return void 0;
|
|
212866
213541
|
if (ignorePaths.some((ignorePath) => ignorePath.includes("!")))
|
|
212867
213542
|
return void 0;
|
|
212868
|
-
logger.info(`Inferring paths to exclude based on Socket config file: ${
|
|
212869
|
-
return config3.projectIgnorePaths;
|
|
212870
|
-
} catch (e) {
|
|
212871
|
-
return void 0;
|
|
212872
|
-
}
|
|
212873
|
-
}
|
|
212874
|
-
|
|
212875
|
-
// dist/internal/socket-mode-helpers-coana-dependency-trees.js
|
|
212876
|
-
var ROOT_IDENTIFIER = "ROOT";
|
|
212877
|
-
async function scanForVulnerabilitiesSocketMode(dependencyTree) {
|
|
212878
|
-
if (!dependencyTree.ecosystem)
|
|
212879
|
-
dependencyTree.ecosystem = "NPM";
|
|
212880
|
-
const purlStringsToIdentifier = getPurlStrings(dependencyTree);
|
|
212881
|
-
const components = await augmentArtifactsWithVulnerabilities(Object.keys(purlStringsToIdentifier).map((purl) => ({ purl })));
|
|
212882
|
-
const parentsMap = /* @__PURE__ */ new Map();
|
|
212883
|
-
for (const [depId, node] of [
|
|
212884
|
-
...Object.entries(dependencyTree.transitiveDependencies),
|
|
212885
|
-
[ROOT_IDENTIFIER, dependencyTree]
|
|
212886
|
-
]) {
|
|
212887
|
-
for (const childId of node.dependencies ?? []) {
|
|
212888
|
-
if (!parentsMap.has(childId)) {
|
|
212889
|
-
parentsMap.set(childId, []);
|
|
212890
|
-
}
|
|
212891
|
-
parentsMap.get(childId).push(depId);
|
|
212892
|
-
}
|
|
212893
|
-
}
|
|
212894
|
-
const vulnerabilities = [];
|
|
212895
|
-
const dependencyIdentifiersNotFound = new Set(Object.keys(dependencyTree.transitiveDependencies));
|
|
212896
|
-
for (const c3 of components) {
|
|
212897
|
-
let simplePurlForComponent = simplePurl(c3.purl_type, c3.namespace, c3.name, c3.version);
|
|
212898
|
-
if (!(simplePurlForComponent in purlStringsToIdentifier))
|
|
212899
|
-
simplePurlForComponent = simplePurl(c3.purl_type, c3.namespace, c3.name, null);
|
|
212900
|
-
const dependencyIdentifiers = purlStringsToIdentifier[simplePurlForComponent];
|
|
212901
|
-
for (const dependencyIdentifier of dependencyIdentifiers) {
|
|
212902
|
-
dependencyIdentifiersNotFound.delete(dependencyIdentifier);
|
|
212903
|
-
const dependencyTreeNode = dependencyTree.transitiveDependencies[dependencyIdentifier];
|
|
212904
|
-
if (!dependencyTreeNode)
|
|
212905
|
-
throw new Error(`Dependency tree does not contain dependency ${simplePurlForComponent}`);
|
|
212906
|
-
dependencyTreeNode.purlObj = {
|
|
212907
|
-
type: c3.purl_type,
|
|
212908
|
-
namespace: c3.namespace ?? void 0,
|
|
212909
|
-
name: c3.name,
|
|
212910
|
-
version: c3.version ?? void 0,
|
|
212911
|
-
subpath: c3.subpath ?? void 0,
|
|
212912
|
-
artifactId: c3.artifactId ?? void 0,
|
|
212913
|
-
artifact_id: c3.artifact_id ?? void 0,
|
|
212914
|
-
qualifiers: c3.qualifiers ?? void 0,
|
|
212915
|
-
purlString: c3.purl
|
|
212916
|
-
};
|
|
212917
|
-
for (const vulnerability of c3.vulnerabilities) {
|
|
212918
|
-
vulnerabilities.push({
|
|
212919
|
-
url: vulnerability.ghsaId,
|
|
212920
|
-
purl: c3.purl,
|
|
212921
|
-
purlType: c3.purl_type,
|
|
212922
|
-
range: vulnerability.range,
|
|
212923
|
-
name: dependencyTreeNode.packageName,
|
|
212924
|
-
dependency: dependencyTreeNode.packageName,
|
|
212925
|
-
vulnChainDetails: computeVulnChainDetails(dependencyTree, dependencyIdentifier, parentsMap),
|
|
212926
|
-
vulnerabilityAccessPaths: vulnerability.reachabilityData?.pattern ?? null,
|
|
212927
|
-
ecosystem: dependencyTree.ecosystem
|
|
212928
|
-
});
|
|
212929
|
-
}
|
|
212930
|
-
}
|
|
212931
|
-
}
|
|
212932
|
-
for (const dependencyIdentifier of dependencyIdentifiersNotFound) {
|
|
212933
|
-
logger.warn(`Dependency ${dependencyIdentifier} not found in Socket mode`, dependencyTree.transitiveDependencies[dependencyIdentifier]);
|
|
212934
|
-
}
|
|
212935
|
-
return vulnerabilities;
|
|
212936
|
-
}
|
|
212937
|
-
function computeVulnChainDetails(dependencyTree, dependencyIdentifier, parentsMap) {
|
|
212938
|
-
const res = {
|
|
212939
|
-
packageName: "root",
|
|
212940
|
-
version: "0.0.0",
|
|
212941
|
-
children: [],
|
|
212942
|
-
transitiveDependencies: {}
|
|
212943
|
-
};
|
|
212944
|
-
function addNode(currentIdentifier, childIdentifier, visited) {
|
|
212945
|
-
if (visited.has(currentIdentifier))
|
|
212946
|
-
return;
|
|
212947
|
-
const parents4 = parentsMap.get(currentIdentifier);
|
|
212948
|
-
const newCurrentNode = transformToVulnChainNode(dependencyTree.transitiveDependencies[currentIdentifier]);
|
|
212949
|
-
res.transitiveDependencies[currentIdentifier] = newCurrentNode;
|
|
212950
|
-
if (childIdentifier && !newCurrentNode.children.includes(childIdentifier))
|
|
212951
|
-
newCurrentNode.children.push(childIdentifier);
|
|
212952
|
-
if (!childIdentifier)
|
|
212953
|
-
newCurrentNode.vulnerable = true;
|
|
212954
|
-
if (!parents4)
|
|
212955
|
-
return res;
|
|
212956
|
-
visited.add(currentIdentifier);
|
|
212957
|
-
for (const parent2 of parents4) {
|
|
212958
|
-
if (parent2 === ROOT_IDENTIFIER)
|
|
212959
|
-
res.children.push(currentIdentifier);
|
|
212960
|
-
else
|
|
212961
|
-
addNode(parent2, currentIdentifier, visited);
|
|
212962
|
-
}
|
|
212963
|
-
}
|
|
212964
|
-
addNode(dependencyIdentifier, void 0, /* @__PURE__ */ new Set());
|
|
212965
|
-
return res;
|
|
212966
|
-
}
|
|
212967
|
-
function transformToVulnChainNode(dependencyTree) {
|
|
212968
|
-
return {
|
|
212969
|
-
...a3(dependencyTree, ["packageName", "version"]),
|
|
212970
|
-
children: []
|
|
212971
|
-
};
|
|
212972
|
-
}
|
|
212973
|
-
|
|
212974
|
-
// dist/internal/socket-mode-helpers-socket-dependency-trees.js
|
|
212975
|
-
var import_packageurl_js2 = __toESM(require_packageurl_js(), 1);
|
|
212976
|
-
var import_picomatch4 = __toESM(require_picomatch2(), 1);
|
|
212977
|
-
import { basename as basename11, dirname as dirname13, join as join24, sep as sep5 } from "path";
|
|
212978
|
-
var REQUIREMENTS_FILES_SEARCH_DEPTH2 = 3;
|
|
212979
|
-
function inferWorkspaceFromManifestPath(ecosystem, manifestPath, properPythonProjects) {
|
|
212980
|
-
switch (ecosystem) {
|
|
212981
|
-
case "NPM": {
|
|
212982
|
-
const base = basename11(manifestPath);
|
|
212983
|
-
const dir = dirname13(manifestPath);
|
|
212984
|
-
return base === "package.json" ? dir || "." : void 0;
|
|
212985
|
-
}
|
|
212986
|
-
case "MAVEN": {
|
|
212987
|
-
return ".";
|
|
212988
|
-
}
|
|
212989
|
-
case "PIP": {
|
|
212990
|
-
const base = basename11(manifestPath);
|
|
212991
|
-
const dir = dirname13(manifestPath);
|
|
212992
|
-
const workspaceDir = dir === "" ? "." : dir;
|
|
212993
|
-
if (properPythonProjects.includes(workspaceDir)) {
|
|
212994
|
-
return workspaceDir;
|
|
212995
|
-
}
|
|
212996
|
-
if (base === "poetry.lock" || base === "Pipfile.lock" || base === "uv.lock") {
|
|
212997
|
-
return workspaceDir;
|
|
212998
|
-
}
|
|
212999
|
-
if (base.endsWith(".txt")) {
|
|
213000
|
-
const properProjectDirs = properPythonProjects.filter((properProjectDir) => (properProjectDir === "." || workspaceDir === "." || workspaceDir.startsWith(properProjectDir)) && workspaceDir.replace(properProjectDir, "").split(sep5).length <= REQUIREMENTS_FILES_SEARCH_DEPTH2);
|
|
213001
|
-
const longestProperProjectDir = l5(properProjectDirs, [(d4) => d4.length, "desc"]);
|
|
213002
|
-
if (longestProperProjectDir) {
|
|
213003
|
-
return longestProperProjectDir;
|
|
213004
|
-
}
|
|
213005
|
-
return workspaceDir;
|
|
213006
|
-
}
|
|
213007
|
-
logger.warn(`No workspace found for manifest file ${manifestPath}`);
|
|
213008
|
-
return void 0;
|
|
213009
|
-
}
|
|
213010
|
-
case "NUGET": {
|
|
213011
|
-
return ".";
|
|
213012
|
-
}
|
|
213013
|
-
case "RUST": {
|
|
213014
|
-
return dirname13(manifestPath) || ".";
|
|
213015
|
-
}
|
|
213016
|
-
case "GO": {
|
|
213017
|
-
const base = basename11(manifestPath);
|
|
213018
|
-
const dir = dirname13(manifestPath);
|
|
213019
|
-
return base === "go.mod" ? dir || "." : void 0;
|
|
213020
|
-
}
|
|
213021
|
-
default: {
|
|
213022
|
-
return ".";
|
|
213023
|
-
}
|
|
213024
|
-
}
|
|
213025
|
-
}
|
|
213026
|
-
function inferProjectFromManifestPath(ecosystem, manifestPath) {
|
|
213027
|
-
switch (ecosystem) {
|
|
213028
|
-
case "NPM": {
|
|
213029
|
-
const filename = basename11(manifestPath);
|
|
213030
|
-
if (["package-lock.json", "pnpm-lock.yaml", "pnpm-lock.yml", "yarn.lock"].includes(filename)) {
|
|
213031
|
-
return dirname13(manifestPath) || ".";
|
|
213032
|
-
}
|
|
213033
|
-
return void 0;
|
|
213034
|
-
}
|
|
213543
|
+
logger.info(`Inferring paths to exclude based on Socket config file: ${basename11(socketConfigFile)}`);
|
|
213544
|
+
return config3.projectIgnorePaths;
|
|
213545
|
+
} catch (e) {
|
|
213546
|
+
return void 0;
|
|
213035
213547
|
}
|
|
213036
213548
|
}
|
|
213037
|
-
|
|
213038
|
-
|
|
213039
|
-
|
|
213040
|
-
|
|
213041
|
-
|
|
213042
|
-
|
|
213043
|
-
|
|
213044
|
-
|
|
213045
|
-
|
|
213046
|
-
|
|
213047
|
-
|
|
213048
|
-
|
|
213049
|
-
|
|
213050
|
-
|
|
213051
|
-
|
|
213052
|
-
|
|
213549
|
+
|
|
213550
|
+
// dist/internal/socket-mode-helpers-coana-dependency-trees.js
|
|
213551
|
+
var ROOT_IDENTIFIER = "ROOT";
|
|
213552
|
+
async function scanForVulnerabilitiesSocketMode(dependencyTree) {
|
|
213553
|
+
if (!dependencyTree.ecosystem)
|
|
213554
|
+
dependencyTree.ecosystem = "NPM";
|
|
213555
|
+
const purlStringsToIdentifier = getPurlStrings(dependencyTree);
|
|
213556
|
+
const components = await augmentArtifactsWithVulnerabilities(Object.keys(purlStringsToIdentifier).map((purl) => ({ purl })));
|
|
213557
|
+
const parentsMap = /* @__PURE__ */ new Map();
|
|
213558
|
+
for (const [depId, node] of [
|
|
213559
|
+
...Object.entries(dependencyTree.transitiveDependencies),
|
|
213560
|
+
[ROOT_IDENTIFIER, dependencyTree]
|
|
213561
|
+
]) {
|
|
213562
|
+
for (const childId of node.dependencies ?? []) {
|
|
213563
|
+
if (!parentsMap.has(childId)) {
|
|
213564
|
+
parentsMap.set(childId, []);
|
|
213053
213565
|
}
|
|
213566
|
+
parentsMap.get(childId).push(depId);
|
|
213054
213567
|
}
|
|
213055
213568
|
}
|
|
213056
|
-
|
|
213057
|
-
|
|
213058
|
-
|
|
213059
|
-
|
|
213060
|
-
|
|
213061
|
-
|
|
213062
|
-
const
|
|
213063
|
-
const
|
|
213064
|
-
|
|
213065
|
-
|
|
213066
|
-
if (
|
|
213067
|
-
|
|
213068
|
-
|
|
213069
|
-
|
|
213070
|
-
|
|
213071
|
-
|
|
213072
|
-
|
|
213073
|
-
|
|
213074
|
-
|
|
213075
|
-
|
|
213076
|
-
|
|
213077
|
-
|
|
213078
|
-
".venvs",
|
|
213079
|
-
"envs",
|
|
213080
|
-
".envs",
|
|
213081
|
-
"__pycache__",
|
|
213082
|
-
".tox",
|
|
213083
|
-
".nox",
|
|
213084
|
-
".pytest_cache",
|
|
213085
|
-
"site-packages",
|
|
213086
|
-
"dist-packages",
|
|
213087
|
-
"conda-meta",
|
|
213088
|
-
"conda-bld",
|
|
213089
|
-
".mypy_cache",
|
|
213090
|
-
".ruff_cache",
|
|
213091
|
-
".hypothesis"
|
|
213092
|
-
];
|
|
213093
|
-
const allFiles = await getFilesRelative(rootWorkingDirectory, venvExcludes);
|
|
213094
|
-
for (const file of allFiles) {
|
|
213095
|
-
const base = basename11(file);
|
|
213096
|
-
const workspaceDir = dirname13(file) || ".";
|
|
213097
|
-
if (base === "pyproject.toml" || base === "setup.py" && await isSetupPySetuptools(join24(rootWorkingDirectory, file))) {
|
|
213098
|
-
if (!properPythonProjects.includes(workspaceDir)) {
|
|
213099
|
-
properPythonProjects.push(workspaceDir);
|
|
213100
|
-
}
|
|
213101
|
-
}
|
|
213102
|
-
}
|
|
213103
|
-
const artifactMap = new Map(artifacts.map((a4) => [a4.id, a4]));
|
|
213104
|
-
const ecosystemToWorkspaceToAnalysisData = {};
|
|
213105
|
-
const ecosystemWorkspaceVulnIds = /* @__PURE__ */ new Set();
|
|
213106
|
-
const ecosystemToWorkspaceToVulnerabilities = {};
|
|
213107
|
-
const purlsFailedToFindWorkspace = /* @__PURE__ */ new Set();
|
|
213108
|
-
for (const artifact of artifacts) {
|
|
213109
|
-
let processToplevelAncestors2 = function(artifact2) {
|
|
213110
|
-
const allAncestorIds = getAllToplevelAncestors(artifactMap, artifact2.id);
|
|
213111
|
-
allAncestorIds.forEach((ancestorId) => artifactMap.get(ancestorId)?.manifestFiles?.forEach((ref) => manifestFiles.push(ref.file)));
|
|
213569
|
+
const vulnerabilities = [];
|
|
213570
|
+
const dependencyIdentifiersNotFound = new Set(Object.keys(dependencyTree.transitiveDependencies));
|
|
213571
|
+
for (const c3 of components) {
|
|
213572
|
+
let simplePurlForComponent = simplePurl(c3.purl_type, c3.namespace, c3.name, c3.version);
|
|
213573
|
+
if (!(simplePurlForComponent in purlStringsToIdentifier))
|
|
213574
|
+
simplePurlForComponent = simplePurl(c3.purl_type, c3.namespace, c3.name, null);
|
|
213575
|
+
const dependencyIdentifiers = purlStringsToIdentifier[simplePurlForComponent];
|
|
213576
|
+
for (const dependencyIdentifier of dependencyIdentifiers) {
|
|
213577
|
+
dependencyIdentifiersNotFound.delete(dependencyIdentifier);
|
|
213578
|
+
const dependencyTreeNode = dependencyTree.transitiveDependencies[dependencyIdentifier];
|
|
213579
|
+
if (!dependencyTreeNode)
|
|
213580
|
+
throw new Error(`Dependency tree does not contain dependency ${simplePurlForComponent}`);
|
|
213581
|
+
dependencyTreeNode.purlObj = {
|
|
213582
|
+
type: c3.purl_type,
|
|
213583
|
+
namespace: c3.namespace ?? void 0,
|
|
213584
|
+
name: c3.name,
|
|
213585
|
+
version: c3.version ?? void 0,
|
|
213586
|
+
subpath: c3.subpath ?? void 0,
|
|
213587
|
+
artifactId: c3.artifactId ?? void 0,
|
|
213588
|
+
artifact_id: c3.artifact_id ?? void 0,
|
|
213589
|
+
qualifiers: c3.qualifiers ?? void 0,
|
|
213590
|
+
purlString: c3.purl
|
|
213112
213591
|
};
|
|
213113
|
-
|
|
213114
|
-
|
|
213115
|
-
|
|
213116
|
-
|
|
213117
|
-
|
|
213118
|
-
|
|
213119
|
-
|
|
213120
|
-
|
|
213121
|
-
|
|
213122
|
-
|
|
213123
|
-
|
|
213124
|
-
manifestFiles.push(...(await getFilesRelative(rootWorkingDirectory)).filter((file) => (0, import_picomatch4.default)("{*.csproj,packages.lock.json}")(basename11(file))));
|
|
213125
|
-
break;
|
|
213126
|
-
}
|
|
213127
|
-
case "PIP": {
|
|
213128
|
-
const sPurl = simplePurl(artifact.type, artifact.namespace ?? "", artifact.name, artifact.version ?? "");
|
|
213129
|
-
if (pipArtifactToRepresentativeManifest[sPurl]) {
|
|
213130
|
-
manifestFiles.push(...(pipArtifactToRepresentativeManifest[sPurl].manifestFiles ?? []).map((ref) => ref.file));
|
|
213131
|
-
}
|
|
213132
|
-
processToplevelAncestors2(artifact);
|
|
213133
|
-
break;
|
|
213134
|
-
}
|
|
213135
|
-
default: {
|
|
213136
|
-
artifact.manifestFiles?.forEach((ref) => manifestFiles.push(ref.file));
|
|
213137
|
-
processToplevelAncestors2(artifact);
|
|
213138
|
-
break;
|
|
213139
|
-
}
|
|
213140
|
-
}
|
|
213141
|
-
const workspaceToManifestFiles = {};
|
|
213142
|
-
manifestFiles.forEach((manifestFile) => {
|
|
213143
|
-
const workspace = inferWorkspaceFromManifestPath(ecosystem, manifestFile, properPythonProjects);
|
|
213144
|
-
if (!workspace)
|
|
213145
|
-
return;
|
|
213146
|
-
(workspaceToManifestFiles[workspace] ??= []).push(manifestFile);
|
|
213147
|
-
});
|
|
213148
|
-
if (Object.keys(workspaceToManifestFiles).length === 0) {
|
|
213149
|
-
manifestFiles.forEach((manifestFile) => {
|
|
213150
|
-
const workspace = inferProjectFromManifestPath(ecosystem, manifestFile);
|
|
213151
|
-
if (!workspace)
|
|
213152
|
-
return;
|
|
213153
|
-
(workspaceToManifestFiles[workspace] ??= []).push(manifestFile);
|
|
213592
|
+
for (const vulnerability of c3.vulnerabilities) {
|
|
213593
|
+
vulnerabilities.push({
|
|
213594
|
+
url: vulnerability.ghsaId,
|
|
213595
|
+
purl: c3.purl,
|
|
213596
|
+
purlType: c3.purl_type,
|
|
213597
|
+
range: vulnerability.range,
|
|
213598
|
+
name: dependencyTreeNode.packageName,
|
|
213599
|
+
dependency: dependencyTreeNode.packageName,
|
|
213600
|
+
vulnChainDetails: computeVulnChainDetails2(dependencyTree, dependencyIdentifier, parentsMap),
|
|
213601
|
+
vulnerabilityAccessPaths: vulnerability.reachabilityData?.pattern ?? null,
|
|
213602
|
+
ecosystem: dependencyTree.ecosystem
|
|
213154
213603
|
});
|
|
213155
213604
|
}
|
|
213156
|
-
if (Object.keys(workspaceToManifestFiles).length === 0 && artifact.vulnerabilities && artifact.vulnerabilities.length > 0) {
|
|
213157
|
-
const purl = new import_packageurl_js2.PackageURL(artifact.type, artifact.namespace, artifact.name, artifact.version, artifact.qualifiers).toString();
|
|
213158
|
-
purlsFailedToFindWorkspace.add(purl);
|
|
213159
|
-
}
|
|
213160
|
-
for (const [workspace, manifestFiles2] of Object.entries(workspaceToManifestFiles)) {
|
|
213161
|
-
const workspaceData = (ecosystemToWorkspaceToAnalysisData[ecosystem] ??= {})[workspace] ??= {
|
|
213162
|
-
type: "socket",
|
|
213163
|
-
data: {
|
|
213164
|
-
type: ecosystem,
|
|
213165
|
-
manifestFiles: manifestFiles2,
|
|
213166
|
-
artifacts: []
|
|
213167
|
-
}
|
|
213168
|
-
};
|
|
213169
|
-
workspaceData.type;
|
|
213170
|
-
workspaceData.data.artifacts.push(artifact);
|
|
213171
|
-
}
|
|
213172
|
-
if (artifact.vulnerabilities && artifact.vulnerabilities.length > 0) {
|
|
213173
|
-
for (const workspace of Object.keys(workspaceToManifestFiles)) {
|
|
213174
|
-
for (const vuln of artifact.vulnerabilities) {
|
|
213175
|
-
const vulnerability = {
|
|
213176
|
-
url: vuln.ghsaId,
|
|
213177
|
-
purlType: artifact.type,
|
|
213178
|
-
range: vuln.range,
|
|
213179
|
-
name: artifact.name ?? "",
|
|
213180
|
-
dependency: artifact.name ?? "",
|
|
213181
|
-
vulnChainDetails: computeVulnChainDetails2(artifacts, artifact.id),
|
|
213182
|
-
vulnerabilityAccessPaths: vuln.reachabilityData?.undeterminableReachability ? vuln.reachabilityData.publicComment ?? "" : vuln.reachabilityData?.pattern ?? null,
|
|
213183
|
-
ecosystem,
|
|
213184
|
-
artifactId: artifact.id
|
|
213185
|
-
};
|
|
213186
|
-
const vulnId = `${ecosystem}-${workspace}-${vulnerability.url}`;
|
|
213187
|
-
if (!ecosystemWorkspaceVulnIds.has(vulnId)) {
|
|
213188
|
-
ecosystemWorkspaceVulnIds.add(vulnId);
|
|
213189
|
-
((ecosystemToWorkspaceToVulnerabilities[ecosystem] ??= {})[workspace] ??= []).push(vulnerability);
|
|
213190
|
-
}
|
|
213191
|
-
}
|
|
213192
|
-
}
|
|
213193
|
-
}
|
|
213194
213605
|
}
|
|
213195
|
-
if (purlsFailedToFindWorkspace.size > 0) {
|
|
213196
|
-
logger.warn(`Failed to find workspace for the following purls with vulnerabilities: ${Array.from(purlsFailedToFindWorkspace).join(", ")}.
|
|
213197
|
-
${mode === "reachability" ? "This means that we will not do a full reachability analysis for these vulnerabilities, but fallback to the results from the pre-computed reachability analysis." : ""}`);
|
|
213198
|
-
}
|
|
213199
|
-
return {
|
|
213200
|
-
artifacts,
|
|
213201
|
-
ecosystemToWorkspaceToAnalysisData,
|
|
213202
|
-
ecosystemToWorkspaceToVulnerabilities
|
|
213203
|
-
};
|
|
213204
|
-
} catch (error) {
|
|
213205
|
-
logger.error("Failed to fetch artifacts from Socket backend", error);
|
|
213206
|
-
throw error;
|
|
213207
213606
|
}
|
|
213208
|
-
|
|
213209
|
-
|
|
213210
|
-
const artifactMap = new Map(artifacts.map((a4) => [a4.id, a4]));
|
|
213211
|
-
const parentsMap = /* @__PURE__ */ new Map();
|
|
213212
|
-
for (const artifact of artifacts) {
|
|
213213
|
-
if (artifact.dependencies) {
|
|
213214
|
-
for (const depId of artifact.dependencies) {
|
|
213215
|
-
if (!parentsMap.has(depId)) {
|
|
213216
|
-
parentsMap.set(depId, []);
|
|
213217
|
-
}
|
|
213218
|
-
parentsMap.get(depId).push(artifact.id);
|
|
213219
|
-
}
|
|
213220
|
-
}
|
|
213607
|
+
for (const dependencyIdentifier of dependencyIdentifiersNotFound) {
|
|
213608
|
+
logger.warn(`Dependency ${dependencyIdentifier} not found in Socket mode`, dependencyTree.transitiveDependencies[dependencyIdentifier]);
|
|
213221
213609
|
}
|
|
213610
|
+
return vulnerabilities;
|
|
213611
|
+
}
|
|
213612
|
+
function computeVulnChainDetails2(dependencyTree, dependencyIdentifier, parentsMap) {
|
|
213222
213613
|
const res = {
|
|
213223
213614
|
packageName: "root",
|
|
213224
213615
|
version: "0.0.0",
|
|
213225
213616
|
children: [],
|
|
213226
213617
|
transitiveDependencies: {}
|
|
213227
213618
|
};
|
|
213228
|
-
function addNode(
|
|
213229
|
-
if (visited.has(
|
|
213230
|
-
return;
|
|
213231
|
-
const currentArtifact = artifactMap.get(currentId);
|
|
213232
|
-
if (!currentArtifact)
|
|
213619
|
+
function addNode(currentIdentifier, childIdentifier, visited) {
|
|
213620
|
+
if (visited.has(currentIdentifier))
|
|
213233
213621
|
return;
|
|
213234
|
-
const parents4 = parentsMap.get(
|
|
213235
|
-
const newCurrentNode =
|
|
213236
|
-
|
|
213237
|
-
|
|
213238
|
-
children
|
|
213239
|
-
|
|
213240
|
-
|
|
213241
|
-
if (
|
|
213242
|
-
|
|
213243
|
-
|
|
213244
|
-
|
|
213245
|
-
|
|
213246
|
-
|
|
213247
|
-
|
|
213248
|
-
|
|
213249
|
-
}
|
|
213250
|
-
visited.add(currentId);
|
|
213251
|
-
if (parents4) {
|
|
213252
|
-
for (const parentId of parents4) {
|
|
213253
|
-
addNode(parentId, currentId, visited);
|
|
213254
|
-
}
|
|
213622
|
+
const parents4 = parentsMap.get(currentIdentifier);
|
|
213623
|
+
const newCurrentNode = transformToVulnChainNode(dependencyTree.transitiveDependencies[currentIdentifier]);
|
|
213624
|
+
res.transitiveDependencies[currentIdentifier] = newCurrentNode;
|
|
213625
|
+
if (childIdentifier && !newCurrentNode.children.includes(childIdentifier))
|
|
213626
|
+
newCurrentNode.children.push(childIdentifier);
|
|
213627
|
+
if (!childIdentifier)
|
|
213628
|
+
newCurrentNode.vulnerable = true;
|
|
213629
|
+
if (!parents4)
|
|
213630
|
+
return res;
|
|
213631
|
+
visited.add(currentIdentifier);
|
|
213632
|
+
for (const parent2 of parents4) {
|
|
213633
|
+
if (parent2 === ROOT_IDENTIFIER)
|
|
213634
|
+
res.children.push(currentIdentifier);
|
|
213635
|
+
else
|
|
213636
|
+
addNode(parent2, currentIdentifier, visited);
|
|
213255
213637
|
}
|
|
213256
213638
|
}
|
|
213257
|
-
addNode(
|
|
213639
|
+
addNode(dependencyIdentifier, void 0, /* @__PURE__ */ new Set());
|
|
213258
213640
|
return res;
|
|
213259
213641
|
}
|
|
213642
|
+
function transformToVulnChainNode(dependencyTree) {
|
|
213643
|
+
return {
|
|
213644
|
+
...a3(dependencyTree, ["packageName", "version"]),
|
|
213645
|
+
children: []
|
|
213646
|
+
};
|
|
213647
|
+
}
|
|
213260
213648
|
|
|
213261
213649
|
// dist/internal/socket-report-coana-dependency-tree.js
|
|
213262
213650
|
var MAX_STACKS_TO_SEND = 10;
|
|
@@ -226948,7 +227336,7 @@ var { root: root2 } = static_exports;
|
|
|
226948
227336
|
// ../utils/src/maven-utils.ts
|
|
226949
227337
|
var import_lodash14 = __toESM(require_lodash(), 1);
|
|
226950
227338
|
import { existsSync as existsSync21, readdirSync as readdirSync4, statSync as statSync3 } from "fs";
|
|
226951
|
-
import { join as
|
|
227339
|
+
import { join as join26 } from "path";
|
|
226952
227340
|
var { memoize: memoize3 } = import_lodash14.default;
|
|
226953
227341
|
var memoizedParseShellArgs = memoize3(parseShellArgs);
|
|
226954
227342
|
var MAVEN_PUBLIC_REPOSITORIES = [
|
|
@@ -227631,12 +228019,6 @@ var InMemoryVulnerabilityMetadataStore = class {
|
|
|
227631
228019
|
}
|
|
227632
228020
|
};
|
|
227633
228021
|
|
|
227634
|
-
// ../web-compat-utils/src/assertions.ts
|
|
227635
|
-
function assertDefined(value) {
|
|
227636
|
-
if (value === void 0 || value === null) throw new Error("Expected value to be defined");
|
|
227637
|
-
return value;
|
|
227638
|
-
}
|
|
227639
|
-
|
|
227640
228022
|
// ../security-auditor/security-auditor-api/src/fixes-task.ts
|
|
227641
228023
|
var MESSAGE_PREFIX_FOR_FAILED_TO_PICK_VERSION = `Failed to pick a version`;
|
|
227642
228024
|
var MESSAGE_PREFIX_FOR_NO_POTENTIAL_VERSIONS = `No potential versions`;
|
|
@@ -228319,7 +228701,7 @@ async function onlineScan(dependencyTree, apiKey, timeout) {
|
|
|
228319
228701
|
}
|
|
228320
228702
|
|
|
228321
228703
|
// dist/version.js
|
|
228322
|
-
var version2 = "14.12.
|
|
228704
|
+
var version2 = "14.12.43";
|
|
228323
228705
|
|
|
228324
228706
|
// dist/cli-core.js
|
|
228325
228707
|
var { mapValues, omit, partition, pick } = import_lodash15.default;
|
|
@@ -228349,7 +228731,7 @@ var CliCore = class {
|
|
|
228349
228731
|
throw new Error("Invalid analysis timeout value");
|
|
228350
228732
|
}
|
|
228351
228733
|
}
|
|
228352
|
-
this.rootWorkingDirectory =
|
|
228734
|
+
this.rootWorkingDirectory = resolve34(rootWorkingDirectory);
|
|
228353
228735
|
this.spinner = Spinner.instance({
|
|
228354
228736
|
text: "Running Coana CLI",
|
|
228355
228737
|
isSilent: this.options.silentSpinner ?? this.options.silent
|
|
@@ -228424,7 +228806,7 @@ var CliCore = class {
|
|
|
228424
228806
|
}
|
|
228425
228807
|
}
|
|
228426
228808
|
async main() {
|
|
228427
|
-
this.coanaLogPath =
|
|
228809
|
+
this.coanaLogPath = join27(await createTmpDirectory("coana-cli-"), "coana-log.txt");
|
|
228428
228810
|
logger.initWinstonLogger(this.options.debug, this.coanaLogPath);
|
|
228429
228811
|
logger.silent = this.options.silent;
|
|
228430
228812
|
try {
|
|
@@ -228522,7 +228904,7 @@ var CliCore = class {
|
|
|
228522
228904
|
this.sendProgress("RUN_ON_SUBPROJECT", false, this.rootWorkingDirectory);
|
|
228523
228905
|
}
|
|
228524
228906
|
const socketReport = toSocketFactsSocketDependencyTree(artifacts, vulnsWithResults, this.reportId);
|
|
228525
|
-
const outputFile =
|
|
228907
|
+
const outputFile = resolve34(this.options.socketMode);
|
|
228526
228908
|
await writeFile10(outputFile, JSON.stringify(socketReport, null, 2));
|
|
228527
228909
|
logger.info(kleur_default.green(`Socket report written to: ${outputFile}`));
|
|
228528
228910
|
}
|
|
@@ -228540,13 +228922,13 @@ var CliCore = class {
|
|
|
228540
228922
|
throw new Error("Dependency trees should be available when using --socket-mode");
|
|
228541
228923
|
}
|
|
228542
228924
|
const socketReport = toSocketFacts(report, this.reportDependencyTrees, subPjToWsPathToDirectDependencies);
|
|
228543
|
-
const outputFile =
|
|
228925
|
+
const outputFile = resolve34(this.options.socketMode);
|
|
228544
228926
|
await writeFile10(outputFile, JSON.stringify(socketReport, null, 2));
|
|
228545
228927
|
logger.info(kleur_default.green(`Socket report written to: ${outputFile}`));
|
|
228546
228928
|
return;
|
|
228547
228929
|
}
|
|
228548
228930
|
if (outputDir) {
|
|
228549
|
-
const jsonReportPath =
|
|
228931
|
+
const jsonReportPath = resolve34(outputDir, `${DEFAULT_REPORT_FILENAME_BASE}.json`);
|
|
228550
228932
|
await mkdir2(outputDir, { recursive: true });
|
|
228551
228933
|
writeFileSync3(jsonReportPath, JSON.stringify(report, null, 2));
|
|
228552
228934
|
logger.info(kleur_default.green(`JSON report written to: ${jsonReportPath}`));
|
|
@@ -228584,7 +228966,7 @@ var CliCore = class {
|
|
|
228584
228966
|
const { reachabilitySupport, traditionalScaSupport, noSupport } = manager.getSubprojectsWithWorkspacePaths();
|
|
228585
228967
|
await this.dashboardAPI.registerSubprojects([...reachabilitySupport, ...traditionalScaSupport, ...noSupport].map((sp) => ({
|
|
228586
228968
|
...sp,
|
|
228587
|
-
subprojectPath:
|
|
228969
|
+
subprojectPath: relative15(this.rootWorkingDirectory, sp.subprojectPath) || "."
|
|
228588
228970
|
})), this.reportId, this.apiKey);
|
|
228589
228971
|
for (const unsupported of noSupport)
|
|
228590
228972
|
logger.warn(unsupported.unsupportedMsg);
|
|
@@ -228613,7 +228995,7 @@ var CliCore = class {
|
|
|
228613
228995
|
await this.spinner.succeed();
|
|
228614
228996
|
} catch (error) {
|
|
228615
228997
|
if (this.options.ignoreFailingWorkspaces) {
|
|
228616
|
-
const relativeSubprojectPath =
|
|
228998
|
+
const relativeSubprojectPath = relative15(this.rootWorkingDirectory, subprojectAndWsPath.subprojectPath) || ".";
|
|
228617
228999
|
this.failedSubprojects.push({
|
|
228618
229000
|
subproject: relativeSubprojectPath,
|
|
228619
229001
|
error: error.message || "Unknown error"
|
|
@@ -228672,7 +229054,7 @@ Subproject: ${subproject}`);
|
|
|
228672
229054
|
}
|
|
228673
229055
|
async updateSpinnerTextOnNewSubproject(subprojectAndWsPath, numberSubprojects, index2) {
|
|
228674
229056
|
this.spinner.start();
|
|
228675
|
-
const relativeSubprojectPath =
|
|
229057
|
+
const relativeSubprojectPath = relative15(this.rootWorkingDirectory, subprojectAndWsPath.subprojectPath) || ".";
|
|
228676
229058
|
await this.spinner.setText(numberSubprojects > 1 ? `Processing subproject ${relativeSubprojectPath} (${index2 + 1}/${numberSubprojects})${+this.options.concurrency > 1 ? `. May process up to ${+this.options.concurrency - 1} other workspaces in parallel` : ""}` : `Processing ${relativeSubprojectPath}`);
|
|
228677
229059
|
}
|
|
228678
229060
|
async initialize() {
|
|
@@ -228750,7 +229132,7 @@ Subproject: ${subproject}`);
|
|
|
228750
229132
|
return workspaceToAugmentedVulnerabilities[workspacePath] !== void 0;
|
|
228751
229133
|
}).map((workspacePath) => {
|
|
228752
229134
|
return {
|
|
228753
|
-
subprojectPath:
|
|
229135
|
+
subprojectPath: relative15(this.rootWorkingDirectory, subprojectPath) || ".",
|
|
228754
229136
|
workspacePath,
|
|
228755
229137
|
directDependencies: projectInfo[workspacePath].dataForAnalysis.directDependenciesMap ?? {},
|
|
228756
229138
|
vulnerabilities: workspaceToAugmentedVulnerabilities[workspacePath],
|
|
@@ -228849,7 +229231,7 @@ Subproject: ${subproject}`);
|
|
|
228849
229231
|
excludeDirs: this.options.excludeDirs ?? [],
|
|
228850
229232
|
changedFiles: this.options.changedFiles,
|
|
228851
229233
|
includeDirs: this.options.includeDirs ?? []
|
|
228852
|
-
},
|
|
229234
|
+
}, resolve34(subprojectPath, workspacePath));
|
|
228853
229235
|
if (shouldExcludeWorkspaceForAnalysis) {
|
|
228854
229236
|
logger.info(`Skipping reachability analysis for workspace ${workspacePath} due to it being excluded.`);
|
|
228855
229237
|
}
|
|
@@ -228880,7 +229262,7 @@ Subproject: ${subproject}`);
|
|
|
228880
229262
|
async sendProgress(type, isStartEvent, subprojectPath, workspacePath) {
|
|
228881
229263
|
await this.dashboardAPI.registerCLIProgress({
|
|
228882
229264
|
type,
|
|
228883
|
-
...subprojectPath ? { subprojectPath:
|
|
229265
|
+
...subprojectPath ? { subprojectPath: relative15(this.rootWorkingDirectory, subprojectPath) || "." } : {},
|
|
228884
229266
|
...workspacePath ? { workspacePath } : {}
|
|
228885
229267
|
}, isStartEvent, this.reportId, this.apiKey);
|
|
228886
229268
|
}
|
|
@@ -228919,471 +229301,108 @@ Subproject: ${subproject}`);
|
|
|
228919
229301
|
artifactId: v.artifactId
|
|
228920
229302
|
};
|
|
228921
229303
|
});
|
|
228922
|
-
}
|
|
228923
|
-
async getDependencyTreeAndVulnerabilities(otherModulesCommunicator, subProjAndWsPath) {
|
|
228924
|
-
const { packageManagerName, subprojectPath, workspacePaths } = subProjAndWsPath;
|
|
228925
|
-
this.sendProgress("RUN_ON_SUBPROJECT", true, subprojectPath);
|
|
228926
|
-
const rootWorkingDirectory = this.rootWorkingDirectory;
|
|
228927
|
-
this.sendProgress("PREPARE_PROJECT_AND_GET_PROJECT_DATA", true, subprojectPath);
|
|
228928
|
-
const projectInfo = await otherModulesCommunicator.prepareProjectAndGetProjectData(packageManagerName, subprojectPath, workspacePaths, this.options.lightweightReachability, this.options.providerProject ? await this.runOnProvider(this.options.providerProject) : void 0);
|
|
228929
|
-
this.sendProgress("PREPARE_PROJECT_AND_GET_PROJECT_DATA", false, subprojectPath);
|
|
228930
|
-
const workspaceToPlainDependencyTree = Object.fromEntries(workspacePaths.map((workspacePath) => [
|
|
228931
|
-
workspacePath,
|
|
228932
|
-
toPlainDependencyTree(projectInfo[workspacePath].dataForAnalysis.data.dependencyTree)
|
|
228933
|
-
]));
|
|
228934
|
-
const dependencyTrees = workspacePaths.map((workspacePath) => ({
|
|
228935
|
-
treeType: "v1",
|
|
228936
|
-
dependencyTree: workspaceToPlainDependencyTree[workspacePath],
|
|
228937
|
-
ecosystem: workspaceToPlainDependencyTree[workspacePath].ecosystem ?? "NPM",
|
|
228938
|
-
workspacePath,
|
|
228939
|
-
subprojectPath:
|
|
228940
|
-
}));
|
|
228941
|
-
if (this.options.socketMode) {
|
|
228942
|
-
this.reportDependencyTrees = workspacePaths.map((workspacePath) => ({
|
|
228943
|
-
treeType: "v1",
|
|
228944
|
-
dependencyTree: projectInfo[workspacePath].dataForAnalysis.data.dependencyTree,
|
|
228945
|
-
ecosystem: projectInfo[workspacePath].dataForAnalysis.data.dependencyTree.ecosystem ?? "NPM",
|
|
228946
|
-
workspacePath,
|
|
228947
|
-
subprojectPath:
|
|
228948
|
-
}));
|
|
228949
|
-
}
|
|
228950
|
-
if (this.shareWithDashboard)
|
|
228951
|
-
sendDependencyTreesToDashboard(dependencyTrees, this.reportId, this.apiKey);
|
|
228952
|
-
const workspaceToVulnerabilities = Object.fromEntries(await asyncMap(workspacePaths, async (workspacePath, idx) => this.spinner.wrap(`Scanning for vulnerabilities: (${subProjAndWsPath.packageManagerName}) (${idx + 1}/${workspacePaths.length}) ${workspacePath}`, async () => {
|
|
228953
|
-
const dependencyTree = projectInfo[workspacePath].dataForAnalysis.data.dependencyTree;
|
|
228954
|
-
this.sendProgress("SCAN_FOR_VULNERABILITIES", true, subprojectPath, workspacePath);
|
|
228955
|
-
try {
|
|
228956
|
-
return [
|
|
228957
|
-
workspacePath,
|
|
228958
|
-
this.options.socketMode ? await scanForVulnerabilitiesSocketMode(projectInfo[workspacePath].dataForAnalysis.data.dependencyTree) : (await scanForVulnerabilities(dependencyTree, this.options.offlineDatabase, this.apiKey, Number(this.options.timeout))).vulnerabilities
|
|
228959
|
-
];
|
|
228960
|
-
} catch (e) {
|
|
228961
|
-
logger.error(`Scanning for vulnerabilities failed for subproject ${subprojectPath} in workspace ${workspacePath}`);
|
|
228962
|
-
if (this.options.ignoreFailingWorkspaces) {
|
|
228963
|
-
const relativeSubprojectPath = relative14(this.rootWorkingDirectory, subprojectPath) || ".";
|
|
228964
|
-
this.failedWorkspaces.push({
|
|
228965
|
-
subproject: relativeSubprojectPath,
|
|
228966
|
-
workspace: workspacePath,
|
|
228967
|
-
error: e.message || "Unknown error",
|
|
228968
|
-
phase: "vulnerability-scanning"
|
|
228969
|
-
});
|
|
228970
|
-
return [workspacePath, void 0];
|
|
228971
|
-
}
|
|
228972
|
-
throw e;
|
|
228973
|
-
} finally {
|
|
228974
|
-
this.sendProgress("SCAN_FOR_VULNERABILITIES", false, subprojectPath, workspacePath);
|
|
228975
|
-
}
|
|
228976
|
-
})));
|
|
228977
|
-
const successfulWorkspaceToVulnerabilities = Object.fromEntries(Object.entries(workspaceToVulnerabilities).filter(([_, vulns]) => vulns !== void 0));
|
|
228978
|
-
return { projectInfo, workspaceToVulnerabilities: successfulWorkspaceToVulnerabilities };
|
|
228979
|
-
}
|
|
228980
|
-
};
|
|
228981
|
-
function getRelativeSubprojectPath(subprojectPath, projectDir) {
|
|
228982
|
-
return relative14(projectDir, subprojectPath) || ".";
|
|
228983
|
-
}
|
|
228984
|
-
function getDependencyType(vulnChainDetails, codeAwareScanResults, directDependencies, reachability) {
|
|
228985
|
-
if (reachability === "UNREACHABLE" || reachability === "UNKNOWN") {
|
|
228986
|
-
return getDependencyTypeForUnreachableVulnerability(vulnChainDetails, directDependencies);
|
|
228987
|
-
}
|
|
228988
|
-
if (codeAwareScanResults.type === "noAnalysisCheck") {
|
|
228989
|
-
const affectedPackages = [
|
|
228990
|
-
"",
|
|
228991
|
-
...Object.values(vulnChainDetails?.transitiveDependencies ?? []).map((n2) => `${n2.packageName}@${n2.version}`)
|
|
228992
|
-
];
|
|
228993
|
-
return getDependencyTypeForReachableVulnerability(vulnChainDetails, directDependencies, affectedPackages);
|
|
228994
|
-
}
|
|
228995
|
-
if (codeAwareScanResults.type !== "success") {
|
|
228996
|
-
throw new Error(`AssertionError: Expected codeAwareScanResults to be either success or noAnalysisCheck when reachability is REACHABLE`);
|
|
228997
|
-
}
|
|
228998
|
-
const detectedOccurrences = codeAwareScanResults.detectedOccurrences;
|
|
228999
|
-
let dependencyType = "unknown";
|
|
229000
|
-
for (const detectedOccurrence of Array.isArray(detectedOccurrences) ? detectedOccurrences : [detectedOccurrences]) {
|
|
229001
|
-
const affectedPackages = detectedOccurrence.affectedPackages;
|
|
229002
|
-
const dependencyTypeForOccurrence = getDependencyTypeForReachableVulnerability(vulnChainDetails, directDependencies, affectedPackages);
|
|
229003
|
-
if (dependencyType === "unknown") {
|
|
229004
|
-
dependencyType = dependencyTypeForOccurrence;
|
|
229005
|
-
} else if (dependencyType !== dependencyTypeForOccurrence) {
|
|
229006
|
-
return "prod&dev";
|
|
229007
|
-
}
|
|
229008
|
-
}
|
|
229009
|
-
if (dependencyType === "unknown") {
|
|
229010
|
-
dependencyType = getDependencyTypeForUnreachableVulnerability(vulnChainDetails, directDependencies);
|
|
229011
|
-
}
|
|
229012
|
-
return dependencyType;
|
|
229013
|
-
}
|
|
229014
|
-
async function getGitDataToMetadataIfAvailable(rootWorkingDirectory) {
|
|
229015
|
-
const base = cmdt`git -c safe.directory=${rootWorkingDirectory} rev-parse`;
|
|
229016
|
-
try {
|
|
229017
|
-
return {
|
|
229018
|
-
sha: await runCommandResolveStdOut([...base, "HEAD"], rootWorkingDirectory),
|
|
229019
|
-
branchName: await runCommandResolveStdOut([...base, "--abbrev-ref", "HEAD"], rootWorkingDirectory)
|
|
229020
|
-
};
|
|
229021
|
-
} catch (e) {
|
|
229022
|
-
logger.debug("Unable to get git data. Is the folder even in a git repository?", e);
|
|
229023
|
-
}
|
|
229024
|
-
}
|
|
229025
|
-
|
|
229026
|
-
// dist/cli-upgrade-purl.js
|
|
229027
|
-
import { join as join27, relative as relative15, resolve as resolve34 } from "node:path";
|
|
229028
|
-
var import_packageurl_js3 = __toESM(require_packageurl_js(), 1);
|
|
229029
|
-
var ECOSYSTEMS_WITH_SOCKET_UPGRADES = ["NPM", "MAVEN", "NUGET", "GO", "RUST"];
|
|
229030
|
-
async function upgradePurl(rootDir, upgrades, options, logFile, cliFixRunId) {
|
|
229031
|
-
if (options.rangeStyle && options.rangeStyle !== "pin") {
|
|
229032
|
-
throw new Error('Range style must be "pin"');
|
|
229033
|
-
}
|
|
229034
|
-
logger.initWinstonLogger(options.debug);
|
|
229035
|
-
logger.silent = options.silent;
|
|
229036
|
-
let cliRunId = cliFixRunId;
|
|
229037
|
-
if (!cliRunId && options.manifestsTarHash) {
|
|
229038
|
-
cliRunId = await getSocketAPI().registerAutofixOrUpgradePurlRun(options.manifestsTarHash, options, "upgrade-purls");
|
|
229039
|
-
}
|
|
229040
|
-
const upgradePurlRunId = cliRunId && await getSocketAPI().registerUpgradePurlRun(cliRunId, upgrades);
|
|
229041
|
-
Spinner.instance({
|
|
229042
|
-
text: "Running Coana Upgrade Purl CLI",
|
|
229043
|
-
isSilent: options.silentSpinner ?? options.silent
|
|
229044
|
-
}).start();
|
|
229045
|
-
try {
|
|
229046
|
-
logger.info(`Upgrading purls for ${rootDir}:
|
|
229047
|
-
${upgrades.map(({ purl, upgradeVersion }) => ` ${prettyPrintPurlUpgrade(purl, upgradeVersion)}`).join("\n")}`);
|
|
229048
|
-
if (options.manifestsTarHash) {
|
|
229049
|
-
const { supportedUpgrades, unsupportedUpgrades } = upgrades.reduce((acc, upgrade) => {
|
|
229050
|
-
const ecosystem = getAdvisoryEcosystemFromPurl(upgrade.purl);
|
|
229051
|
-
const target = ECOSYSTEMS_WITH_SOCKET_UPGRADES.includes(ecosystem) ? "supportedUpgrades" : "unsupportedUpgrades";
|
|
229052
|
-
acc[target].push(upgrade);
|
|
229053
|
-
return acc;
|
|
229054
|
-
}, { supportedUpgrades: [], unsupportedUpgrades: [] });
|
|
229055
|
-
if (unsupportedUpgrades.length > 0) {
|
|
229056
|
-
logger.warn(`The following upgrades are not supported due to missing support for upgrading their ecosystem: ${unsupportedUpgrades.map(({ purl, upgradeVersion }) => ` ${prettyPrintPurlUpgrade(purl, upgradeVersion)}`).join("\n")}`);
|
|
229057
|
-
}
|
|
229058
|
-
if (supportedUpgrades.length === 0) {
|
|
229059
|
-
return "fixed-none";
|
|
229060
|
-
}
|
|
229061
|
-
try {
|
|
229062
|
-
const purlToUpgradeVersion = new Map(supportedUpgrades.map((upgrade) => [upgrade.purl, upgrade.upgradeVersion]));
|
|
229063
|
-
const [manifestFiles, artifacts] = await Promise.all([
|
|
229064
|
-
fetchManifestFilesFromManifestsTarHash(options.manifestsTarHash),
|
|
229065
|
-
(await fetchArtifactsFromSocket(rootDir, options.manifestsTarHash, "upgrade-purls")).artifacts
|
|
229066
|
-
]);
|
|
229067
|
-
const ecosystemToSocketArtifactUpgrades = /* @__PURE__ */ new Map();
|
|
229068
|
-
artifacts.forEach((artifact, idx) => {
|
|
229069
|
-
if (!artifact.name)
|
|
229070
|
-
return;
|
|
229071
|
-
if (!artifact.version)
|
|
229072
|
-
return;
|
|
229073
|
-
const purl = new import_packageurl_js3.PackageURL(artifact.type, artifact.namespace, artifact.name, artifact.version, artifact.qualifiers).toString();
|
|
229074
|
-
const upgradeVersion = purlToUpgradeVersion.get(purl);
|
|
229075
|
-
if (!upgradeVersion)
|
|
229076
|
-
return;
|
|
229077
|
-
const ecosystem = getAdvisoryEcosystemFromPurlType(artifact.type);
|
|
229078
|
-
if (!ecosystemToSocketArtifactUpgrades.has(ecosystem)) {
|
|
229079
|
-
ecosystemToSocketArtifactUpgrades.set(ecosystem, /* @__PURE__ */ new Map());
|
|
229080
|
-
}
|
|
229081
|
-
const currentUpgradeVersion = ecosystemToSocketArtifactUpgrades.get(ecosystem).get(idx);
|
|
229082
|
-
if (currentUpgradeVersion === void 0) {
|
|
229083
|
-
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, upgradeVersion);
|
|
229084
|
-
} else {
|
|
229085
|
-
const versions = sortVersions(ecosystem, [artifact.version, currentUpgradeVersion, upgradeVersion]);
|
|
229086
|
-
if (versionSatisfiesRelation(ecosystem, artifact.version, "=", versions[0])) {
|
|
229087
|
-
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, versions[versions.length - 1]);
|
|
229088
|
-
} else if (versionSatisfiesRelation(ecosystem, artifact.version, "=", versions[versions.length - 1])) {
|
|
229089
|
-
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, versions[0]);
|
|
229090
|
-
} else {
|
|
229091
|
-
ecosystemToSocketArtifactUpgrades.get(ecosystem).set(idx, versions[versions.length - 1]);
|
|
229092
|
-
}
|
|
229093
|
-
}
|
|
229094
|
-
});
|
|
229095
|
-
let anyErrors = false;
|
|
229096
|
-
for (const [ecosystem, upgrades2] of ecosystemToSocketArtifactUpgrades) {
|
|
229097
|
-
if (options.rangeStyle && !["NPM", "MAVEN", "NUGET", "RUST"].includes(ecosystem)) {
|
|
229098
|
-
logger.warn(`Range style is not supported for ${ecosystem}, skipping upgrades`);
|
|
229099
|
-
continue;
|
|
229100
|
-
}
|
|
229101
|
-
const statusUpdater = (update2) => {
|
|
229102
|
-
const statusIcons = {
|
|
229103
|
-
success: "\u2705",
|
|
229104
|
-
skipped: "\u26AA",
|
|
229105
|
-
warn: "\u26A0\uFE0F",
|
|
229106
|
-
error: "\u274C"
|
|
229107
|
-
};
|
|
229108
|
-
logger.info(`${statusIcons[update2.status]} ${update2.message} \u2500 ${relative15(rootDir, resolve34(rootDir, update2.file))}`);
|
|
229109
|
-
update2.artifacts.forEach((idx, i7) => {
|
|
229110
|
-
logger.info(`${" ".repeat(3)}${i7 === update2.artifacts.length - 1 ? "\u2514\u2500" : "\u251C\u2500"} ${prettyPrintSocketFactArtifactUpgrade(artifacts[idx], upgrades2.get(idx))}`);
|
|
229111
|
-
});
|
|
229112
|
-
for (const detail of update2.details ?? []) {
|
|
229113
|
-
logger.debug(detail);
|
|
229114
|
-
}
|
|
229115
|
-
if (update2.patch)
|
|
229116
|
-
logger.debug(update2.patch);
|
|
229117
|
-
if (update2.status === "error")
|
|
229118
|
-
anyErrors = true;
|
|
229119
|
-
};
|
|
229120
|
-
const ctxt = {
|
|
229121
|
-
manifestFiles,
|
|
229122
|
-
upgrades: upgrades2,
|
|
229123
|
-
artifacts,
|
|
229124
|
-
rangeStyle: options.rangeStyle,
|
|
229125
|
-
statusUpdater
|
|
229126
|
-
};
|
|
229127
|
-
await applySocketUpgrades(ecosystem, rootDir, ctxt);
|
|
229128
|
-
}
|
|
229129
|
-
if (upgradePurlRunId) {
|
|
229130
|
-
await getSocketAPI().finalizeUpgradePurlRun(upgradePurlRunId, "succeeded");
|
|
229131
|
-
}
|
|
229132
|
-
return unsupportedUpgrades.length === 0 && !anyErrors ? "fixed-all" : "fixed-some";
|
|
229133
|
-
} catch (error) {
|
|
229134
|
-
if (upgradePurlRunId) {
|
|
229135
|
-
await getSocketAPI().finalizeUpgradePurlRun(
|
|
229136
|
-
upgradePurlRunId,
|
|
229137
|
-
"error",
|
|
229138
|
-
!cliFixRunId ? error.stack : void 0,
|
|
229139
|
-
// do not send stack trace and logContent for computeFixes runs, as that will be handled by that command.
|
|
229140
|
-
!cliFixRunId && logFile ? await logger.getLogContent(logFile) : void 0
|
|
229141
|
-
);
|
|
229142
|
-
}
|
|
229143
|
-
throw error;
|
|
229144
|
-
}
|
|
229145
|
-
}
|
|
229146
|
-
const otherModulesCommunicator = new OtherModulesCommunicator(rootDir, options, {
|
|
229147
|
-
type: "missing"
|
|
229148
|
-
});
|
|
229149
|
-
const ecosystems = upgrades.map((upgrade) => getAdvisoryEcosystemFromPurl(upgrade.purl));
|
|
229150
|
-
const manager = await ProjectManager.create(rootDir, otherModulesCommunicator, ecosystems);
|
|
229151
|
-
const { reachabilitySupport, traditionalScaSupport } = manager.getSubprojectsWithWorkspacePaths();
|
|
229152
|
-
const supportedSubprojects = reachabilitySupport.concat(traditionalScaSupport).filter((p3) => getPackageManagerSupport(p3.packageManagerName).supportsApplyingFixes);
|
|
229153
|
-
if (supportedSubprojects.length === 0) {
|
|
229154
|
-
throw new Error(`No supported projects found in ${rootDir}.`);
|
|
229304
|
+
}
|
|
229305
|
+
async getDependencyTreeAndVulnerabilities(otherModulesCommunicator, subProjAndWsPath) {
|
|
229306
|
+
const { packageManagerName, subprojectPath, workspacePaths } = subProjAndWsPath;
|
|
229307
|
+
this.sendProgress("RUN_ON_SUBPROJECT", true, subprojectPath);
|
|
229308
|
+
const rootWorkingDirectory = this.rootWorkingDirectory;
|
|
229309
|
+
this.sendProgress("PREPARE_PROJECT_AND_GET_PROJECT_DATA", true, subprojectPath);
|
|
229310
|
+
const projectInfo = await otherModulesCommunicator.prepareProjectAndGetProjectData(packageManagerName, subprojectPath, workspacePaths, this.options.lightweightReachability, this.options.providerProject ? await this.runOnProvider(this.options.providerProject) : void 0);
|
|
229311
|
+
this.sendProgress("PREPARE_PROJECT_AND_GET_PROJECT_DATA", false, subprojectPath);
|
|
229312
|
+
const workspaceToPlainDependencyTree = Object.fromEntries(workspacePaths.map((workspacePath) => [
|
|
229313
|
+
workspacePath,
|
|
229314
|
+
toPlainDependencyTree(projectInfo[workspacePath].dataForAnalysis.data.dependencyTree)
|
|
229315
|
+
]));
|
|
229316
|
+
const dependencyTrees = workspacePaths.map((workspacePath) => ({
|
|
229317
|
+
treeType: "v1",
|
|
229318
|
+
dependencyTree: workspaceToPlainDependencyTree[workspacePath],
|
|
229319
|
+
ecosystem: workspaceToPlainDependencyTree[workspacePath].ecosystem ?? "NPM",
|
|
229320
|
+
workspacePath,
|
|
229321
|
+
subprojectPath: relative15(rootWorkingDirectory, subprojectPath) || "."
|
|
229322
|
+
}));
|
|
229323
|
+
if (this.options.socketMode) {
|
|
229324
|
+
this.reportDependencyTrees = workspacePaths.map((workspacePath) => ({
|
|
229325
|
+
treeType: "v1",
|
|
229326
|
+
dependencyTree: projectInfo[workspacePath].dataForAnalysis.data.dependencyTree,
|
|
229327
|
+
ecosystem: projectInfo[workspacePath].dataForAnalysis.data.dependencyTree.ecosystem ?? "NPM",
|
|
229328
|
+
workspacePath,
|
|
229329
|
+
subprojectPath: relative15(rootWorkingDirectory, subprojectPath) || "."
|
|
229330
|
+
}));
|
|
229155
229331
|
}
|
|
229156
|
-
|
|
229157
|
-
|
|
229158
|
-
|
|
229159
|
-
|
|
229160
|
-
|
|
229161
|
-
|
|
229162
|
-
|
|
229163
|
-
|
|
229164
|
-
|
|
229165
|
-
|
|
229166
|
-
|
|
229167
|
-
|
|
229168
|
-
|
|
229169
|
-
|
|
229170
|
-
|
|
229171
|
-
|
|
229172
|
-
|
|
229173
|
-
|
|
229174
|
-
|
|
229175
|
-
const node = depTree.transitiveDependencies[depIdMatchingPurl];
|
|
229176
|
-
if (!node)
|
|
229177
|
-
throw Error("should not happen!");
|
|
229178
|
-
vulnerabilityFixes.push({
|
|
229179
|
-
dependencyName: node.packageName,
|
|
229180
|
-
currentVersion: assertDefined(node.version),
|
|
229181
|
-
dependencyIdentifier: depIdMatchingPurl,
|
|
229182
|
-
fixedVersion: upgrade.upgradeVersion
|
|
229183
|
-
});
|
|
229184
|
-
}
|
|
229332
|
+
if (this.shareWithDashboard)
|
|
229333
|
+
sendDependencyTreesToDashboard(dependencyTrees, this.reportId, this.apiKey);
|
|
229334
|
+
const workspaceToVulnerabilities = Object.fromEntries(await asyncMap(workspacePaths, async (workspacePath, idx) => this.spinner.wrap(`Scanning for vulnerabilities: (${subProjAndWsPath.packageManagerName}) (${idx + 1}/${workspacePaths.length}) ${workspacePath}`, async () => {
|
|
229335
|
+
const dependencyTree = projectInfo[workspacePath].dataForAnalysis.data.dependencyTree;
|
|
229336
|
+
this.sendProgress("SCAN_FOR_VULNERABILITIES", true, subprojectPath, workspacePath);
|
|
229337
|
+
try {
|
|
229338
|
+
return [
|
|
229339
|
+
workspacePath,
|
|
229340
|
+
this.options.socketMode ? await scanForVulnerabilitiesSocketMode(projectInfo[workspacePath].dataForAnalysis.data.dependencyTree) : (await scanForVulnerabilities(dependencyTree, this.options.offlineDatabase, this.apiKey, Number(this.options.timeout))).vulnerabilities
|
|
229341
|
+
];
|
|
229342
|
+
} catch (e) {
|
|
229343
|
+
logger.error(`Scanning for vulnerabilities failed for subproject ${subprojectPath} in workspace ${workspacePath}`);
|
|
229344
|
+
if (this.options.ignoreFailingWorkspaces) {
|
|
229345
|
+
const relativeSubprojectPath = relative15(this.rootWorkingDirectory, subprojectPath) || ".";
|
|
229346
|
+
this.failedWorkspaces.push({
|
|
229347
|
+
subproject: relativeSubprojectPath,
|
|
229348
|
+
workspace: workspacePath,
|
|
229349
|
+
error: e.message || "Unknown error",
|
|
229350
|
+
phase: "vulnerability-scanning"
|
|
229185
229351
|
});
|
|
229186
|
-
|
|
229187
|
-
return;
|
|
229188
|
-
logger.info(`Found ${vulnerabilityFixes.length} ${vulnerabilityFixes.length === 1 ? "dependency" : "dependencies"} matching upgrade specs for ${join27(subproject.subprojectPath, wsPath)}`);
|
|
229189
|
-
workspaceToFixes[wsPath] = [
|
|
229190
|
-
{
|
|
229191
|
-
fixId: "dummy",
|
|
229192
|
-
vulnerabilityFixes
|
|
229193
|
-
}
|
|
229194
|
-
];
|
|
229195
|
-
});
|
|
229196
|
-
if (Object.entries(workspaceToFixes).length === 0) {
|
|
229197
|
-
logger.info(`No dependencies matching upgrade specs found for subproject ${subproject.subprojectPath}`);
|
|
229198
|
-
return;
|
|
229352
|
+
return [workspacePath, void 0];
|
|
229199
229353
|
}
|
|
229200
|
-
|
|
229201
|
-
}
|
|
229202
|
-
|
|
229203
|
-
|
|
229204
|
-
|
|
229205
|
-
|
|
229354
|
+
throw e;
|
|
229355
|
+
} finally {
|
|
229356
|
+
this.sendProgress("SCAN_FOR_VULNERABILITIES", false, subprojectPath, workspacePath);
|
|
229357
|
+
}
|
|
229358
|
+
})));
|
|
229359
|
+
const successfulWorkspaceToVulnerabilities = Object.fromEntries(Object.entries(workspaceToVulnerabilities).filter(([_, vulns]) => vulns !== void 0));
|
|
229360
|
+
return { projectInfo, workspaceToVulnerabilities: successfulWorkspaceToVulnerabilities };
|
|
229206
229361
|
}
|
|
229207
|
-
}
|
|
229208
|
-
var signalFixApplied = (_fixId, subprojectPath, workspacePath, vulnerabilityFixes) => {
|
|
229209
|
-
logger.info(`Successfully upgraded purls for: ${join27(subprojectPath, workspacePath)}`);
|
|
229210
|
-
logger.info(`Upgraded:
|
|
229211
|
-
${vulnerabilityFixes.map((fix) => ` ${fix.dependencyName} from ${fix.currentVersion} to ${fix.fixedVersion}`).join("\n")}`);
|
|
229212
229362
|
};
|
|
229213
|
-
|
|
229214
|
-
|
|
229215
|
-
|
|
229216
|
-
|
|
229217
|
-
|
|
229218
|
-
|
|
229219
|
-
logger.info("No vulnerabilities to compute fixes for");
|
|
229220
|
-
return { type: "no-vulnerabilities-found" };
|
|
229221
|
-
}
|
|
229222
|
-
if (options.applyFixesTo.length === 0) {
|
|
229223
|
-
logger.info("Vulnerabilities found:", Object.keys(ghsaToVulnerableArtifactIds).join(", "));
|
|
229224
|
-
logger.info("Run again with --apply-fixes-to GHSA_IDS to fix those vulnerabilities by computing packages to upgrade and apply them");
|
|
229225
|
-
return { type: "no-ghsas-fix-requested", ghsas: Object.keys(ghsaToVulnerableArtifactIds) };
|
|
229226
|
-
}
|
|
229227
|
-
const ghsaToVulnerableArtifactIdsToApply = options.applyFixesTo.includes("all") ? ghsaToVulnerableArtifactIds : Object.fromEntries(Object.entries(ghsaToVulnerableArtifactIds).filter(([ghsa]) => options.applyFixesTo.includes(ghsa)));
|
|
229228
|
-
const computedFix = await useSocketComputeFixEndpoint(autofixRunId, artifacts, ghsaToVulnerableArtifactIdsToApply, {
|
|
229229
|
-
noMajorUpdates: options.disableMajorUpdates,
|
|
229230
|
-
minimumReleaseAgeInMinutes: options.minimumReleaseAgeInMinutes
|
|
229231
|
-
});
|
|
229232
|
-
if (computedFix.type !== "success") {
|
|
229233
|
-
throw new Error(`No fix found for the given vulnerabilities`);
|
|
229363
|
+
function getRelativeSubprojectPath(subprojectPath, projectDir) {
|
|
229364
|
+
return relative15(projectDir, subprojectPath) || ".";
|
|
229365
|
+
}
|
|
229366
|
+
function getDependencyType(vulnChainDetails, codeAwareScanResults, directDependencies, reachability) {
|
|
229367
|
+
if (reachability === "UNREACHABLE" || reachability === "UNKNOWN") {
|
|
229368
|
+
return getDependencyTypeForUnreachableVulnerability(vulnChainDetails, directDependencies);
|
|
229234
229369
|
}
|
|
229235
|
-
|
|
229236
|
-
const
|
|
229237
|
-
|
|
229238
|
-
|
|
229239
|
-
|
|
229240
|
-
|
|
229241
|
-
if (ghsasFailedToFix.length > 0) {
|
|
229242
|
-
logger.info("Failed to compute fixes for the following vulnerabilities:");
|
|
229370
|
+
if (codeAwareScanResults.type === "noAnalysisCheck") {
|
|
229371
|
+
const affectedPackages = [
|
|
229372
|
+
"",
|
|
229373
|
+
...Object.values(vulnChainDetails?.transitiveDependencies ?? []).map((n2) => `${n2.packageName}@${n2.version}`)
|
|
229374
|
+
];
|
|
229375
|
+
return getDependencyTypeForReachableVulnerability(vulnChainDetails, directDependencies, affectedPackages);
|
|
229243
229376
|
}
|
|
229244
|
-
|
|
229245
|
-
|
|
229377
|
+
if (codeAwareScanResults.type !== "success") {
|
|
229378
|
+
throw new Error(`AssertionError: Expected codeAwareScanResults to be either success or noAnalysisCheck when reachability is REACHABLE`);
|
|
229246
229379
|
}
|
|
229247
|
-
const
|
|
229248
|
-
|
|
229249
|
-
|
|
229250
|
-
|
|
229251
|
-
|
|
229252
|
-
|
|
229253
|
-
|
|
229254
|
-
|
|
229255
|
-
|
|
229380
|
+
const detectedOccurrences = codeAwareScanResults.detectedOccurrences;
|
|
229381
|
+
let dependencyType = "unknown";
|
|
229382
|
+
for (const detectedOccurrence of Array.isArray(detectedOccurrences) ? detectedOccurrences : [detectedOccurrences]) {
|
|
229383
|
+
const affectedPackages = detectedOccurrence.affectedPackages;
|
|
229384
|
+
const dependencyTypeForOccurrence = getDependencyTypeForReachableVulnerability(vulnChainDetails, directDependencies, affectedPackages);
|
|
229385
|
+
if (dependencyType === "unknown") {
|
|
229386
|
+
dependencyType = dependencyTypeForOccurrence;
|
|
229387
|
+
} else if (dependencyType !== dependencyTypeForOccurrence) {
|
|
229388
|
+
return "prod&dev";
|
|
229256
229389
|
}
|
|
229257
|
-
return {
|
|
229258
|
-
type: "dry-run-result",
|
|
229259
|
-
fixes: Object.fromEntries(fixesFound.map(([ghsa, result]) => [ghsa, result.fixes])),
|
|
229260
|
-
...ghsasFailedToFix.length > 0 && { failedToFix: ghsasFailedToFix }
|
|
229261
|
-
};
|
|
229262
229390
|
}
|
|
229263
|
-
if (
|
|
229264
|
-
|
|
229265
|
-
await getSocketAPI().finalizeAutofixRun(autofixRunId, "fixed-none");
|
|
229266
|
-
}
|
|
229267
|
-
throw new Error("Failed to find a fix for the given vulnerabilities");
|
|
229391
|
+
if (dependencyType === "unknown") {
|
|
229392
|
+
dependencyType = getDependencyTypeForUnreachableVulnerability(vulnChainDetails, directDependencies);
|
|
229268
229393
|
}
|
|
229394
|
+
return dependencyType;
|
|
229395
|
+
}
|
|
229396
|
+
async function getGitDataToMetadataIfAvailable(rootWorkingDirectory) {
|
|
229397
|
+
const base = cmdt`git -c safe.directory=${rootWorkingDirectory} rev-parse`;
|
|
229269
229398
|
try {
|
|
229270
|
-
const applyFixesStatus = await upgradePurl(path2, T3(combinedFixes, (fix) => `${fix.purl}${fix.fixedVersion}`).map((fix) => ({
|
|
229271
|
-
purl: fix.purl,
|
|
229272
|
-
upgradeVersion: fix.fixedVersion
|
|
229273
|
-
})), {
|
|
229274
|
-
debug: options.debug,
|
|
229275
|
-
silent: options.silent,
|
|
229276
|
-
runWithoutDocker: options.runWithoutDocker,
|
|
229277
|
-
manifestsTarHash: options.manifestsTarHash,
|
|
229278
|
-
concurrency: "1",
|
|
229279
|
-
globPattern: options.globPattern,
|
|
229280
|
-
rangeStyle: options.rangeStyle
|
|
229281
|
-
}, void 0, autofixRunId) ?? "fixed-all";
|
|
229282
|
-
if (autofixRunId) {
|
|
229283
|
-
await getSocketAPI().finalizeAutofixRun(autofixRunId, ghsasFailedToFix.length === 0 && applyFixesStatus === "fixed-all" ? "fixed-all" : ghsasFailedToFix.length === Object.keys(ghsaToVulnerableArtifactIdsToApply).length || applyFixesStatus === "fixed-none" ? "fixed-none" : "fixed-some");
|
|
229284
|
-
}
|
|
229285
229399
|
return {
|
|
229286
|
-
|
|
229287
|
-
|
|
229400
|
+
sha: await runCommandResolveStdOut([...base, "HEAD"], rootWorkingDirectory),
|
|
229401
|
+
branchName: await runCommandResolveStdOut([...base, "--abbrev-ref", "HEAD"], rootWorkingDirectory)
|
|
229288
229402
|
};
|
|
229289
|
-
} catch (
|
|
229290
|
-
|
|
229291
|
-
await getSocketAPI().finalizeAutofixRun(autofixRunId, "error", error.stack, await logger.getLogContent(logFile));
|
|
229292
|
-
}
|
|
229293
|
-
logger.error("Error applying fixes:", error);
|
|
229294
|
-
throw error;
|
|
229295
|
-
}
|
|
229296
|
-
}
|
|
229297
|
-
async function computeInputForComputingFixes(path2, options) {
|
|
229298
|
-
if (options.manifestsTarHash) {
|
|
229299
|
-
const { artifacts: artifacts2 } = await fetchArtifactsFromSocket(path2, options.manifestsTarHash, "autofix");
|
|
229300
|
-
const ghsaToVulnerableArtifactIds2 = {};
|
|
229301
|
-
for (const [index2, artifact] of artifacts2.entries()) {
|
|
229302
|
-
if (!artifact.vulnerabilities)
|
|
229303
|
-
continue;
|
|
229304
|
-
for (const vulnerability of artifact.vulnerabilities) {
|
|
229305
|
-
if (!(ghsaToVulnerableArtifactIds2[vulnerability.ghsaId] ??= []).includes(index2)) {
|
|
229306
|
-
ghsaToVulnerableArtifactIds2[vulnerability.ghsaId].push(index2);
|
|
229307
|
-
}
|
|
229308
|
-
}
|
|
229309
|
-
}
|
|
229310
|
-
const sbomTaskArtifacts = artifacts2.map((artifact) => ({
|
|
229311
|
-
type: artifact.type,
|
|
229312
|
-
name: artifact.name ?? "",
|
|
229313
|
-
version: artifact.version ?? "",
|
|
229314
|
-
namespace: artifact.namespace ?? void 0,
|
|
229315
|
-
adj: artifact.dependencies?.map((dep) => artifacts2.findIndex((a4) => a4.id === dep)) ?? []
|
|
229316
|
-
}));
|
|
229317
|
-
return { artifacts: sbomTaskArtifacts, ghsaToVulnerableArtifactIds: ghsaToVulnerableArtifactIds2 };
|
|
229318
|
-
}
|
|
229319
|
-
const otherModulesCommunicator = new OtherModulesCommunicator(path2, options, {
|
|
229320
|
-
type: "missing"
|
|
229321
|
-
});
|
|
229322
|
-
const manager = await ProjectManager.create(path2, otherModulesCommunicator);
|
|
229323
|
-
const { reachabilitySupport, traditionalScaSupport } = manager.getSubprojectsWithWorkspacePaths();
|
|
229324
|
-
const supportedSubprojects = reachabilitySupport.concat(traditionalScaSupport).filter((p3) => getPackageManagerSupport(p3.packageManagerName).supportsApplyingFixes);
|
|
229325
|
-
if (supportedSubprojects.length === 0) {
|
|
229326
|
-
throw new Error(`No supported projects found in ${path2}.`);
|
|
229327
|
-
}
|
|
229328
|
-
const cliCore = new CliCore(path2, { ...defaultCliOptions, socketMode: "true" });
|
|
229329
|
-
const results = await asyncMap(supportedSubprojects, async (subproject) => cliCore.getDependencyTreeAndVulnerabilities(otherModulesCommunicator, subproject));
|
|
229330
|
-
const { artifacts, purlToIndex } = computeSBOMTaskArtifacts(results.flatMap((r3) => Object.values(r3.projectInfo).map((info) => info.dataForAnalysis.data.dependencyTree)));
|
|
229331
|
-
const ghsaToVulnerableArtifactIds = computeVulnerableArtifactIdsPerVulnerability(results.flatMap((r3) => Object.values(r3.workspaceToVulnerabilities).flat()), purlToIndex);
|
|
229332
|
-
return { artifacts, ghsaToVulnerableArtifactIds };
|
|
229333
|
-
}
|
|
229334
|
-
function computeVulnerableArtifactIdsPerVulnerability(vulnerabilities, purlToIndex) {
|
|
229335
|
-
const vulnerableArtifactIdsPerVulnerability = {};
|
|
229336
|
-
for (const vulnerability of vulnerabilities) {
|
|
229337
|
-
if (!vulnerableArtifactIdsPerVulnerability[vulnerability.url]) {
|
|
229338
|
-
vulnerableArtifactIdsPerVulnerability[vulnerability.url] = [];
|
|
229339
|
-
}
|
|
229340
|
-
if (!vulnerability.purl)
|
|
229341
|
-
throw new Error(`Vulnerability ${vulnerability.url} has no purl`);
|
|
229342
|
-
if (!purlToIndex.has(vulnerability.purl)) {
|
|
229343
|
-
throw new Error(`Vulnerability ${vulnerability.url} has no purl in sbomTaskArtifacts`);
|
|
229344
|
-
}
|
|
229345
|
-
const index2 = purlToIndex.get(vulnerability.purl);
|
|
229346
|
-
if (!vulnerableArtifactIdsPerVulnerability[vulnerability.url].includes(index2)) {
|
|
229347
|
-
vulnerableArtifactIdsPerVulnerability[vulnerability.url].push(index2);
|
|
229348
|
-
}
|
|
229349
|
-
}
|
|
229350
|
-
return vulnerableArtifactIdsPerVulnerability;
|
|
229351
|
-
}
|
|
229352
|
-
function computeSBOMTaskArtifacts(dependencyTrees) {
|
|
229353
|
-
const components = [];
|
|
229354
|
-
const purlToIndex = /* @__PURE__ */ new Map();
|
|
229355
|
-
for (const dependencyTree of dependencyTrees) {
|
|
229356
|
-
const depIdentifierToPurl = Object.fromEntries(Object.entries(dependencyTree.transitiveDependencies).filter(([_depIdentifier, dep]) => dep.purlObj).map(([depIdentifier, dep]) => {
|
|
229357
|
-
const purl = dep.purlObj.purlString;
|
|
229358
|
-
if (purl && !purlToIndex.has(purl)) {
|
|
229359
|
-
purlToIndex.set(purl, components.length);
|
|
229360
|
-
const depTreeNode = dependencyTree.transitiveDependencies[depIdentifier];
|
|
229361
|
-
components[purlToIndex.get(purl)] = {
|
|
229362
|
-
type: depTreeNode.purlObj.type,
|
|
229363
|
-
name: depTreeNode.purlObj.name,
|
|
229364
|
-
version: depTreeNode.purlObj.version,
|
|
229365
|
-
namespace: depTreeNode.purlObj.namespace,
|
|
229366
|
-
adj: []
|
|
229367
|
-
};
|
|
229368
|
-
}
|
|
229369
|
-
return [depIdentifier, purl];
|
|
229370
|
-
}));
|
|
229371
|
-
for (const [depIdentifier, purl] of Object.entries(depIdentifierToPurl)) {
|
|
229372
|
-
const depTreeNode = dependencyTree.transitiveDependencies[depIdentifier];
|
|
229373
|
-
if (!depTreeNode.purlObj) {
|
|
229374
|
-
continue;
|
|
229375
|
-
}
|
|
229376
|
-
const component = components[purlToIndex.get(purl)];
|
|
229377
|
-
depTreeNode.dependencies?.forEach((dep) => {
|
|
229378
|
-
const depPurl = depIdentifierToPurl[dep];
|
|
229379
|
-
const depIndex = purlToIndex.get(depPurl);
|
|
229380
|
-
if (depIndex && !component.adj?.includes(depIndex)) {
|
|
229381
|
-
component.adj.push(depIndex);
|
|
229382
|
-
}
|
|
229383
|
-
});
|
|
229384
|
-
}
|
|
229403
|
+
} catch (e) {
|
|
229404
|
+
logger.debug("Unable to get git data. Is the folder even in a git repository?", e);
|
|
229385
229405
|
}
|
|
229386
|
-
return { artifacts: components, purlToIndex };
|
|
229387
229406
|
}
|
|
229388
229407
|
|
|
229389
229408
|
// dist/index.js
|
|
@@ -229419,7 +229438,7 @@ upgradePurls.name("upgrade-purls").argument("<path>", "File system path to the f
|
|
|
229419
229438
|
});
|
|
229420
229439
|
}).configureHelp({ sortOptions: true });
|
|
229421
229440
|
var computeFixesAndUpgradePurlsCmd = new Command();
|
|
229422
|
-
computeFixesAndUpgradePurlsCmd.name("compute-fixes-and-upgrade-purls").argument("<path>", "File system path to the folder containing the project").option("-a, --apply-fixes-to <ghsas...>", 'GHSA IDs to compute fixes for. Use "all" to compute fixes for all vulnerabilities.', []).option("--dry-run", "Show what changes would be made without actually making them", false).option("-g, --glob <pattern>", "Glob pattern to filter workspaces by absolute file path").option("-d, --debug", "Enable debug logging", false).option("-s, --silent", "Silence all debug/warning output", false).option("--silent-spinner", "Silence spinner", "CI" in process.env || !process.stdin.isTTY).option("--range-style <style>", 'Range style to use for the output. Currently only "pin" is supported and it only works for npm.').option("--disable-major-updates", "Do not suggest major updates. If only major update are available, the fix will not be applied.", false).option("-o, --output-file <file>", "Writes output to a JSON file").option("--minimum-release-age <minimumReleaseAge>", "Do not allow upgrades to package versions that are newer than minimumReleaseAge. Format is 2m, 5h, 3d or 1w").addOption(new Option("--run-without-docker", "Run package managers without using docker").default(process.env.RUN_WITHOUT_DOCKER === "true").hideHelp()).addOption(new Option("--manifests-tar-hash <hash>", "Hash of the tarball containing all manifest files already uploaded to Socket. If provided, Socket will be used for computing dependency trees.").hideHelp()).version(version2).action(async (path2, options) => {
|
|
229441
|
+
computeFixesAndUpgradePurlsCmd.name("compute-fixes-and-upgrade-purls").argument("<path>", "File system path to the folder containing the project").option("-a, --apply-fixes-to <ghsas...>", 'GHSA IDs to compute fixes for. Use "all" to compute fixes for all vulnerabilities.', []).option("--dry-run", "Show what changes would be made without actually making them", false).option("-g, --glob <pattern>", "Glob pattern to filter workspaces by absolute file path").option("-d, --debug", "Enable debug logging", false).option("-s, --silent", "Silence all debug/warning output", false).option("--silent-spinner", "Silence spinner", "CI" in process.env || !process.stdin.isTTY).option("--range-style <style>", 'Range style to use for the output. Currently only "pin" is supported and it only works for npm.').option("--disable-major-updates", "Do not suggest major updates. If only major update are available, the fix will not be applied.", false).option("-o, --output-file <file>", "Writes output to a JSON file").option("--minimum-release-age <minimumReleaseAge>", "Do not allow upgrades to package versions that are newer than minimumReleaseAge. Format is 2m, 5h, 3d or 1w").option("--show-affected-direct-dependencies", "Show the affected direct dependencies for each vulnerability and what upgrades could fix them - does not apply the upgrades.", false).addOption(new Option("--run-without-docker", "Run package managers without using docker").default(process.env.RUN_WITHOUT_DOCKER === "true").hideHelp()).addOption(new Option("--manifests-tar-hash <hash>", "Hash of the tarball containing all manifest files already uploaded to Socket. If provided, Socket will be used for computing dependency trees.").hideHelp()).version(version2).action(async (path2, options) => {
|
|
229423
229442
|
process.env.DOCKER_IMAGE_TAG ??= version2;
|
|
229424
229443
|
if (options.outputFile && !options.outputFile.endsWith(".json")) {
|
|
229425
229444
|
throw new Error("Output file must have a .json extension");
|