mobbdev 1.0.203 → 1.0.205
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/dist/args/commands/upload_ai_blame.d.mts +176 -2
- package/dist/args/commands/upload_ai_blame.mjs +159 -73
- package/dist/index.mjs +514 -420
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -569,7 +569,7 @@ var init_FilePatterns = __esm({
|
|
|
569
569
|
});
|
|
570
570
|
|
|
571
571
|
// src/features/analysis/scm/services/FileUtils.ts
|
|
572
|
-
import
|
|
572
|
+
import fs from "fs";
|
|
573
573
|
import { promises as fsPromises } from "fs";
|
|
574
574
|
import { isBinary } from "istextorbinary";
|
|
575
575
|
import path from "path";
|
|
@@ -603,11 +603,11 @@ var init_FileUtils = __esm({
|
|
|
603
603
|
return false;
|
|
604
604
|
}
|
|
605
605
|
try {
|
|
606
|
-
const stats =
|
|
606
|
+
const stats = fs.statSync(absoluteFilepath);
|
|
607
607
|
if (stats.size > maxFileSize) {
|
|
608
608
|
return false;
|
|
609
609
|
}
|
|
610
|
-
const data =
|
|
610
|
+
const data = fs.readFileSync(absoluteFilepath);
|
|
611
611
|
if (isBinary(null, data)) {
|
|
612
612
|
return false;
|
|
613
613
|
}
|
|
@@ -644,7 +644,7 @@ var init_FileUtils = __esm({
|
|
|
644
644
|
return [];
|
|
645
645
|
}
|
|
646
646
|
try {
|
|
647
|
-
await fsPromises.access(dir,
|
|
647
|
+
await fsPromises.access(dir, fs.constants.R_OK);
|
|
648
648
|
} catch {
|
|
649
649
|
return [];
|
|
650
650
|
}
|
|
@@ -654,7 +654,7 @@ var init_FileUtils = __esm({
|
|
|
654
654
|
for (const item of items) {
|
|
655
655
|
const fullPath = path.join(dir, item);
|
|
656
656
|
try {
|
|
657
|
-
await fsPromises.access(fullPath,
|
|
657
|
+
await fsPromises.access(fullPath, fs.constants.R_OK);
|
|
658
658
|
const stat = await fsPromises.stat(fullPath);
|
|
659
659
|
if (stat.isDirectory()) {
|
|
660
660
|
if (isRootLevel && excludedRootDirectories.includes(item)) {
|
|
@@ -689,7 +689,7 @@ var init_FileUtils = __esm({
|
|
|
689
689
|
isAllFilesScan
|
|
690
690
|
}) {
|
|
691
691
|
try {
|
|
692
|
-
const stats =
|
|
692
|
+
const stats = fs.statSync(dir);
|
|
693
693
|
if (!stats.isDirectory()) return [];
|
|
694
694
|
} catch {
|
|
695
695
|
return [];
|
|
@@ -720,7 +720,7 @@ var GitService_exports = {};
|
|
|
720
720
|
__export(GitService_exports, {
|
|
721
721
|
GitService: () => GitService
|
|
722
722
|
});
|
|
723
|
-
import
|
|
723
|
+
import fs2 from "fs";
|
|
724
724
|
import ignore from "ignore";
|
|
725
725
|
import * as path2 from "path";
|
|
726
726
|
import { simpleGit } from "simple-git";
|
|
@@ -1195,16 +1195,16 @@ var init_GitService = __esm({
|
|
|
1195
1195
|
try {
|
|
1196
1196
|
let combinedContent = "";
|
|
1197
1197
|
const localGitignorePath = path2.join(this.repositoryPath, ".gitignore");
|
|
1198
|
-
if (
|
|
1199
|
-
const localContent =
|
|
1198
|
+
if (fs2.existsSync(localGitignorePath)) {
|
|
1199
|
+
const localContent = fs2.readFileSync(localGitignorePath, "utf8");
|
|
1200
1200
|
combinedContent += `${localContent}
|
|
1201
1201
|
`;
|
|
1202
1202
|
}
|
|
1203
1203
|
try {
|
|
1204
1204
|
const gitRoot = await this.git.revparse(["--show-toplevel"]);
|
|
1205
1205
|
const rootGitignorePath = path2.join(gitRoot, ".gitignore");
|
|
1206
|
-
if (
|
|
1207
|
-
const rootContent =
|
|
1206
|
+
if (fs2.existsSync(rootGitignorePath)) {
|
|
1207
|
+
const rootContent = fs2.readFileSync(rootGitignorePath, "utf8");
|
|
1208
1208
|
if (rootContent.trim() !== combinedContent.trim()) {
|
|
1209
1209
|
combinedContent += `
|
|
1210
1210
|
${rootContent}`;
|
|
@@ -1265,8 +1265,8 @@ ${rootContent}`;
|
|
|
1265
1265
|
const gitRoot = await this.getGitRoot();
|
|
1266
1266
|
const gitignorePath = path2.join(gitRoot, ".gitignore");
|
|
1267
1267
|
let gitignoreContent = "";
|
|
1268
|
-
if (
|
|
1269
|
-
gitignoreContent =
|
|
1268
|
+
if (fs2.existsSync(gitignorePath)) {
|
|
1269
|
+
gitignoreContent = fs2.readFileSync(gitignorePath, "utf8");
|
|
1270
1270
|
this.log("[GitService] .gitignore file exists", "debug");
|
|
1271
1271
|
} else {
|
|
1272
1272
|
this.log("[GitService] Creating .gitignore file", "info", {
|
|
@@ -1283,7 +1283,7 @@ ${rootContent}`;
|
|
|
1283
1283
|
const newLine = gitignoreContent.endsWith("\n") || gitignoreContent === "" ? "" : "\n";
|
|
1284
1284
|
const updatedContent = `${gitignoreContent}${newLine}${entry}
|
|
1285
1285
|
`;
|
|
1286
|
-
|
|
1286
|
+
fs2.writeFileSync(gitignorePath, updatedContent, "utf8");
|
|
1287
1287
|
this.log("[GitService] .gitignore updated successfully", "debug", {
|
|
1288
1288
|
entry
|
|
1289
1289
|
});
|
|
@@ -1303,7 +1303,7 @@ ${rootContent}`;
|
|
|
1303
1303
|
try {
|
|
1304
1304
|
const gitRoot = await this.getGitRoot();
|
|
1305
1305
|
const gitignorePath = path2.join(gitRoot, ".gitignore");
|
|
1306
|
-
const exists =
|
|
1306
|
+
const exists = fs2.existsSync(gitignorePath);
|
|
1307
1307
|
this.log("[GitService] .gitignore existence check complete", "debug", {
|
|
1308
1308
|
exists
|
|
1309
1309
|
});
|
|
@@ -1322,247 +1322,19 @@ ${rootContent}`;
|
|
|
1322
1322
|
import Debug20 from "debug";
|
|
1323
1323
|
import { hideBin } from "yargs/helpers";
|
|
1324
1324
|
|
|
1325
|
+
// src/args/yargs.ts
|
|
1326
|
+
import chalk11 from "chalk";
|
|
1327
|
+
import yargs from "yargs/yargs";
|
|
1328
|
+
|
|
1325
1329
|
// src/args/commands/convert_to_sarif.ts
|
|
1326
1330
|
import fs7 from "fs";
|
|
1327
1331
|
|
|
1328
1332
|
// src/commands/convert_to_sarif.ts
|
|
1329
1333
|
import fs6 from "fs";
|
|
1330
1334
|
import path5 from "path";
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
import
|
|
1334
|
-
import readline from "readline";
|
|
1335
|
-
import sax from "sax";
|
|
1336
|
-
var BaseStreamParser = class {
|
|
1337
|
-
constructor(parser) {
|
|
1338
|
-
__publicField(this, "currentPath", []);
|
|
1339
|
-
parser.on("opentag", (tag) => this.onOpenTag(tag));
|
|
1340
|
-
parser.on("closetag", () => this.onCloseTag());
|
|
1341
|
-
parser.on("text", (text) => this.onText(text));
|
|
1342
|
-
}
|
|
1343
|
-
getPathString() {
|
|
1344
|
-
return this.currentPath.join(" > ");
|
|
1345
|
-
}
|
|
1346
|
-
onOpenTag(tag) {
|
|
1347
|
-
this.currentPath.push(tag.name);
|
|
1348
|
-
}
|
|
1349
|
-
onCloseTag() {
|
|
1350
|
-
this.currentPath.pop();
|
|
1351
|
-
}
|
|
1352
|
-
onText(_text) {
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
var AuditMetadataParser = class extends BaseStreamParser {
|
|
1356
|
-
constructor() {
|
|
1357
|
-
super(...arguments);
|
|
1358
|
-
__publicField(this, "suppressedMap", {});
|
|
1359
|
-
}
|
|
1360
|
-
onOpenTag(tag) {
|
|
1361
|
-
super.onOpenTag(tag);
|
|
1362
|
-
switch (this.getPathString()) {
|
|
1363
|
-
case "Audit > IssueList > Issue":
|
|
1364
|
-
this.suppressedMap[String(tag.attributes["instanceId"] ?? "")] = String(
|
|
1365
|
-
tag.attributes["suppressed"] ?? ""
|
|
1366
|
-
);
|
|
1367
|
-
break;
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
getAuditMetadata() {
|
|
1371
|
-
return this.suppressedMap;
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
var ReportMetadataParser = class extends BaseStreamParser {
|
|
1375
|
-
constructor() {
|
|
1376
|
-
super(...arguments);
|
|
1377
|
-
__publicField(this, "uuid", "");
|
|
1378
|
-
__publicField(this, "createdTSDate", "");
|
|
1379
|
-
__publicField(this, "createdTSTime", "");
|
|
1380
|
-
__publicField(this, "rules", {});
|
|
1381
|
-
__publicField(this, "ruleId", "");
|
|
1382
|
-
__publicField(this, "groupName", "");
|
|
1383
|
-
}
|
|
1384
|
-
onOpenTag(tag) {
|
|
1385
|
-
super.onOpenTag(tag);
|
|
1386
|
-
switch (this.getPathString()) {
|
|
1387
|
-
case "FVDL > EngineData > RuleInfo > Rule":
|
|
1388
|
-
this.ruleId = String(tag.attributes["id"] ?? "");
|
|
1389
|
-
break;
|
|
1390
|
-
case "FVDL > EngineData > RuleInfo > Rule > MetaInfo > Group":
|
|
1391
|
-
this.groupName = String(tag.attributes["name"] ?? "");
|
|
1392
|
-
break;
|
|
1393
|
-
case "FVDL > CreatedTS":
|
|
1394
|
-
this.createdTSDate = String(tag.attributes["date"] ?? "");
|
|
1395
|
-
this.createdTSTime = String(tag.attributes["time"] ?? "");
|
|
1396
|
-
break;
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
onText(text) {
|
|
1400
|
-
super.onText(text);
|
|
1401
|
-
switch (this.getPathString()) {
|
|
1402
|
-
case "FVDL > UUID":
|
|
1403
|
-
this.uuid = text;
|
|
1404
|
-
break;
|
|
1405
|
-
case "FVDL > EngineData > RuleInfo > Rule > MetaInfo > Group": {
|
|
1406
|
-
const ruleMeta = this.rules[this.ruleId] ?? {};
|
|
1407
|
-
ruleMeta[this.groupName] = text;
|
|
1408
|
-
this.rules[this.ruleId] = ruleMeta;
|
|
1409
|
-
break;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
getReportMetadata() {
|
|
1414
|
-
return {
|
|
1415
|
-
createdTSDate: this.createdTSDate,
|
|
1416
|
-
createdTSTime: this.createdTSTime,
|
|
1417
|
-
uuid: this.uuid,
|
|
1418
|
-
rules: this.rules
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
};
|
|
1422
|
-
var UnifiedNodePoolParser = class extends BaseStreamParser {
|
|
1423
|
-
constructor() {
|
|
1424
|
-
super(...arguments);
|
|
1425
|
-
__publicField(this, "codePoints", {});
|
|
1426
|
-
__publicField(this, "nodeId", "");
|
|
1427
|
-
}
|
|
1428
|
-
onOpenTag(tag) {
|
|
1429
|
-
super.onOpenTag(tag);
|
|
1430
|
-
switch (this.getPathString()) {
|
|
1431
|
-
case "FVDL > UnifiedNodePool > Node":
|
|
1432
|
-
this.nodeId = String(tag.attributes["id"] ?? "");
|
|
1433
|
-
break;
|
|
1434
|
-
case "FVDL > UnifiedNodePool > Node > SourceLocation":
|
|
1435
|
-
this.codePoints[this.nodeId] = {
|
|
1436
|
-
path: String(tag.attributes["path"] ?? ""),
|
|
1437
|
-
colStart: String(tag.attributes["colStart"] ?? ""),
|
|
1438
|
-
colEnd: String(tag.attributes["colEnd"] ?? ""),
|
|
1439
|
-
line: String(tag.attributes["line"] ?? ""),
|
|
1440
|
-
lineEnd: String(tag.attributes["lineEnd"] ?? "")
|
|
1441
|
-
};
|
|
1442
|
-
break;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
getNodesPull() {
|
|
1446
|
-
return this.codePoints;
|
|
1447
|
-
}
|
|
1448
|
-
};
|
|
1449
|
-
var VulnerabilityParser = class extends BaseStreamParser {
|
|
1450
|
-
constructor(parser, tmpStorageFilePath) {
|
|
1451
|
-
super(parser);
|
|
1452
|
-
__publicField(this, "isInVulnerability", false);
|
|
1453
|
-
__publicField(this, "codePoints", []);
|
|
1454
|
-
__publicField(this, "metadata", {});
|
|
1455
|
-
__publicField(this, "metaInfo", {});
|
|
1456
|
-
__publicField(this, "groupName", "");
|
|
1457
|
-
__publicField(this, "tmpStorageFileWriter");
|
|
1458
|
-
__publicField(this, "tmpStorageFilePath");
|
|
1459
|
-
this.tmpStorageFilePath = tmpStorageFilePath;
|
|
1460
|
-
this.tmpStorageFileWriter = fs.createWriteStream(tmpStorageFilePath);
|
|
1461
|
-
}
|
|
1462
|
-
onOpenTag(tag) {
|
|
1463
|
-
super.onOpenTag(tag);
|
|
1464
|
-
switch (this.getPathString()) {
|
|
1465
|
-
case "FVDL > Vulnerabilities > Vulnerability":
|
|
1466
|
-
this.isInVulnerability = true;
|
|
1467
|
-
this.metadata = {};
|
|
1468
|
-
this.metaInfo = {};
|
|
1469
|
-
this.codePoints = [];
|
|
1470
|
-
break;
|
|
1471
|
-
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > MetaInfo > Group":
|
|
1472
|
-
this.groupName = String(tag.attributes["name"] ?? "");
|
|
1473
|
-
break;
|
|
1474
|
-
}
|
|
1475
|
-
if (this.isInVulnerability) {
|
|
1476
|
-
if (this.getPathString().endsWith(" > Entry > Node > SourceLocation")) {
|
|
1477
|
-
this.codePoints.push({
|
|
1478
|
-
path: String(tag.attributes["path"] ?? ""),
|
|
1479
|
-
colStart: String(tag.attributes["colStart"] ?? ""),
|
|
1480
|
-
colEnd: String(tag.attributes["colEnd"] ?? ""),
|
|
1481
|
-
line: String(tag.attributes["line"] ?? ""),
|
|
1482
|
-
lineEnd: String(tag.attributes["lineEnd"] ?? "")
|
|
1483
|
-
});
|
|
1484
|
-
} else if (this.getPathString().endsWith(" > Entry > NodeRef")) {
|
|
1485
|
-
this.codePoints.push({
|
|
1486
|
-
id: String(tag.attributes["id"] ?? "")
|
|
1487
|
-
});
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
onText(text) {
|
|
1492
|
-
super.onText(text);
|
|
1493
|
-
const lastPathSegment = this.currentPath.at(-1);
|
|
1494
|
-
if (!this.isInVulnerability || !lastPathSegment) {
|
|
1495
|
-
return;
|
|
1496
|
-
}
|
|
1497
|
-
switch (this.getPathString()) {
|
|
1498
|
-
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > InstanceID":
|
|
1499
|
-
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > InstanceSeverity":
|
|
1500
|
-
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > Confidence":
|
|
1501
|
-
case "FVDL > Vulnerabilities > Vulnerability > ClassInfo > ClassID":
|
|
1502
|
-
case "FVDL > Vulnerabilities > Vulnerability > ClassInfo > Type":
|
|
1503
|
-
case "FVDL > Vulnerabilities > Vulnerability > ClassInfo > Subtype":
|
|
1504
|
-
this.metadata[lastPathSegment] = text;
|
|
1505
|
-
break;
|
|
1506
|
-
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > MetaInfo > Group":
|
|
1507
|
-
this.metaInfo[this.groupName] = text;
|
|
1508
|
-
break;
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
onCloseTag() {
|
|
1512
|
-
if (this.getPathString() === "FVDL > Vulnerabilities > Vulnerability") {
|
|
1513
|
-
this.isInVulnerability = false;
|
|
1514
|
-
this.tmpStorageFileWriter.write(
|
|
1515
|
-
JSON.stringify({
|
|
1516
|
-
nodes: this.codePoints,
|
|
1517
|
-
instanceID: this.metadata["InstanceID"] ?? "",
|
|
1518
|
-
instanceSeverity: this.metadata["InstanceSeverity"] ?? "",
|
|
1519
|
-
confidence: this.metadata["Confidence"] ?? "",
|
|
1520
|
-
classID: this.metadata["ClassID"] ?? "",
|
|
1521
|
-
type: this.metadata["Type"] ?? "",
|
|
1522
|
-
subtype: this.metadata["Subtype"] ?? "",
|
|
1523
|
-
metaInfo: this.metaInfo
|
|
1524
|
-
}) + "\n"
|
|
1525
|
-
);
|
|
1526
|
-
}
|
|
1527
|
-
super.onCloseTag();
|
|
1528
|
-
}
|
|
1529
|
-
async *getVulnerabilities() {
|
|
1530
|
-
await new Promise((r) => this.tmpStorageFileWriter.end(r));
|
|
1531
|
-
const rl = readline.createInterface({
|
|
1532
|
-
input: fs.createReadStream(this.tmpStorageFilePath),
|
|
1533
|
-
crlfDelay: Infinity
|
|
1534
|
-
});
|
|
1535
|
-
for await (const line of rl) {
|
|
1536
|
-
if (line) {
|
|
1537
|
-
yield JSON.parse(line);
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
};
|
|
1542
|
-
function initSaxParser(filepath) {
|
|
1543
|
-
const parser = sax.createStream(true, {
|
|
1544
|
-
// All these flags help to improve parsing speed a lot.
|
|
1545
|
-
trim: false,
|
|
1546
|
-
normalize: false,
|
|
1547
|
-
lowercase: false,
|
|
1548
|
-
xmlns: false,
|
|
1549
|
-
position: false
|
|
1550
|
-
});
|
|
1551
|
-
const awaiter = new Promise((resolve, reject) => {
|
|
1552
|
-
parser.on("end", () => resolve(true));
|
|
1553
|
-
parser.on("error", (e) => reject(e));
|
|
1554
|
-
});
|
|
1555
|
-
return {
|
|
1556
|
-
parser,
|
|
1557
|
-
parse: async () => {
|
|
1558
|
-
fs.createReadStream(filepath, {
|
|
1559
|
-
// Set chunk size to 100 MB. The default is 16 KB, which makes the process too slow.
|
|
1560
|
-
highWaterMark: 100 * 1024 * 1024
|
|
1561
|
-
}).pipe(parser);
|
|
1562
|
-
await awaiter;
|
|
1563
|
-
}
|
|
1564
|
-
};
|
|
1565
|
-
}
|
|
1335
|
+
import multimatch from "multimatch";
|
|
1336
|
+
import StreamZip from "node-stream-zip";
|
|
1337
|
+
import tmp from "tmp";
|
|
1566
1338
|
|
|
1567
1339
|
// src/features/analysis/scm/errors.ts
|
|
1568
1340
|
var InvalidRepoUrlError = class extends Error {
|
|
@@ -9441,142 +9213,394 @@ async function createScmLib({ url, accessToken, scmType, scmOrg }, { propagateEx
|
|
|
9441
9213
|
return scm;
|
|
9442
9214
|
}
|
|
9443
9215
|
}
|
|
9444
|
-
} catch (e) {
|
|
9445
|
-
if (e instanceof InvalidRepoUrlError && url) {
|
|
9446
|
-
throw new RepoNoTokenAccessError(
|
|
9447
|
-
"no access to repo",
|
|
9448
|
-
scmLibScmTypeToScmType[z23.nativeEnum(ScmLibScmType).parse(scmType)]
|
|
9449
|
-
);
|
|
9216
|
+
} catch (e) {
|
|
9217
|
+
if (e instanceof InvalidRepoUrlError && url) {
|
|
9218
|
+
throw new RepoNoTokenAccessError(
|
|
9219
|
+
"no access to repo",
|
|
9220
|
+
scmLibScmTypeToScmType[z23.nativeEnum(ScmLibScmType).parse(scmType)]
|
|
9221
|
+
);
|
|
9222
|
+
}
|
|
9223
|
+
console.error(`error validating scm: ${scmType} `, e);
|
|
9224
|
+
if (propagateExceptions) {
|
|
9225
|
+
throw e;
|
|
9226
|
+
}
|
|
9227
|
+
}
|
|
9228
|
+
return new StubSCMLib(trimmedUrl, void 0, void 0);
|
|
9229
|
+
}
|
|
9230
|
+
|
|
9231
|
+
// src/utils/index.ts
|
|
9232
|
+
var utils_exports = {};
|
|
9233
|
+
__export(utils_exports, {
|
|
9234
|
+
CliError: () => CliError,
|
|
9235
|
+
Spinner: () => Spinner,
|
|
9236
|
+
getDirName: () => getDirName,
|
|
9237
|
+
getModuleRootDir: () => getModuleRootDir,
|
|
9238
|
+
getTopLevelDirName: () => getTopLevelDirName,
|
|
9239
|
+
keypress: () => keypress,
|
|
9240
|
+
packageJson: () => packageJson,
|
|
9241
|
+
sleep: () => sleep
|
|
9242
|
+
});
|
|
9243
|
+
|
|
9244
|
+
// src/utils/dirname.ts
|
|
9245
|
+
import fs3 from "fs";
|
|
9246
|
+
import path3 from "path";
|
|
9247
|
+
import { fileURLToPath } from "url";
|
|
9248
|
+
function getModuleRootDir() {
|
|
9249
|
+
let manifestDir = getDirName();
|
|
9250
|
+
for (let i = 0; i < 10; i++) {
|
|
9251
|
+
const manifestPath = path3.join(manifestDir, "package.json");
|
|
9252
|
+
if (fs3.existsSync(manifestPath)) {
|
|
9253
|
+
return manifestDir;
|
|
9254
|
+
}
|
|
9255
|
+
manifestDir = path3.join(manifestDir, "..");
|
|
9256
|
+
}
|
|
9257
|
+
throw new Error("Cannot locate package.json file");
|
|
9258
|
+
}
|
|
9259
|
+
function getDirName() {
|
|
9260
|
+
if (typeof __filename !== "undefined") {
|
|
9261
|
+
return path3.dirname(__filename);
|
|
9262
|
+
} else {
|
|
9263
|
+
try {
|
|
9264
|
+
const getImportMetaUrl = new Function("return import.meta.url");
|
|
9265
|
+
const importMetaUrl = getImportMetaUrl();
|
|
9266
|
+
return path3.dirname(fileURLToPath(importMetaUrl));
|
|
9267
|
+
} catch (e) {
|
|
9268
|
+
try {
|
|
9269
|
+
const err = new Error();
|
|
9270
|
+
const stack = err.stack || "";
|
|
9271
|
+
const match = stack.match(/file:\/\/[^\s)]+/);
|
|
9272
|
+
if (match) {
|
|
9273
|
+
const fileUrl = match[0];
|
|
9274
|
+
return path3.dirname(fileURLToPath(fileUrl));
|
|
9275
|
+
}
|
|
9276
|
+
} catch {
|
|
9277
|
+
}
|
|
9278
|
+
throw new Error("Unable to determine directory name in this environment");
|
|
9279
|
+
}
|
|
9280
|
+
}
|
|
9281
|
+
}
|
|
9282
|
+
function getTopLevelDirName(fullPath) {
|
|
9283
|
+
return path3.parse(fullPath).name;
|
|
9284
|
+
}
|
|
9285
|
+
|
|
9286
|
+
// src/utils/keypress.ts
|
|
9287
|
+
import readline from "readline";
|
|
9288
|
+
async function keypress() {
|
|
9289
|
+
const rl = readline.createInterface({
|
|
9290
|
+
input: process.stdin,
|
|
9291
|
+
output: process.stdout
|
|
9292
|
+
});
|
|
9293
|
+
return new Promise((resolve) => {
|
|
9294
|
+
rl.question("", (answer) => {
|
|
9295
|
+
rl.close();
|
|
9296
|
+
process.stderr.moveCursor(0, -1);
|
|
9297
|
+
process.stderr.clearLine(1);
|
|
9298
|
+
resolve(answer);
|
|
9299
|
+
});
|
|
9300
|
+
});
|
|
9301
|
+
}
|
|
9302
|
+
|
|
9303
|
+
// src/utils/spinner.ts
|
|
9304
|
+
import {
|
|
9305
|
+
createSpinner as _createSpinner
|
|
9306
|
+
} from "nanospinner";
|
|
9307
|
+
function printToStdError(opts) {
|
|
9308
|
+
if (opts?.text) console.error(opts.text);
|
|
9309
|
+
}
|
|
9310
|
+
var mockSpinner = {
|
|
9311
|
+
success: (opts) => {
|
|
9312
|
+
printToStdError(opts);
|
|
9313
|
+
return mockSpinner;
|
|
9314
|
+
},
|
|
9315
|
+
error: (opts) => {
|
|
9316
|
+
printToStdError(opts);
|
|
9317
|
+
return mockSpinner;
|
|
9318
|
+
},
|
|
9319
|
+
warn: (opts) => {
|
|
9320
|
+
printToStdError(opts);
|
|
9321
|
+
return mockSpinner;
|
|
9322
|
+
},
|
|
9323
|
+
stop: (opts) => {
|
|
9324
|
+
printToStdError(opts);
|
|
9325
|
+
return mockSpinner;
|
|
9326
|
+
},
|
|
9327
|
+
start: (opts) => {
|
|
9328
|
+
printToStdError(opts);
|
|
9329
|
+
return mockSpinner;
|
|
9330
|
+
},
|
|
9331
|
+
update: (opts) => {
|
|
9332
|
+
printToStdError(opts);
|
|
9333
|
+
return mockSpinner;
|
|
9334
|
+
},
|
|
9335
|
+
reset: () => mockSpinner,
|
|
9336
|
+
clear: () => mockSpinner,
|
|
9337
|
+
spin: () => mockSpinner
|
|
9338
|
+
};
|
|
9339
|
+
function Spinner({ ci = false } = {}) {
|
|
9340
|
+
return {
|
|
9341
|
+
createSpinner: (text, options) => ci ? mockSpinner : _createSpinner(text, options)
|
|
9342
|
+
};
|
|
9343
|
+
}
|
|
9344
|
+
|
|
9345
|
+
// src/utils/check_node_version.ts
|
|
9346
|
+
import fs4 from "fs";
|
|
9347
|
+
import path4 from "path";
|
|
9348
|
+
import semver from "semver";
|
|
9349
|
+
function getPackageJson() {
|
|
9350
|
+
return JSON.parse(
|
|
9351
|
+
fs4.readFileSync(path4.join(getModuleRootDir(), "package.json"), "utf8")
|
|
9352
|
+
);
|
|
9353
|
+
}
|
|
9354
|
+
var packageJson = getPackageJson();
|
|
9355
|
+
if (!semver.satisfies(process.version, packageJson.engines.node)) {
|
|
9356
|
+
console.error(
|
|
9357
|
+
`
|
|
9358
|
+
\u26A0\uFE0F ${packageJson.name} requires node version ${packageJson.engines.node}, but running ${process.version}.`
|
|
9359
|
+
);
|
|
9360
|
+
process.exit(1);
|
|
9361
|
+
}
|
|
9362
|
+
|
|
9363
|
+
// src/utils/index.ts
|
|
9364
|
+
var sleep = (ms = 2e3) => new Promise((r) => setTimeout(r, ms));
|
|
9365
|
+
var CliError = class extends Error {
|
|
9366
|
+
};
|
|
9367
|
+
|
|
9368
|
+
// src/commands/fpr_stream_parser.ts
|
|
9369
|
+
import fs5 from "fs";
|
|
9370
|
+
import readline2 from "readline";
|
|
9371
|
+
import sax from "sax";
|
|
9372
|
+
var BaseStreamParser = class {
|
|
9373
|
+
constructor(parser) {
|
|
9374
|
+
__publicField(this, "currentPath", []);
|
|
9375
|
+
parser.on("opentag", (tag) => this.onOpenTag(tag));
|
|
9376
|
+
parser.on("closetag", () => this.onCloseTag());
|
|
9377
|
+
parser.on("text", (text) => this.onText(text));
|
|
9378
|
+
}
|
|
9379
|
+
getPathString() {
|
|
9380
|
+
return this.currentPath.join(" > ");
|
|
9381
|
+
}
|
|
9382
|
+
onOpenTag(tag) {
|
|
9383
|
+
this.currentPath.push(tag.name);
|
|
9384
|
+
}
|
|
9385
|
+
onCloseTag() {
|
|
9386
|
+
this.currentPath.pop();
|
|
9387
|
+
}
|
|
9388
|
+
onText(_text) {
|
|
9389
|
+
}
|
|
9390
|
+
};
|
|
9391
|
+
var AuditMetadataParser = class extends BaseStreamParser {
|
|
9392
|
+
constructor() {
|
|
9393
|
+
super(...arguments);
|
|
9394
|
+
__publicField(this, "suppressedMap", {});
|
|
9395
|
+
}
|
|
9396
|
+
onOpenTag(tag) {
|
|
9397
|
+
super.onOpenTag(tag);
|
|
9398
|
+
switch (this.getPathString()) {
|
|
9399
|
+
case "Audit > IssueList > Issue":
|
|
9400
|
+
this.suppressedMap[String(tag.attributes["instanceId"] ?? "")] = String(
|
|
9401
|
+
tag.attributes["suppressed"] ?? ""
|
|
9402
|
+
);
|
|
9403
|
+
break;
|
|
9404
|
+
}
|
|
9405
|
+
}
|
|
9406
|
+
getAuditMetadata() {
|
|
9407
|
+
return this.suppressedMap;
|
|
9408
|
+
}
|
|
9409
|
+
};
|
|
9410
|
+
var ReportMetadataParser = class extends BaseStreamParser {
|
|
9411
|
+
constructor() {
|
|
9412
|
+
super(...arguments);
|
|
9413
|
+
__publicField(this, "uuid", "");
|
|
9414
|
+
__publicField(this, "createdTSDate", "");
|
|
9415
|
+
__publicField(this, "createdTSTime", "");
|
|
9416
|
+
__publicField(this, "rules", {});
|
|
9417
|
+
__publicField(this, "ruleId", "");
|
|
9418
|
+
__publicField(this, "groupName", "");
|
|
9419
|
+
}
|
|
9420
|
+
onOpenTag(tag) {
|
|
9421
|
+
super.onOpenTag(tag);
|
|
9422
|
+
switch (this.getPathString()) {
|
|
9423
|
+
case "FVDL > EngineData > RuleInfo > Rule":
|
|
9424
|
+
this.ruleId = String(tag.attributes["id"] ?? "");
|
|
9425
|
+
break;
|
|
9426
|
+
case "FVDL > EngineData > RuleInfo > Rule > MetaInfo > Group":
|
|
9427
|
+
this.groupName = String(tag.attributes["name"] ?? "");
|
|
9428
|
+
break;
|
|
9429
|
+
case "FVDL > CreatedTS":
|
|
9430
|
+
this.createdTSDate = String(tag.attributes["date"] ?? "");
|
|
9431
|
+
this.createdTSTime = String(tag.attributes["time"] ?? "");
|
|
9432
|
+
break;
|
|
9433
|
+
}
|
|
9434
|
+
}
|
|
9435
|
+
onText(text) {
|
|
9436
|
+
super.onText(text);
|
|
9437
|
+
switch (this.getPathString()) {
|
|
9438
|
+
case "FVDL > UUID":
|
|
9439
|
+
this.uuid = text;
|
|
9440
|
+
break;
|
|
9441
|
+
case "FVDL > EngineData > RuleInfo > Rule > MetaInfo > Group": {
|
|
9442
|
+
const ruleMeta = this.rules[this.ruleId] ?? {};
|
|
9443
|
+
ruleMeta[this.groupName] = text;
|
|
9444
|
+
this.rules[this.ruleId] = ruleMeta;
|
|
9445
|
+
break;
|
|
9446
|
+
}
|
|
9447
|
+
}
|
|
9448
|
+
}
|
|
9449
|
+
getReportMetadata() {
|
|
9450
|
+
return {
|
|
9451
|
+
createdTSDate: this.createdTSDate,
|
|
9452
|
+
createdTSTime: this.createdTSTime,
|
|
9453
|
+
uuid: this.uuid,
|
|
9454
|
+
rules: this.rules
|
|
9455
|
+
};
|
|
9456
|
+
}
|
|
9457
|
+
};
|
|
9458
|
+
var UnifiedNodePoolParser = class extends BaseStreamParser {
|
|
9459
|
+
constructor() {
|
|
9460
|
+
super(...arguments);
|
|
9461
|
+
__publicField(this, "codePoints", {});
|
|
9462
|
+
__publicField(this, "nodeId", "");
|
|
9463
|
+
}
|
|
9464
|
+
onOpenTag(tag) {
|
|
9465
|
+
super.onOpenTag(tag);
|
|
9466
|
+
switch (this.getPathString()) {
|
|
9467
|
+
case "FVDL > UnifiedNodePool > Node":
|
|
9468
|
+
this.nodeId = String(tag.attributes["id"] ?? "");
|
|
9469
|
+
break;
|
|
9470
|
+
case "FVDL > UnifiedNodePool > Node > SourceLocation":
|
|
9471
|
+
this.codePoints[this.nodeId] = {
|
|
9472
|
+
path: String(tag.attributes["path"] ?? ""),
|
|
9473
|
+
colStart: String(tag.attributes["colStart"] ?? ""),
|
|
9474
|
+
colEnd: String(tag.attributes["colEnd"] ?? ""),
|
|
9475
|
+
line: String(tag.attributes["line"] ?? ""),
|
|
9476
|
+
lineEnd: String(tag.attributes["lineEnd"] ?? "")
|
|
9477
|
+
};
|
|
9478
|
+
break;
|
|
9479
|
+
}
|
|
9480
|
+
}
|
|
9481
|
+
getNodesPull() {
|
|
9482
|
+
return this.codePoints;
|
|
9483
|
+
}
|
|
9484
|
+
};
|
|
9485
|
+
var VulnerabilityParser = class extends BaseStreamParser {
|
|
9486
|
+
constructor(parser, tmpStorageFilePath) {
|
|
9487
|
+
super(parser);
|
|
9488
|
+
__publicField(this, "isInVulnerability", false);
|
|
9489
|
+
__publicField(this, "codePoints", []);
|
|
9490
|
+
__publicField(this, "metadata", {});
|
|
9491
|
+
__publicField(this, "metaInfo", {});
|
|
9492
|
+
__publicField(this, "groupName", "");
|
|
9493
|
+
__publicField(this, "tmpStorageFileWriter");
|
|
9494
|
+
__publicField(this, "tmpStorageFilePath");
|
|
9495
|
+
this.tmpStorageFilePath = tmpStorageFilePath;
|
|
9496
|
+
this.tmpStorageFileWriter = fs5.createWriteStream(tmpStorageFilePath);
|
|
9497
|
+
}
|
|
9498
|
+
onOpenTag(tag) {
|
|
9499
|
+
super.onOpenTag(tag);
|
|
9500
|
+
switch (this.getPathString()) {
|
|
9501
|
+
case "FVDL > Vulnerabilities > Vulnerability":
|
|
9502
|
+
this.isInVulnerability = true;
|
|
9503
|
+
this.metadata = {};
|
|
9504
|
+
this.metaInfo = {};
|
|
9505
|
+
this.codePoints = [];
|
|
9506
|
+
break;
|
|
9507
|
+
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > MetaInfo > Group":
|
|
9508
|
+
this.groupName = String(tag.attributes["name"] ?? "");
|
|
9509
|
+
break;
|
|
9510
|
+
}
|
|
9511
|
+
if (this.isInVulnerability) {
|
|
9512
|
+
if (this.getPathString().endsWith(" > Entry > Node > SourceLocation")) {
|
|
9513
|
+
this.codePoints.push({
|
|
9514
|
+
path: String(tag.attributes["path"] ?? ""),
|
|
9515
|
+
colStart: String(tag.attributes["colStart"] ?? ""),
|
|
9516
|
+
colEnd: String(tag.attributes["colEnd"] ?? ""),
|
|
9517
|
+
line: String(tag.attributes["line"] ?? ""),
|
|
9518
|
+
lineEnd: String(tag.attributes["lineEnd"] ?? "")
|
|
9519
|
+
});
|
|
9520
|
+
} else if (this.getPathString().endsWith(" > Entry > NodeRef")) {
|
|
9521
|
+
this.codePoints.push({
|
|
9522
|
+
id: String(tag.attributes["id"] ?? "")
|
|
9523
|
+
});
|
|
9524
|
+
}
|
|
9525
|
+
}
|
|
9526
|
+
}
|
|
9527
|
+
onText(text) {
|
|
9528
|
+
super.onText(text);
|
|
9529
|
+
const lastPathSegment = this.currentPath.at(-1);
|
|
9530
|
+
if (!this.isInVulnerability || !lastPathSegment) {
|
|
9531
|
+
return;
|
|
9450
9532
|
}
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9533
|
+
switch (this.getPathString()) {
|
|
9534
|
+
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > InstanceID":
|
|
9535
|
+
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > InstanceSeverity":
|
|
9536
|
+
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > Confidence":
|
|
9537
|
+
case "FVDL > Vulnerabilities > Vulnerability > ClassInfo > ClassID":
|
|
9538
|
+
case "FVDL > Vulnerabilities > Vulnerability > ClassInfo > Type":
|
|
9539
|
+
case "FVDL > Vulnerabilities > Vulnerability > ClassInfo > Subtype":
|
|
9540
|
+
this.metadata[lastPathSegment] = text;
|
|
9541
|
+
break;
|
|
9542
|
+
case "FVDL > Vulnerabilities > Vulnerability > InstanceInfo > MetaInfo > Group":
|
|
9543
|
+
this.metaInfo[this.groupName] = text;
|
|
9544
|
+
break;
|
|
9454
9545
|
}
|
|
9455
9546
|
}
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
// src/utils/dirname.ts
|
|
9473
|
-
import fs4 from "fs";
|
|
9474
|
-
import path3 from "path";
|
|
9475
|
-
import { fileURLToPath } from "url";
|
|
9476
|
-
function getModuleRootDir() {
|
|
9477
|
-
let manifestDir = getDirName();
|
|
9478
|
-
for (let i = 0; i < 10; i++) {
|
|
9479
|
-
const manifestPath = path3.join(manifestDir, "package.json");
|
|
9480
|
-
if (fs4.existsSync(manifestPath)) {
|
|
9481
|
-
return manifestDir;
|
|
9547
|
+
onCloseTag() {
|
|
9548
|
+
if (this.getPathString() === "FVDL > Vulnerabilities > Vulnerability") {
|
|
9549
|
+
this.isInVulnerability = false;
|
|
9550
|
+
this.tmpStorageFileWriter.write(
|
|
9551
|
+
JSON.stringify({
|
|
9552
|
+
nodes: this.codePoints,
|
|
9553
|
+
instanceID: this.metadata["InstanceID"] ?? "",
|
|
9554
|
+
instanceSeverity: this.metadata["InstanceSeverity"] ?? "",
|
|
9555
|
+
confidence: this.metadata["Confidence"] ?? "",
|
|
9556
|
+
classID: this.metadata["ClassID"] ?? "",
|
|
9557
|
+
type: this.metadata["Type"] ?? "",
|
|
9558
|
+
subtype: this.metadata["Subtype"] ?? "",
|
|
9559
|
+
metaInfo: this.metaInfo
|
|
9560
|
+
}) + "\n"
|
|
9561
|
+
);
|
|
9482
9562
|
}
|
|
9483
|
-
|
|
9563
|
+
super.onCloseTag();
|
|
9484
9564
|
}
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
function getTopLevelDirName(fullPath) {
|
|
9491
|
-
return path3.parse(fullPath).name;
|
|
9492
|
-
}
|
|
9493
|
-
|
|
9494
|
-
// src/utils/keypress.ts
|
|
9495
|
-
import readline2 from "readline";
|
|
9496
|
-
async function keypress() {
|
|
9497
|
-
const rl = readline2.createInterface({
|
|
9498
|
-
input: process.stdin,
|
|
9499
|
-
output: process.stdout
|
|
9500
|
-
});
|
|
9501
|
-
return new Promise((resolve) => {
|
|
9502
|
-
rl.question("", (answer) => {
|
|
9503
|
-
rl.close();
|
|
9504
|
-
process.stderr.moveCursor(0, -1);
|
|
9505
|
-
process.stderr.clearLine(1);
|
|
9506
|
-
resolve(answer);
|
|
9565
|
+
async *getVulnerabilities() {
|
|
9566
|
+
await new Promise((r) => this.tmpStorageFileWriter.end(r));
|
|
9567
|
+
const rl = readline2.createInterface({
|
|
9568
|
+
input: fs5.createReadStream(this.tmpStorageFilePath),
|
|
9569
|
+
crlfDelay: Infinity
|
|
9507
9570
|
});
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9514
|
-
} from "nanospinner";
|
|
9515
|
-
function printToStdError(opts) {
|
|
9516
|
-
if (opts?.text) console.error(opts.text);
|
|
9517
|
-
}
|
|
9518
|
-
var mockSpinner = {
|
|
9519
|
-
success: (opts) => {
|
|
9520
|
-
printToStdError(opts);
|
|
9521
|
-
return mockSpinner;
|
|
9522
|
-
},
|
|
9523
|
-
error: (opts) => {
|
|
9524
|
-
printToStdError(opts);
|
|
9525
|
-
return mockSpinner;
|
|
9526
|
-
},
|
|
9527
|
-
warn: (opts) => {
|
|
9528
|
-
printToStdError(opts);
|
|
9529
|
-
return mockSpinner;
|
|
9530
|
-
},
|
|
9531
|
-
stop: (opts) => {
|
|
9532
|
-
printToStdError(opts);
|
|
9533
|
-
return mockSpinner;
|
|
9534
|
-
},
|
|
9535
|
-
start: (opts) => {
|
|
9536
|
-
printToStdError(opts);
|
|
9537
|
-
return mockSpinner;
|
|
9538
|
-
},
|
|
9539
|
-
update: (opts) => {
|
|
9540
|
-
printToStdError(opts);
|
|
9541
|
-
return mockSpinner;
|
|
9542
|
-
},
|
|
9543
|
-
reset: () => mockSpinner,
|
|
9544
|
-
clear: () => mockSpinner,
|
|
9545
|
-
spin: () => mockSpinner
|
|
9571
|
+
for await (const line of rl) {
|
|
9572
|
+
if (line) {
|
|
9573
|
+
yield JSON.parse(line);
|
|
9574
|
+
}
|
|
9575
|
+
}
|
|
9576
|
+
}
|
|
9546
9577
|
};
|
|
9547
|
-
function
|
|
9578
|
+
function initSaxParser(filepath) {
|
|
9579
|
+
const parser = sax.createStream(true, {
|
|
9580
|
+
// All these flags help to improve parsing speed a lot.
|
|
9581
|
+
trim: false,
|
|
9582
|
+
normalize: false,
|
|
9583
|
+
lowercase: false,
|
|
9584
|
+
xmlns: false,
|
|
9585
|
+
position: false
|
|
9586
|
+
});
|
|
9587
|
+
const awaiter = new Promise((resolve, reject) => {
|
|
9588
|
+
parser.on("end", () => resolve(true));
|
|
9589
|
+
parser.on("error", (e) => reject(e));
|
|
9590
|
+
});
|
|
9548
9591
|
return {
|
|
9549
|
-
|
|
9592
|
+
parser,
|
|
9593
|
+
parse: async () => {
|
|
9594
|
+
fs5.createReadStream(filepath, {
|
|
9595
|
+
// Set chunk size to 100 MB. The default is 16 KB, which makes the process too slow.
|
|
9596
|
+
highWaterMark: 100 * 1024 * 1024
|
|
9597
|
+
}).pipe(parser);
|
|
9598
|
+
await awaiter;
|
|
9599
|
+
}
|
|
9550
9600
|
};
|
|
9551
9601
|
}
|
|
9552
9602
|
|
|
9553
|
-
// src/utils/check_node_version.ts
|
|
9554
|
-
import fs5 from "fs";
|
|
9555
|
-
import path4 from "path";
|
|
9556
|
-
import semver from "semver";
|
|
9557
|
-
function getPackageJson() {
|
|
9558
|
-
return JSON.parse(
|
|
9559
|
-
fs5.readFileSync(path4.join(getModuleRootDir(), "package.json"), "utf8")
|
|
9560
|
-
);
|
|
9561
|
-
}
|
|
9562
|
-
var packageJson = getPackageJson();
|
|
9563
|
-
if (!semver.satisfies(process.version, packageJson.engines.node)) {
|
|
9564
|
-
console.error(
|
|
9565
|
-
`
|
|
9566
|
-
\u26A0\uFE0F ${packageJson.name} requires node version ${packageJson.engines.node}, but running ${process.version}.`
|
|
9567
|
-
);
|
|
9568
|
-
process.exit(1);
|
|
9569
|
-
}
|
|
9570
|
-
|
|
9571
|
-
// src/utils/index.ts
|
|
9572
|
-
var sleep = (ms = 2e3) => new Promise((r) => setTimeout(r, ms));
|
|
9573
|
-
var CliError = class extends Error {
|
|
9574
|
-
};
|
|
9575
|
-
|
|
9576
9603
|
// src/commands/convert_to_sarif.ts
|
|
9577
|
-
import multimatch from "multimatch";
|
|
9578
|
-
import StreamZip from "node-stream-zip";
|
|
9579
|
-
import tmp from "tmp";
|
|
9580
9604
|
async function convertToSarif(options) {
|
|
9581
9605
|
switch (options.inputFileFormat) {
|
|
9582
9606
|
case "FortifyFPR" /* FortifyFPR */:
|
|
@@ -9984,16 +10008,18 @@ var ScanContext = {
|
|
|
9984
10008
|
BUGSY: "BUGSY"
|
|
9985
10009
|
};
|
|
9986
10010
|
|
|
9987
|
-
// src/args/yargs.ts
|
|
9988
|
-
import chalk11 from "chalk";
|
|
9989
|
-
import yargs from "yargs/yargs";
|
|
9990
|
-
|
|
9991
10011
|
// src/args/commands/analyze.ts
|
|
9992
10012
|
import fs10 from "fs";
|
|
10013
|
+
import chalk8 from "chalk";
|
|
9993
10014
|
|
|
9994
10015
|
// src/commands/index.ts
|
|
9995
10016
|
import crypto from "crypto";
|
|
9996
10017
|
import os from "os";
|
|
10018
|
+
import chalk6 from "chalk";
|
|
10019
|
+
import chalkAnimation from "chalk-animation";
|
|
10020
|
+
import Configstore2 from "configstore";
|
|
10021
|
+
import Debug19 from "debug";
|
|
10022
|
+
import open3 from "open";
|
|
9997
10023
|
|
|
9998
10024
|
// src/features/analysis/index.ts
|
|
9999
10025
|
import fs9 from "fs";
|
|
@@ -10764,7 +10790,11 @@ function createWSClient(options) {
|
|
|
10764
10790
|
);
|
|
10765
10791
|
const CustomWebSocket = class extends WebSocket {
|
|
10766
10792
|
constructor(address, protocols) {
|
|
10767
|
-
super(
|
|
10793
|
+
super(
|
|
10794
|
+
address,
|
|
10795
|
+
protocols,
|
|
10796
|
+
proxy ? { agent: proxy } : void 0
|
|
10797
|
+
);
|
|
10768
10798
|
}
|
|
10769
10799
|
};
|
|
10770
10800
|
return createClient({
|
|
@@ -11458,6 +11488,12 @@ async function snykArticlePrompt() {
|
|
|
11458
11488
|
|
|
11459
11489
|
// src/features/analysis/scanners/checkmarx.ts
|
|
11460
11490
|
import { createRequire } from "module";
|
|
11491
|
+
import chalk3 from "chalk";
|
|
11492
|
+
import Debug15 from "debug";
|
|
11493
|
+
import { existsSync } from "fs";
|
|
11494
|
+
import { createSpinner as createSpinner2 } from "nanospinner";
|
|
11495
|
+
import { type } from "os";
|
|
11496
|
+
import path8 from "path";
|
|
11461
11497
|
|
|
11462
11498
|
// src/post_install/constants.mjs
|
|
11463
11499
|
var cxOperatingSystemSupportMessage = `Your operating system does not support checkmarx.
|
|
@@ -11513,19 +11549,31 @@ function createChildProcess({ childProcess, name }, options) {
|
|
|
11513
11549
|
}
|
|
11514
11550
|
|
|
11515
11551
|
// src/features/analysis/scanners/checkmarx.ts
|
|
11516
|
-
import chalk3 from "chalk";
|
|
11517
|
-
import Debug15 from "debug";
|
|
11518
|
-
import { existsSync } from "fs";
|
|
11519
|
-
import { createSpinner as createSpinner2 } from "nanospinner";
|
|
11520
|
-
import { type } from "os";
|
|
11521
|
-
import path8 from "path";
|
|
11522
11552
|
var debug15 = Debug15("mobbdev:checkmarx");
|
|
11523
|
-
var
|
|
11553
|
+
var moduleUrl;
|
|
11554
|
+
if (typeof __filename !== "undefined") {
|
|
11555
|
+
moduleUrl = __filename;
|
|
11556
|
+
} else {
|
|
11557
|
+
try {
|
|
11558
|
+
const getImportMetaUrl = new Function("return import.meta.url");
|
|
11559
|
+
moduleUrl = getImportMetaUrl();
|
|
11560
|
+
} catch {
|
|
11561
|
+
const err = new Error();
|
|
11562
|
+
const stack = err.stack || "";
|
|
11563
|
+
const match = stack.match(/file:\/\/[^\s)]+/);
|
|
11564
|
+
if (match) {
|
|
11565
|
+
moduleUrl = match[0];
|
|
11566
|
+
} else {
|
|
11567
|
+
throw new Error("Unable to determine module URL in this environment");
|
|
11568
|
+
}
|
|
11569
|
+
}
|
|
11570
|
+
}
|
|
11571
|
+
var costumeRequire = createRequire(moduleUrl);
|
|
11524
11572
|
var getCheckmarxPath = () => {
|
|
11525
11573
|
const os6 = type();
|
|
11526
11574
|
const cxFileName = os6 === "Windows_NT" ? "cx.exe" : "cx";
|
|
11527
11575
|
try {
|
|
11528
|
-
return
|
|
11576
|
+
return costumeRequire.resolve(`.bin/${cxFileName}`);
|
|
11529
11577
|
} catch (e) {
|
|
11530
11578
|
throw new CliError(cxOperatingSystemSupportMessage);
|
|
11531
11579
|
}
|
|
@@ -11639,8 +11687,26 @@ import Debug16 from "debug";
|
|
|
11639
11687
|
import { createSpinner as createSpinner3 } from "nanospinner";
|
|
11640
11688
|
import open from "open";
|
|
11641
11689
|
var debug16 = Debug16("mobbdev:snyk");
|
|
11642
|
-
var
|
|
11643
|
-
|
|
11690
|
+
var moduleUrl2;
|
|
11691
|
+
if (typeof __filename !== "undefined") {
|
|
11692
|
+
moduleUrl2 = __filename;
|
|
11693
|
+
} else {
|
|
11694
|
+
try {
|
|
11695
|
+
const getImportMetaUrl = new Function("return import.meta.url");
|
|
11696
|
+
moduleUrl2 = getImportMetaUrl();
|
|
11697
|
+
} catch {
|
|
11698
|
+
const err = new Error();
|
|
11699
|
+
const stack = err.stack || "";
|
|
11700
|
+
const match = stack.match(/file:\/\/[^\s)]+/);
|
|
11701
|
+
if (match) {
|
|
11702
|
+
moduleUrl2 = match[0];
|
|
11703
|
+
} else {
|
|
11704
|
+
throw new Error("Unable to determine module URL in this environment");
|
|
11705
|
+
}
|
|
11706
|
+
}
|
|
11707
|
+
}
|
|
11708
|
+
var costumeRequire2 = createRequire2(moduleUrl2);
|
|
11709
|
+
var SNYK_PATH = costumeRequire2.resolve("snyk/bin/snyk");
|
|
11644
11710
|
var SNYK_ARTICLE_URL = "https://docs.snyk.io/scan-using-snyk/snyk-code/configure-snyk-code#enable-snyk-code";
|
|
11645
11711
|
debug16("snyk executable path %s", SNYK_PATH);
|
|
11646
11712
|
async function forkSnyk(args, { display }) {
|
|
@@ -12404,11 +12470,6 @@ async function waitForAnaysisAndReviewPr({
|
|
|
12404
12470
|
}
|
|
12405
12471
|
|
|
12406
12472
|
// src/commands/index.ts
|
|
12407
|
-
import chalk6 from "chalk";
|
|
12408
|
-
import chalkAnimation from "chalk-animation";
|
|
12409
|
-
import Configstore2 from "configstore";
|
|
12410
|
-
import Debug19 from "debug";
|
|
12411
|
-
import open3 from "open";
|
|
12412
12473
|
var debug19 = Debug19("mobbdev:commands");
|
|
12413
12474
|
async function review(params, { skipPrompts = true } = {}) {
|
|
12414
12475
|
const {
|
|
@@ -12630,9 +12691,6 @@ async function handleMobbLogin({
|
|
|
12630
12691
|
return newGqlClient;
|
|
12631
12692
|
}
|
|
12632
12693
|
|
|
12633
|
-
// src/args/commands/analyze.ts
|
|
12634
|
-
import chalk8 from "chalk";
|
|
12635
|
-
|
|
12636
12694
|
// src/args/validation.ts
|
|
12637
12695
|
import chalk7 from "chalk";
|
|
12638
12696
|
import path10 from "path";
|
|
@@ -13057,8 +13115,8 @@ var GetLatestReportByRepoUrlResponseSchema = z31.object({
|
|
|
13057
13115
|
});
|
|
13058
13116
|
|
|
13059
13117
|
// src/mcp/services/ConfigStoreService.ts
|
|
13060
|
-
init_configs();
|
|
13061
13118
|
import Configstore4 from "configstore";
|
|
13119
|
+
init_configs();
|
|
13062
13120
|
function createConfigStore(defaultValues = { apiToken: "" }) {
|
|
13063
13121
|
const API_URL2 = process.env["API_URL"] || MCP_DEFAULT_API_URL;
|
|
13064
13122
|
let domain = "";
|
|
@@ -13082,8 +13140,8 @@ var configStore = getConfigStore();
|
|
|
13082
13140
|
// src/mcp/services/McpAuthService.ts
|
|
13083
13141
|
import crypto2 from "crypto";
|
|
13084
13142
|
import os2 from "os";
|
|
13085
|
-
init_configs();
|
|
13086
13143
|
import open4 from "open";
|
|
13144
|
+
init_configs();
|
|
13087
13145
|
var McpAuthService = class {
|
|
13088
13146
|
constructor(client) {
|
|
13089
13147
|
__publicField(this, "client");
|
|
@@ -14146,10 +14204,10 @@ var getHostInfo = (additionalMcpList) => {
|
|
|
14146
14204
|
};
|
|
14147
14205
|
|
|
14148
14206
|
// src/mcp/services/McpUsageService/McpUsageService.ts
|
|
14149
|
-
init_configs();
|
|
14150
14207
|
import fetch5 from "node-fetch";
|
|
14151
14208
|
import os5 from "os";
|
|
14152
14209
|
import { v4 as uuidv43, v5 as uuidv5 } from "uuid";
|
|
14210
|
+
init_configs();
|
|
14153
14211
|
|
|
14154
14212
|
// src/mcp/services/McpUsageService/system.ts
|
|
14155
14213
|
init_configs();
|
|
@@ -18697,8 +18755,8 @@ var McpCheckerTool = class extends BaseTool {
|
|
|
18697
18755
|
};
|
|
18698
18756
|
|
|
18699
18757
|
// src/mcp/tools/scanAndFixVulnerabilities/ScanAndFixVulnerabilitiesTool.ts
|
|
18700
|
-
init_configs();
|
|
18701
18758
|
import z37 from "zod";
|
|
18759
|
+
init_configs();
|
|
18702
18760
|
|
|
18703
18761
|
// src/mcp/tools/scanAndFixVulnerabilities/ScanAndFixVulnerabilitiesService.ts
|
|
18704
18762
|
init_configs();
|
|
@@ -19168,9 +19226,34 @@ async function addScmTokenHandler(args) {
|
|
|
19168
19226
|
}
|
|
19169
19227
|
|
|
19170
19228
|
// src/args/commands/upload_ai_blame.ts
|
|
19171
|
-
import
|
|
19229
|
+
import fsPromises3 from "fs/promises";
|
|
19172
19230
|
import path16 from "path";
|
|
19173
19231
|
import chalk10 from "chalk";
|
|
19232
|
+
import { withFile } from "tmp-promise";
|
|
19233
|
+
import z38 from "zod";
|
|
19234
|
+
var PromptItemZ = z38.object({
|
|
19235
|
+
type: z38.enum(["USER_PROMPT", "AI_RESPONSE", "TOOL_EXECUTION"]),
|
|
19236
|
+
attachedFiles: z38.array(
|
|
19237
|
+
z38.object({
|
|
19238
|
+
relativePath: z38.string(),
|
|
19239
|
+
startLine: z38.number().optional()
|
|
19240
|
+
})
|
|
19241
|
+
).optional(),
|
|
19242
|
+
tokens: z38.object({
|
|
19243
|
+
inputCount: z38.number(),
|
|
19244
|
+
outputCount: z38.number()
|
|
19245
|
+
}).optional(),
|
|
19246
|
+
text: z38.string().optional(),
|
|
19247
|
+
date: z38.date().optional(),
|
|
19248
|
+
tool: z38.object({
|
|
19249
|
+
name: z38.string(),
|
|
19250
|
+
parameters: z38.string(),
|
|
19251
|
+
result: z38.string(),
|
|
19252
|
+
rawArguments: z38.string().optional(),
|
|
19253
|
+
accepted: z38.boolean().optional()
|
|
19254
|
+
}).optional()
|
|
19255
|
+
});
|
|
19256
|
+
var PromptItemArrayZ = z38.array(PromptItemZ);
|
|
19174
19257
|
function uploadAiBlameBuilder(args) {
|
|
19175
19258
|
return args.option("prompt", {
|
|
19176
19259
|
type: "string",
|
|
@@ -19200,17 +19283,19 @@ function uploadAiBlameBuilder(args) {
|
|
|
19200
19283
|
describe: chalk10.bold("Tool/IDE name(s) (optional, one per session)")
|
|
19201
19284
|
}).strict();
|
|
19202
19285
|
}
|
|
19203
|
-
async function uploadAiBlameHandler(args) {
|
|
19286
|
+
async function uploadAiBlameHandler(args, exitOnError = true) {
|
|
19204
19287
|
const prompts = args.prompt || [];
|
|
19205
19288
|
const inferences = args.inference || [];
|
|
19206
19289
|
const models = args.model || [];
|
|
19207
19290
|
const tools = args.toolName || args["tool-name"] || [];
|
|
19208
19291
|
const responseTimes = args.aiResponseAt || args["ai-response-at"] || [];
|
|
19209
19292
|
if (prompts.length !== inferences.length) {
|
|
19210
|
-
|
|
19211
|
-
|
|
19212
|
-
)
|
|
19213
|
-
|
|
19293
|
+
const errorMsg = "prompt and inference must have the same number of entries";
|
|
19294
|
+
console.error(chalk10.red(errorMsg));
|
|
19295
|
+
if (exitOnError) {
|
|
19296
|
+
process.exit(1);
|
|
19297
|
+
}
|
|
19298
|
+
throw new Error(errorMsg);
|
|
19214
19299
|
}
|
|
19215
19300
|
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
19216
19301
|
const sessions = [];
|
|
@@ -19218,10 +19303,17 @@ async function uploadAiBlameHandler(args) {
|
|
|
19218
19303
|
const promptPath = String(prompts[i]);
|
|
19219
19304
|
const inferencePath = String(inferences[i]);
|
|
19220
19305
|
try {
|
|
19221
|
-
await Promise.all([
|
|
19306
|
+
await Promise.all([
|
|
19307
|
+
fsPromises3.access(promptPath),
|
|
19308
|
+
fsPromises3.access(inferencePath)
|
|
19309
|
+
]);
|
|
19222
19310
|
} catch {
|
|
19223
|
-
|
|
19224
|
-
|
|
19311
|
+
const errorMsg = `File not found for session ${i + 1}`;
|
|
19312
|
+
console.error(chalk10.red(errorMsg));
|
|
19313
|
+
if (exitOnError) {
|
|
19314
|
+
process.exit(1);
|
|
19315
|
+
}
|
|
19316
|
+
throw new Error(errorMsg);
|
|
19225
19317
|
}
|
|
19226
19318
|
sessions.push({
|
|
19227
19319
|
promptFileName: path16.basename(promptPath),
|
|
@@ -19235,10 +19327,12 @@ async function uploadAiBlameHandler(args) {
|
|
|
19235
19327
|
const initRes = await gqlClient.uploadAIBlameInferencesInitRaw({ sessions });
|
|
19236
19328
|
const uploadSessions = initRes.uploadAIBlameInferencesInit?.uploadSessions ?? [];
|
|
19237
19329
|
if (uploadSessions.length !== sessions.length) {
|
|
19238
|
-
|
|
19239
|
-
|
|
19240
|
-
)
|
|
19241
|
-
|
|
19330
|
+
const errorMsg = "Init failed to return expected number of sessions";
|
|
19331
|
+
console.error(chalk10.red(errorMsg));
|
|
19332
|
+
if (exitOnError) {
|
|
19333
|
+
process.exit(1);
|
|
19334
|
+
}
|
|
19335
|
+
throw new Error(errorMsg);
|
|
19242
19336
|
}
|
|
19243
19337
|
for (let i = 0; i < uploadSessions.length; i++) {
|
|
19244
19338
|
const us = uploadSessions[i];
|
|
@@ -19273,12 +19367,12 @@ async function uploadAiBlameHandler(args) {
|
|
|
19273
19367
|
});
|
|
19274
19368
|
const status = finRes?.finalizeAIBlameInferencesUpload?.status;
|
|
19275
19369
|
if (status !== "OK") {
|
|
19276
|
-
|
|
19277
|
-
|
|
19278
|
-
|
|
19279
|
-
)
|
|
19280
|
-
|
|
19281
|
-
|
|
19370
|
+
const errorMsg = finRes?.finalizeAIBlameInferencesUpload?.error || "unknown error";
|
|
19371
|
+
console.error(chalk10.red(errorMsg));
|
|
19372
|
+
if (exitOnError) {
|
|
19373
|
+
process.exit(1);
|
|
19374
|
+
}
|
|
19375
|
+
throw new Error(errorMsg);
|
|
19282
19376
|
}
|
|
19283
19377
|
console.log(chalk10.green("AI Blame uploads finalized successfully"));
|
|
19284
19378
|
}
|