mobbdev 1.0.51 → 1.0.58
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/index.mjs +233 -269
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import chalk10 from "chalk";
|
|
|
25
25
|
import yargs from "yargs/yargs";
|
|
26
26
|
|
|
27
27
|
// src/args/commands/analyze.ts
|
|
28
|
-
import
|
|
28
|
+
import fs4 from "node:fs";
|
|
29
29
|
|
|
30
30
|
// src/commands/index.ts
|
|
31
31
|
import crypto from "node:crypto";
|
|
@@ -123,6 +123,7 @@ var IssueType_Enum = /* @__PURE__ */ ((IssueType_Enum2) => {
|
|
|
123
123
|
IssueType_Enum2["DefaultRightsInObjDefinition"] = "DEFAULT_RIGHTS_IN_OBJ_DEFINITION";
|
|
124
124
|
IssueType_Enum2["DeprecatedFunction"] = "DEPRECATED_FUNCTION";
|
|
125
125
|
IssueType_Enum2["DosStringBuilder"] = "DOS_STRING_BUILDER";
|
|
126
|
+
IssueType_Enum2["DuplicatedStrings"] = "DUPLICATED_STRINGS";
|
|
126
127
|
IssueType_Enum2["ErroneousStringCompare"] = "ERRONEOUS_STRING_COMPARE";
|
|
127
128
|
IssueType_Enum2["ErrorCondtionWithoutAction"] = "ERROR_CONDTION_WITHOUT_ACTION";
|
|
128
129
|
IssueType_Enum2["FrameableLoginPage"] = "FRAMEABLE_LOGIN_PAGE";
|
|
@@ -191,6 +192,7 @@ var IssueType_Enum = /* @__PURE__ */ ((IssueType_Enum2) => {
|
|
|
191
192
|
IssueType_Enum2["WcfMisconfigurationThrottlingNotEnabled"] = "WCF_MISCONFIGURATION_THROTTLING_NOT_ENABLED";
|
|
192
193
|
IssueType_Enum2["WeakEncryption"] = "WEAK_ENCRYPTION";
|
|
193
194
|
IssueType_Enum2["WeakXmlSchemaUnboundedOccurrences"] = "WEAK_XML_SCHEMA_UNBOUNDED_OCCURRENCES";
|
|
195
|
+
IssueType_Enum2["WebsocketMissingOriginCheck"] = "WEBSOCKET_MISSING_ORIGIN_CHECK";
|
|
194
196
|
IssueType_Enum2["Xss"] = "XSS";
|
|
195
197
|
IssueType_Enum2["Xxe"] = "XXE";
|
|
196
198
|
IssueType_Enum2["ZipSlip"] = "ZIP_SLIP";
|
|
@@ -896,6 +898,7 @@ var FixPageFixReportZ = z3.object({
|
|
|
896
898
|
});
|
|
897
899
|
|
|
898
900
|
// src/features/analysis/scm/shared/src/types/issue.ts
|
|
901
|
+
var MAX_SOURCE_CODE_FILE_SIZE_IN_BYTES = 1e5;
|
|
899
902
|
var category = {
|
|
900
903
|
NoFix: "NoFix",
|
|
901
904
|
Unsupported: "Unsupported",
|
|
@@ -917,6 +920,10 @@ var BaseIssuePartsZ = z4.object({
|
|
|
917
920
|
createdAt: z4.string(),
|
|
918
921
|
parsedSeverity: ParsedSeverityZ,
|
|
919
922
|
category: ValidCategoriesZ,
|
|
923
|
+
extraData: z4.object({
|
|
924
|
+
missing_files: z4.string().array().nullish(),
|
|
925
|
+
error_files: z4.string().array().nullish()
|
|
926
|
+
}),
|
|
920
927
|
vulnerabilityReportIssueTags: z4.array(
|
|
921
928
|
z4.object({
|
|
922
929
|
tag: z4.nativeEnum(Vulnerability_Report_Issue_Tag_Enum)
|
|
@@ -929,7 +936,35 @@ var BaseIssuePartsZ = z4.object({
|
|
|
929
936
|
index: z4.number()
|
|
930
937
|
})
|
|
931
938
|
).transform((nodes) => nodes.sort((a, b) => b.index - a.index)),
|
|
932
|
-
|
|
939
|
+
sourceCodeNodes: z4.array(
|
|
940
|
+
z4.object({
|
|
941
|
+
sourceCodeFile: z4.object({
|
|
942
|
+
path: z4.string(),
|
|
943
|
+
signedFile: z4.object({
|
|
944
|
+
url: z4.string()
|
|
945
|
+
})
|
|
946
|
+
})
|
|
947
|
+
}).transform(async ({ sourceCodeFile }) => {
|
|
948
|
+
const { url } = sourceCodeFile.signedFile;
|
|
949
|
+
const sourceCodeRes = await fetch(url);
|
|
950
|
+
if (Number(sourceCodeRes.headers.get("Content-Length")) > MAX_SOURCE_CODE_FILE_SIZE_IN_BYTES) {
|
|
951
|
+
return null;
|
|
952
|
+
}
|
|
953
|
+
return {
|
|
954
|
+
path: sourceCodeFile.path,
|
|
955
|
+
fileContent: await sourceCodeRes.text()
|
|
956
|
+
};
|
|
957
|
+
})
|
|
958
|
+
).transform((nodes) => nodes.filter((node) => node !== null)),
|
|
959
|
+
fix: FixPartsForFixScreenZ.nullish(),
|
|
960
|
+
vulnerabilityReportIssueNodeDiffFile: z4.object({
|
|
961
|
+
signedFile: z4.object({
|
|
962
|
+
url: z4.string()
|
|
963
|
+
}).transform(async ({ url }) => {
|
|
964
|
+
const codeDiff = await fetch(url).then((res) => res.text());
|
|
965
|
+
return { codeDiff };
|
|
966
|
+
})
|
|
967
|
+
}).nullish()
|
|
933
968
|
});
|
|
934
969
|
var FalsePositivePartsZ = z4.object({
|
|
935
970
|
extraContext: z4.array(z4.object({ key: z4.string(), value: z4.string() })),
|
|
@@ -1071,7 +1106,9 @@ var issueTypeMap = {
|
|
|
1071
1106
|
["REGEX_MISSING_TIMEOUT" /* RegexMissingTimeout */]: "Regex Missing Timeout",
|
|
1072
1107
|
["FRAMEABLE_LOGIN_PAGE" /* FrameableLoginPage */]: "Frameable Login Page",
|
|
1073
1108
|
["USE_OF_HARD_CODED_CRYPTOGRAPHIC_KEY" /* UseOfHardCodedCryptographicKey */]: "Use of Hardcoded Cryptographic Key",
|
|
1074
|
-
["MISSING_SSL_MINVERSION" /* MissingSslMinversion */]: "Missing SSL MinVersion"
|
|
1109
|
+
["MISSING_SSL_MINVERSION" /* MissingSslMinversion */]: "Missing SSL MinVersion",
|
|
1110
|
+
["WEBSOCKET_MISSING_ORIGIN_CHECK" /* WebsocketMissingOriginCheck */]: "Missing Websocket Origin Check",
|
|
1111
|
+
["DUPLICATED_STRINGS" /* DuplicatedStrings */]: "String Literals Should not Be Duplicated"
|
|
1075
1112
|
};
|
|
1076
1113
|
var issueTypeZ = z5.nativeEnum(IssueType_Enum);
|
|
1077
1114
|
var getIssueTypeFriendlyString = (issueType) => {
|
|
@@ -1574,9 +1611,9 @@ var progressMassages = {
|
|
|
1574
1611
|
var VUL_REPORT_DIGEST_TIMEOUT_MS = 1e3 * 60 * 30;
|
|
1575
1612
|
|
|
1576
1613
|
// src/features/analysis/index.ts
|
|
1577
|
-
import
|
|
1614
|
+
import fs3 from "node:fs";
|
|
1578
1615
|
import fsPromises from "node:fs/promises";
|
|
1579
|
-
import
|
|
1616
|
+
import path6 from "node:path";
|
|
1580
1617
|
import { env as env2 } from "node:process";
|
|
1581
1618
|
import { pipeline } from "node:stream/promises";
|
|
1582
1619
|
|
|
@@ -1690,8 +1727,8 @@ import extract from "extract-zip";
|
|
|
1690
1727
|
import { createSpinner as createSpinner4 } from "nanospinner";
|
|
1691
1728
|
import fetch4 from "node-fetch";
|
|
1692
1729
|
import open2 from "open";
|
|
1693
|
-
import
|
|
1694
|
-
import { z as
|
|
1730
|
+
import tmp from "tmp";
|
|
1731
|
+
import { z as z29 } from "zod";
|
|
1695
1732
|
|
|
1696
1733
|
// src/features/analysis/add_fix_comments_for_pr/add_fix_comments_for_pr.ts
|
|
1697
1734
|
import Debug8 from "debug";
|
|
@@ -1975,7 +2012,9 @@ var fixDetailsData = {
|
|
|
1975
2012
|
["REGEX_MISSING_TIMEOUT" /* RegexMissingTimeout */]: void 0,
|
|
1976
2013
|
["FRAMEABLE_LOGIN_PAGE" /* FrameableLoginPage */]: void 0,
|
|
1977
2014
|
["USE_OF_HARD_CODED_CRYPTOGRAPHIC_KEY" /* UseOfHardCodedCryptographicKey */]: void 0,
|
|
1978
|
-
["MISSING_SSL_MINVERSION" /* MissingSslMinversion */]: void 0
|
|
2015
|
+
["MISSING_SSL_MINVERSION" /* MissingSslMinversion */]: void 0,
|
|
2016
|
+
["WEBSOCKET_MISSING_ORIGIN_CHECK" /* WebsocketMissingOriginCheck */]: void 0,
|
|
2017
|
+
["DUPLICATED_STRINGS" /* DuplicatedStrings */]: void 0
|
|
1979
2018
|
};
|
|
1980
2019
|
|
|
1981
2020
|
// src/features/analysis/scm/shared/src/commitDescriptionMarkup.ts
|
|
@@ -2546,10 +2585,20 @@ var missingSslMinversion = {
|
|
|
2546
2585
|
}
|
|
2547
2586
|
};
|
|
2548
2587
|
|
|
2588
|
+
// src/features/analysis/scm/shared/src/storedQuestionData/go/websocketMissingOriginCheck.ts
|
|
2589
|
+
var websocketMissingOriginCheck = {
|
|
2590
|
+
minTlsVersion: {
|
|
2591
|
+
content: () => "Please provide a comma-separated list of valid hosts. This list will serve as an allow list to check the connection `Origin` header.",
|
|
2592
|
+
description: () => "",
|
|
2593
|
+
guidance: () => ""
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
2596
|
+
|
|
2549
2597
|
// src/features/analysis/scm/shared/src/storedQuestionData/go/index.ts
|
|
2550
2598
|
var vulnerabilities10 = {
|
|
2551
2599
|
["LOG_FORGING" /* LogForging */]: logForging2,
|
|
2552
|
-
["MISSING_SSL_MINVERSION" /* MissingSslMinversion */]: missingSslMinversion
|
|
2600
|
+
["MISSING_SSL_MINVERSION" /* MissingSslMinversion */]: missingSslMinversion,
|
|
2601
|
+
["WEBSOCKET_MISSING_ORIGIN_CHECK" /* WebsocketMissingOriginCheck */]: websocketMissingOriginCheck
|
|
2553
2602
|
};
|
|
2554
2603
|
var go_default2 = vulnerabilities10;
|
|
2555
2604
|
|
|
@@ -2613,6 +2662,15 @@ var confusingNaming = {
|
|
|
2613
2662
|
}
|
|
2614
2663
|
};
|
|
2615
2664
|
|
|
2665
|
+
// src/features/analysis/scm/shared/src/storedQuestionData/java/duplicatedStrings.ts
|
|
2666
|
+
var duplicatedStrings = {
|
|
2667
|
+
constantName: {
|
|
2668
|
+
content: () => "New constant name",
|
|
2669
|
+
description: () => "",
|
|
2670
|
+
guidance: () => ""
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
|
|
2616
2674
|
// src/features/analysis/scm/shared/src/storedQuestionData/java/erroneousStringCompare.ts
|
|
2617
2675
|
var erroneousStringCompare = {
|
|
2618
2676
|
javaVersionGreaterOrEqual17: {
|
|
@@ -3009,7 +3067,8 @@ var vulnerabilities11 = {
|
|
|
3009
3067
|
["INSECURE_COOKIE" /* InsecureCookie */]: insecureCookie2,
|
|
3010
3068
|
["TRUST_BOUNDARY_VIOLATION" /* TrustBoundaryViolation */]: trustBoundaryViolation2,
|
|
3011
3069
|
["LEFTOVER_DEBUG_CODE" /* LeftoverDebugCode */]: leftoverDebugCode,
|
|
3012
|
-
["ERRONEOUS_STRING_COMPARE" /* ErroneousStringCompare */]: erroneousStringCompare
|
|
3070
|
+
["ERRONEOUS_STRING_COMPARE" /* ErroneousStringCompare */]: erroneousStringCompare,
|
|
3071
|
+
["DUPLICATED_STRINGS" /* DuplicatedStrings */]: duplicatedStrings
|
|
3013
3072
|
};
|
|
3014
3073
|
var java_default2 = vulnerabilities11;
|
|
3015
3074
|
|
|
@@ -3826,17 +3885,9 @@ import { z as z15 } from "zod";
|
|
|
3826
3885
|
var EnvVariablesZod = z15.object({
|
|
3827
3886
|
GITLAB_API_TOKEN: z15.string().optional(),
|
|
3828
3887
|
GITHUB_API_TOKEN: z15.string().optional(),
|
|
3829
|
-
GIT_COMMITTER_EMAIL: z15.string().optional(),
|
|
3830
|
-
GIT_COMMITTER_NAME: z15.string().optional(),
|
|
3831
3888
|
GIT_PROXY_HOST: z15.string()
|
|
3832
3889
|
});
|
|
3833
|
-
var {
|
|
3834
|
-
GITLAB_API_TOKEN,
|
|
3835
|
-
GITHUB_API_TOKEN,
|
|
3836
|
-
GIT_PROXY_HOST,
|
|
3837
|
-
GIT_COMMITTER_EMAIL,
|
|
3838
|
-
GIT_COMMITTER_NAME
|
|
3839
|
-
} = EnvVariablesZod.parse(process.env);
|
|
3890
|
+
var { GITLAB_API_TOKEN, GITHUB_API_TOKEN, GIT_PROXY_HOST } = EnvVariablesZod.parse(process.env);
|
|
3840
3891
|
|
|
3841
3892
|
// src/features/analysis/scm/utils/index.ts
|
|
3842
3893
|
import { z as z16 } from "zod";
|
|
@@ -4387,7 +4438,7 @@ async function getAdoSdk(params) {
|
|
|
4387
4438
|
const url = new URL(repoUrl);
|
|
4388
4439
|
const origin2 = url.origin.toLowerCase().endsWith(".visualstudio.com") ? DEFUALT_ADO_ORIGIN : url.origin.toLowerCase();
|
|
4389
4440
|
const params2 = `path=/&versionDescriptor[versionOptions]=0&versionDescriptor[versionType]=commit&versionDescriptor[version]=${branch}&resolveLfs=true&$format=zip&api-version=5.0&download=true`;
|
|
4390
|
-
const
|
|
4441
|
+
const path8 = [
|
|
4391
4442
|
prefixPath,
|
|
4392
4443
|
owner,
|
|
4393
4444
|
projectName,
|
|
@@ -4398,7 +4449,7 @@ async function getAdoSdk(params) {
|
|
|
4398
4449
|
"items",
|
|
4399
4450
|
"items"
|
|
4400
4451
|
].filter(Boolean).join("/");
|
|
4401
|
-
return new URL(`${
|
|
4452
|
+
return new URL(`${path8}?${params2}`, origin2).toString();
|
|
4402
4453
|
},
|
|
4403
4454
|
async getAdoBranchList({ repoUrl }) {
|
|
4404
4455
|
try {
|
|
@@ -4622,112 +4673,7 @@ async function getAdoRepoList({
|
|
|
4622
4673
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
4623
4674
|
|
|
4624
4675
|
// src/features/analysis/scm/scmSubmit/index.ts
|
|
4625
|
-
import fs2 from "node:fs/promises";
|
|
4626
|
-
import parseDiff from "parse-diff";
|
|
4627
|
-
import path4 from "path";
|
|
4628
4676
|
import { simpleGit } from "simple-git";
|
|
4629
|
-
import tmp from "tmp";
|
|
4630
|
-
import { z as z20 } from "zod";
|
|
4631
|
-
|
|
4632
|
-
// src/features/analysis/scm/scmSubmit/types.ts
|
|
4633
|
-
import { z as z19 } from "zod";
|
|
4634
|
-
var BaseSubmitToScmMessageZ = z19.object({
|
|
4635
|
-
submitFixRequestId: z19.string().uuid(),
|
|
4636
|
-
fixes: z19.array(
|
|
4637
|
-
z19.object({
|
|
4638
|
-
fixId: z19.string().uuid(),
|
|
4639
|
-
patchesOriginalEncodingBase64: z19.array(z19.string()),
|
|
4640
|
-
patches: z19.array(z19.string())
|
|
4641
|
-
})
|
|
4642
|
-
),
|
|
4643
|
-
commitHash: z19.string(),
|
|
4644
|
-
repoUrl: z19.string(),
|
|
4645
|
-
mobbUserEmail: z19.string(),
|
|
4646
|
-
extraHeaders: z19.record(z19.string(), z19.string()).default({})
|
|
4647
|
-
});
|
|
4648
|
-
var submitToScmMessageType = {
|
|
4649
|
-
commitToSameBranch: "commitToSameBranch",
|
|
4650
|
-
submitFixesForDifferentBranch: "submitFixesForDifferentBranch"
|
|
4651
|
-
};
|
|
4652
|
-
var CommitToSameBranchParamsZ = BaseSubmitToScmMessageZ.merge(
|
|
4653
|
-
z19.object({
|
|
4654
|
-
type: z19.literal(submitToScmMessageType.commitToSameBranch),
|
|
4655
|
-
branch: z19.string(),
|
|
4656
|
-
commitMessages: z19.array(z19.string()),
|
|
4657
|
-
commitDescriptions: z19.array(z19.string().nullish()),
|
|
4658
|
-
githubCommentId: z19.number().nullish(),
|
|
4659
|
-
prId: z19.number().nullish()
|
|
4660
|
-
})
|
|
4661
|
-
);
|
|
4662
|
-
var SubmitFixesToDifferentBranchParamsZ = z19.object({
|
|
4663
|
-
type: z19.literal(submitToScmMessageType.submitFixesForDifferentBranch),
|
|
4664
|
-
submitBranch: z19.string(),
|
|
4665
|
-
baseBranch: z19.string()
|
|
4666
|
-
}).merge(BaseSubmitToScmMessageZ);
|
|
4667
|
-
var SubmitFixesMessageZ = z19.union([
|
|
4668
|
-
CommitToSameBranchParamsZ,
|
|
4669
|
-
SubmitFixesToDifferentBranchParamsZ
|
|
4670
|
-
]);
|
|
4671
|
-
var FixResponseArrayZ = z19.array(
|
|
4672
|
-
z19.object({
|
|
4673
|
-
fixId: z19.string().uuid()
|
|
4674
|
-
})
|
|
4675
|
-
);
|
|
4676
|
-
var SubmitFixesBaseResponseMessageZ = z19.object({
|
|
4677
|
-
mobbUserEmail: z19.string(),
|
|
4678
|
-
submitFixRequestId: z19.string().uuid(),
|
|
4679
|
-
submitBranches: z19.array(
|
|
4680
|
-
z19.object({
|
|
4681
|
-
branchName: z19.string(),
|
|
4682
|
-
fixes: FixResponseArrayZ
|
|
4683
|
-
})
|
|
4684
|
-
),
|
|
4685
|
-
error: z19.object({
|
|
4686
|
-
type: z19.enum([
|
|
4687
|
-
"InitialRepoAccessError",
|
|
4688
|
-
"PushBranchError",
|
|
4689
|
-
"AllFixesConflictWithTargetBranchError",
|
|
4690
|
-
"InternalFixConflictError",
|
|
4691
|
-
"UnknownError"
|
|
4692
|
-
]),
|
|
4693
|
-
info: z19.object({
|
|
4694
|
-
message: z19.string(),
|
|
4695
|
-
pushBranchName: z19.string().optional()
|
|
4696
|
-
})
|
|
4697
|
-
}).optional()
|
|
4698
|
-
});
|
|
4699
|
-
var authorSchemaZ = z19.object({
|
|
4700
|
-
email: z19.string(),
|
|
4701
|
-
name: z19.string()
|
|
4702
|
-
}).nullable();
|
|
4703
|
-
var summarySchemaZ = z19.object({
|
|
4704
|
-
changes: z19.number(),
|
|
4705
|
-
insertions: z19.number(),
|
|
4706
|
-
deletions: z19.number()
|
|
4707
|
-
});
|
|
4708
|
-
var GitCommitZ = z19.object({
|
|
4709
|
-
author: authorSchemaZ,
|
|
4710
|
-
branch: z19.string(),
|
|
4711
|
-
commit: z19.string(),
|
|
4712
|
-
root: z19.boolean(),
|
|
4713
|
-
summary: summarySchemaZ
|
|
4714
|
-
});
|
|
4715
|
-
var SubmitFixesToSameBranchResponseMessageZ = z19.object({
|
|
4716
|
-
type: z19.literal(submitToScmMessageType.commitToSameBranch),
|
|
4717
|
-
githubCommentId: z19.number().nullish(),
|
|
4718
|
-
commits: z19.array(GitCommitZ),
|
|
4719
|
-
prId: z19.number().nullish()
|
|
4720
|
-
}).merge(SubmitFixesBaseResponseMessageZ);
|
|
4721
|
-
var SubmitFixesToDifferentBranchResponseMessageZ = z19.object({
|
|
4722
|
-
type: z19.literal(submitToScmMessageType.submitFixesForDifferentBranch),
|
|
4723
|
-
githubCommentId: z19.number().optional()
|
|
4724
|
-
}).merge(SubmitFixesBaseResponseMessageZ);
|
|
4725
|
-
var SubmitFixesResponseMessageZ = z19.discriminatedUnion("type", [
|
|
4726
|
-
SubmitFixesToSameBranchResponseMessageZ,
|
|
4727
|
-
SubmitFixesToDifferentBranchResponseMessageZ
|
|
4728
|
-
]);
|
|
4729
|
-
|
|
4730
|
-
// src/features/analysis/scm/scmSubmit/index.ts
|
|
4731
4677
|
var isValidBranchName = async (branchName) => {
|
|
4732
4678
|
const git = simpleGit();
|
|
4733
4679
|
try {
|
|
@@ -4740,12 +4686,6 @@ var isValidBranchName = async (branchName) => {
|
|
|
4740
4686
|
return false;
|
|
4741
4687
|
}
|
|
4742
4688
|
};
|
|
4743
|
-
var FixesZ = z20.array(
|
|
4744
|
-
z20.object({
|
|
4745
|
-
fixId: z20.string(),
|
|
4746
|
-
patchesOriginalEncodingBase64: z20.array(z20.string())
|
|
4747
|
-
})
|
|
4748
|
-
).nonempty();
|
|
4749
4689
|
|
|
4750
4690
|
// src/features/analysis/scm/scm.ts
|
|
4751
4691
|
var SCMLib = class {
|
|
@@ -5007,33 +4947,33 @@ import querystring2 from "node:querystring";
|
|
|
5007
4947
|
import * as bitbucketPkgNode from "bitbucket";
|
|
5008
4948
|
import bitbucketPkg from "bitbucket";
|
|
5009
4949
|
import Debug3 from "debug";
|
|
5010
|
-
import { z as
|
|
4950
|
+
import { z as z20 } from "zod";
|
|
5011
4951
|
|
|
5012
4952
|
// src/features/analysis/scm/bitbucket/validation.ts
|
|
5013
|
-
import { z as
|
|
5014
|
-
var BitbucketAuthResultZ =
|
|
5015
|
-
access_token:
|
|
5016
|
-
token_type:
|
|
5017
|
-
refresh_token:
|
|
4953
|
+
import { z as z19 } from "zod";
|
|
4954
|
+
var BitbucketAuthResultZ = z19.object({
|
|
4955
|
+
access_token: z19.string(),
|
|
4956
|
+
token_type: z19.string(),
|
|
4957
|
+
refresh_token: z19.string()
|
|
5018
4958
|
});
|
|
5019
4959
|
|
|
5020
4960
|
// src/features/analysis/scm/bitbucket/bitbucket.ts
|
|
5021
4961
|
var debug3 = Debug3("scm:bitbucket");
|
|
5022
4962
|
var BITBUCKET_HOSTNAME = "bitbucket.org";
|
|
5023
|
-
var TokenExpiredErrorZ =
|
|
5024
|
-
status:
|
|
5025
|
-
error:
|
|
5026
|
-
type:
|
|
5027
|
-
error:
|
|
5028
|
-
message:
|
|
4963
|
+
var TokenExpiredErrorZ = z20.object({
|
|
4964
|
+
status: z20.number(),
|
|
4965
|
+
error: z20.object({
|
|
4966
|
+
type: z20.string(),
|
|
4967
|
+
error: z20.object({
|
|
4968
|
+
message: z20.string()
|
|
5029
4969
|
})
|
|
5030
4970
|
})
|
|
5031
4971
|
});
|
|
5032
4972
|
var BITBUCKET_ACCESS_TOKEN_URL = `https://${BITBUCKET_HOSTNAME}/site/oauth2/access_token`;
|
|
5033
|
-
var BitbucketParseResultZ =
|
|
5034
|
-
organization:
|
|
5035
|
-
repoName:
|
|
5036
|
-
hostname:
|
|
4973
|
+
var BitbucketParseResultZ = z20.object({
|
|
4974
|
+
organization: z20.string(),
|
|
4975
|
+
repoName: z20.string(),
|
|
4976
|
+
hostname: z20.literal(BITBUCKET_HOSTNAME)
|
|
5037
4977
|
});
|
|
5038
4978
|
function parseBitbucketOrganizationAndRepo(bitbucketUrl) {
|
|
5039
4979
|
const parsedGitHubUrl = normalizeUrl(bitbucketUrl);
|
|
@@ -5094,7 +5034,7 @@ function getBitbucketSdk(params) {
|
|
|
5094
5034
|
if (!res.data.values) {
|
|
5095
5035
|
return [];
|
|
5096
5036
|
}
|
|
5097
|
-
return res.data.values.filter((branch) => !!branch.name).map((branch) =>
|
|
5037
|
+
return res.data.values.filter((branch) => !!branch.name).map((branch) => z20.string().parse(branch.name));
|
|
5098
5038
|
},
|
|
5099
5039
|
async getIsUserCollaborator(params2) {
|
|
5100
5040
|
const { repoUrl } = params2;
|
|
@@ -5209,7 +5149,7 @@ function getBitbucketSdk(params) {
|
|
|
5209
5149
|
return GetRefererenceResultZ.parse({
|
|
5210
5150
|
sha: tagRes.data.target?.hash,
|
|
5211
5151
|
type: "TAG" /* TAG */,
|
|
5212
|
-
date: new Date(
|
|
5152
|
+
date: new Date(z20.string().parse(tagRes.data.target?.date))
|
|
5213
5153
|
});
|
|
5214
5154
|
},
|
|
5215
5155
|
async getBranchRef(params2) {
|
|
@@ -5217,7 +5157,7 @@ function getBitbucketSdk(params) {
|
|
|
5217
5157
|
return GetRefererenceResultZ.parse({
|
|
5218
5158
|
sha: getBranchRes.target?.hash,
|
|
5219
5159
|
type: "BRANCH" /* BRANCH */,
|
|
5220
|
-
date: new Date(
|
|
5160
|
+
date: new Date(z20.string().parse(getBranchRes.target?.date))
|
|
5221
5161
|
});
|
|
5222
5162
|
},
|
|
5223
5163
|
async getCommitRef(params2) {
|
|
@@ -5225,13 +5165,13 @@ function getBitbucketSdk(params) {
|
|
|
5225
5165
|
return GetRefererenceResultZ.parse({
|
|
5226
5166
|
sha: getCommitRes.hash,
|
|
5227
5167
|
type: "COMMIT" /* COMMIT */,
|
|
5228
|
-
date: new Date(
|
|
5168
|
+
date: new Date(z20.string().parse(getCommitRes.date))
|
|
5229
5169
|
});
|
|
5230
5170
|
},
|
|
5231
5171
|
async getDownloadUrl({ url, sha }) {
|
|
5232
5172
|
this.getReferenceData({ ref: sha, url });
|
|
5233
5173
|
const repoRes = await this.getRepo({ repoUrl: url });
|
|
5234
|
-
const parsedRepoUrl =
|
|
5174
|
+
const parsedRepoUrl = z20.string().url().parse(repoRes.links?.html?.href);
|
|
5235
5175
|
return `${parsedRepoUrl}/get/${sha}.zip`;
|
|
5236
5176
|
},
|
|
5237
5177
|
async getPullRequest(params2) {
|
|
@@ -5296,7 +5236,7 @@ async function validateBitbucketParams(params) {
|
|
|
5296
5236
|
}
|
|
5297
5237
|
async function getUsersworkspacesSlugs(bitbucketClient) {
|
|
5298
5238
|
const res = await bitbucketClient.workspaces.getWorkspaces({});
|
|
5299
|
-
return res.data.values?.map((v) =>
|
|
5239
|
+
return res.data.values?.map((v) => z20.string().parse(v.slug));
|
|
5300
5240
|
}
|
|
5301
5241
|
async function getllUsersrepositories(bitbucketClient) {
|
|
5302
5242
|
const userWorspacesSlugs = await getUsersworkspacesSlugs(bitbucketClient);
|
|
@@ -5324,10 +5264,10 @@ async function getRepositoriesByWorkspace(bitbucketClient, { workspaceSlug }) {
|
|
|
5324
5264
|
|
|
5325
5265
|
// src/features/analysis/scm/bitbucket/BitbucketSCMLib.ts
|
|
5326
5266
|
import { setTimeout as setTimeout3 } from "node:timers/promises";
|
|
5327
|
-
import { z as
|
|
5267
|
+
import { z as z21 } from "zod";
|
|
5328
5268
|
function getUserAndPassword(token) {
|
|
5329
5269
|
const [username, password] = token.split(":");
|
|
5330
|
-
const safePasswordAndUsername =
|
|
5270
|
+
const safePasswordAndUsername = z21.object({ username: z21.string(), password: z21.string() }).parse({ username, password });
|
|
5331
5271
|
return {
|
|
5332
5272
|
username: safePasswordAndUsername.username,
|
|
5333
5273
|
password: safePasswordAndUsername.password
|
|
@@ -5399,7 +5339,7 @@ var BitbucketSCMLib = class extends SCMLib {
|
|
|
5399
5339
|
return { username, password, authType };
|
|
5400
5340
|
}
|
|
5401
5341
|
case "token": {
|
|
5402
|
-
return { authType, token:
|
|
5342
|
+
return { authType, token: z21.string().parse(this.accessToken) };
|
|
5403
5343
|
}
|
|
5404
5344
|
case "public":
|
|
5405
5345
|
return { authType };
|
|
@@ -5413,7 +5353,7 @@ var BitbucketSCMLib = class extends SCMLib {
|
|
|
5413
5353
|
...params,
|
|
5414
5354
|
repoUrl: this.url
|
|
5415
5355
|
});
|
|
5416
|
-
return String(
|
|
5356
|
+
return String(z21.number().parse(pullRequestRes.id));
|
|
5417
5357
|
} catch (e) {
|
|
5418
5358
|
console.warn(
|
|
5419
5359
|
`error creating pull request for BB. Try number ${i + 1}`,
|
|
@@ -5498,7 +5438,7 @@ var BitbucketSCMLib = class extends SCMLib {
|
|
|
5498
5438
|
async getUsername() {
|
|
5499
5439
|
this._validateAccessToken();
|
|
5500
5440
|
const res = await this.bitbucketSdk.getUser();
|
|
5501
|
-
return
|
|
5441
|
+
return z21.string().parse(res.username);
|
|
5502
5442
|
}
|
|
5503
5443
|
async getSubmitRequestStatus(_scmSubmitRequestId) {
|
|
5504
5444
|
this._validateAccessTokenAndUrl();
|
|
@@ -5527,7 +5467,7 @@ var BitbucketSCMLib = class extends SCMLib {
|
|
|
5527
5467
|
async getRepoDefaultBranch() {
|
|
5528
5468
|
this._validateUrl();
|
|
5529
5469
|
const repoRes = await this.bitbucketSdk.getRepo({ repoUrl: this.url });
|
|
5530
|
-
return
|
|
5470
|
+
return z21.string().parse(repoRes.mainbranch?.name);
|
|
5531
5471
|
}
|
|
5532
5472
|
getSubmitRequestUrl(submitRequestId) {
|
|
5533
5473
|
this._validateUrl();
|
|
@@ -5558,7 +5498,7 @@ var BitbucketSCMLib = class extends SCMLib {
|
|
|
5558
5498
|
};
|
|
5559
5499
|
|
|
5560
5500
|
// src/features/analysis/scm/github/GithubSCMLib.ts
|
|
5561
|
-
import { z as
|
|
5501
|
+
import { z as z22 } from "zod";
|
|
5562
5502
|
var GithubSCMLib = class extends SCMLib {
|
|
5563
5503
|
// we don't always need a url, what's important is that we have an access token
|
|
5564
5504
|
constructor(url, accessToken, scmOrg) {
|
|
@@ -5659,7 +5599,7 @@ var GithubSCMLib = class extends SCMLib {
|
|
|
5659
5599
|
owner,
|
|
5660
5600
|
repo
|
|
5661
5601
|
});
|
|
5662
|
-
return
|
|
5602
|
+
return z22.string().parse(prRes.data);
|
|
5663
5603
|
}
|
|
5664
5604
|
async getRepoList(_scmOrg) {
|
|
5665
5605
|
this._validateAccessToken();
|
|
@@ -5723,11 +5663,11 @@ var GithubSCMLib = class extends SCMLib {
|
|
|
5723
5663
|
markdownComment: comment
|
|
5724
5664
|
});
|
|
5725
5665
|
}
|
|
5726
|
-
async getRepoBlameRanges(ref,
|
|
5666
|
+
async getRepoBlameRanges(ref, path8) {
|
|
5727
5667
|
this._validateUrl();
|
|
5728
5668
|
return await this.githubSdk.getGithubBlameRanges({
|
|
5729
5669
|
ref,
|
|
5730
|
-
path:
|
|
5670
|
+
path: path8,
|
|
5731
5671
|
gitHubUrl: this.url
|
|
5732
5672
|
});
|
|
5733
5673
|
}
|
|
@@ -5821,11 +5761,11 @@ import {
|
|
|
5821
5761
|
} from "undici";
|
|
5822
5762
|
|
|
5823
5763
|
// src/features/analysis/scm/gitlab/types.ts
|
|
5824
|
-
import { z as
|
|
5825
|
-
var GitlabAuthResultZ =
|
|
5826
|
-
access_token:
|
|
5827
|
-
token_type:
|
|
5828
|
-
refresh_token:
|
|
5764
|
+
import { z as z23 } from "zod";
|
|
5765
|
+
var GitlabAuthResultZ = z23.object({
|
|
5766
|
+
access_token: z23.string(),
|
|
5767
|
+
token_type: z23.string(),
|
|
5768
|
+
refresh_token: z23.string()
|
|
5829
5769
|
});
|
|
5830
5770
|
|
|
5831
5771
|
// src/features/analysis/scm/gitlab/gitlab.ts
|
|
@@ -6123,13 +6063,13 @@ function parseGitlabOwnerAndRepo(gitlabUrl) {
|
|
|
6123
6063
|
const { organization, repoName, projectPath } = parsingResult;
|
|
6124
6064
|
return { owner: organization, repo: repoName, projectPath };
|
|
6125
6065
|
}
|
|
6126
|
-
async function getGitlabBlameRanges({ ref, gitlabUrl, path:
|
|
6066
|
+
async function getGitlabBlameRanges({ ref, gitlabUrl, path: path8 }, options) {
|
|
6127
6067
|
const { projectPath } = parseGitlabOwnerAndRepo(gitlabUrl);
|
|
6128
6068
|
const api2 = getGitBeaker({
|
|
6129
6069
|
url: gitlabUrl,
|
|
6130
6070
|
gitlabAuthToken: options?.gitlabAuthToken
|
|
6131
6071
|
});
|
|
6132
|
-
const resp = await api2.RepositoryFiles.allFileBlames(projectPath,
|
|
6072
|
+
const resp = await api2.RepositoryFiles.allFileBlames(projectPath, path8, ref);
|
|
6133
6073
|
let lineNumber = 1;
|
|
6134
6074
|
return resp.filter((range) => range.lines).map((range) => {
|
|
6135
6075
|
const oldLineNumber = lineNumber;
|
|
@@ -6315,10 +6255,10 @@ var GitlabSCMLib = class extends SCMLib {
|
|
|
6315
6255
|
markdownComment: comment
|
|
6316
6256
|
});
|
|
6317
6257
|
}
|
|
6318
|
-
async getRepoBlameRanges(ref,
|
|
6258
|
+
async getRepoBlameRanges(ref, path8) {
|
|
6319
6259
|
this._validateUrl();
|
|
6320
6260
|
return await getGitlabBlameRanges(
|
|
6321
|
-
{ ref, path:
|
|
6261
|
+
{ ref, path: path8, gitlabUrl: this.url },
|
|
6322
6262
|
{
|
|
6323
6263
|
url: this.url,
|
|
6324
6264
|
gitlabAuthToken: this.accessToken
|
|
@@ -6367,7 +6307,7 @@ var GitlabSCMLib = class extends SCMLib {
|
|
|
6367
6307
|
};
|
|
6368
6308
|
|
|
6369
6309
|
// src/features/analysis/scm/scmFactory.ts
|
|
6370
|
-
import { z as
|
|
6310
|
+
import { z as z24 } from "zod";
|
|
6371
6311
|
|
|
6372
6312
|
// src/features/analysis/scm/StubSCMLib.ts
|
|
6373
6313
|
var StubSCMLib = class extends SCMLib {
|
|
@@ -6489,7 +6429,7 @@ async function createScmLib({ url, accessToken, scmType, scmOrg }, { propagateEx
|
|
|
6489
6429
|
if (e instanceof InvalidRepoUrlError && url) {
|
|
6490
6430
|
throw new RepoNoTokenAccessError(
|
|
6491
6431
|
"no access to repo",
|
|
6492
|
-
scmLibScmTypeToScmType[
|
|
6432
|
+
scmLibScmTypeToScmType[z24.nativeEnum(ScmLibScmType).parse(scmType)]
|
|
6493
6433
|
);
|
|
6494
6434
|
}
|
|
6495
6435
|
console.error(`error validating scm: ${scmType} `, e);
|
|
@@ -6820,14 +6760,14 @@ function getGithubSdk(params = {}) {
|
|
|
6820
6760
|
};
|
|
6821
6761
|
},
|
|
6822
6762
|
async getGithubBlameRanges(params2) {
|
|
6823
|
-
const { ref, gitHubUrl, path:
|
|
6763
|
+
const { ref, gitHubUrl, path: path8 } = params2;
|
|
6824
6764
|
const { owner, repo } = parseGithubOwnerAndRepo(gitHubUrl);
|
|
6825
6765
|
const res = await octokit.graphql(
|
|
6826
6766
|
GET_BLAME_DOCUMENT,
|
|
6827
6767
|
{
|
|
6828
6768
|
owner,
|
|
6829
6769
|
repo,
|
|
6830
|
-
path:
|
|
6770
|
+
path: path8,
|
|
6831
6771
|
ref
|
|
6832
6772
|
}
|
|
6833
6773
|
);
|
|
@@ -6970,8 +6910,8 @@ function getGithubSdk(params = {}) {
|
|
|
6970
6910
|
|
|
6971
6911
|
// src/features/analysis/add_fix_comments_for_pr/utils/utils.ts
|
|
6972
6912
|
import Debug7 from "debug";
|
|
6973
|
-
import
|
|
6974
|
-
import { z as
|
|
6913
|
+
import parseDiff from "parse-diff";
|
|
6914
|
+
import { z as z26 } from "zod";
|
|
6975
6915
|
|
|
6976
6916
|
// src/features/analysis/utils/by_key.ts
|
|
6977
6917
|
function keyBy(array, keyBy2) {
|
|
@@ -7043,7 +6983,7 @@ var scannerToFriendlyString = {
|
|
|
7043
6983
|
|
|
7044
6984
|
// src/features/analysis/add_fix_comments_for_pr/utils/buildCommentBody.ts
|
|
7045
6985
|
import Debug6 from "debug";
|
|
7046
|
-
import { z as
|
|
6986
|
+
import { z as z25 } from "zod";
|
|
7047
6987
|
var debug6 = Debug6("mobbdev:handle-finished-analysis");
|
|
7048
6988
|
var getCommitFixButton = (commitUrl) => `<a href="${commitUrl}"><img src=${COMMIT_FIX_SVG}></a>`;
|
|
7049
6989
|
function buildCommentBody({
|
|
@@ -7077,11 +7017,11 @@ function buildCommentBody({
|
|
|
7077
7017
|
});
|
|
7078
7018
|
const issueType = getIssueTypeFriendlyString(fix.safeIssueType);
|
|
7079
7019
|
const title = `# ${MobbIconMarkdown} ${issueType} fix is ready`;
|
|
7080
|
-
const validFixParseRes =
|
|
7020
|
+
const validFixParseRes = z25.object({
|
|
7081
7021
|
patchAndQuestions: PatchAndQuestionsZ,
|
|
7082
|
-
safeIssueLanguage:
|
|
7083
|
-
severityText:
|
|
7084
|
-
safeIssueType:
|
|
7022
|
+
safeIssueLanguage: z25.nativeEnum(IssueLanguage_Enum),
|
|
7023
|
+
severityText: z25.nativeEnum(Vulnerability_Severity_Enum),
|
|
7024
|
+
safeIssueType: z25.nativeEnum(IssueType_Enum)
|
|
7085
7025
|
}).safeParse(fix);
|
|
7086
7026
|
if (!validFixParseRes.success) {
|
|
7087
7027
|
debug6(
|
|
@@ -7182,7 +7122,7 @@ async function postFixComment(params) {
|
|
|
7182
7122
|
scanner
|
|
7183
7123
|
} = params;
|
|
7184
7124
|
const {
|
|
7185
|
-
path:
|
|
7125
|
+
path: path8,
|
|
7186
7126
|
startLine,
|
|
7187
7127
|
vulnerabilityReportIssue: { fixId }
|
|
7188
7128
|
} = vulnerabilityReportIssueCodeNode;
|
|
@@ -7198,7 +7138,7 @@ async function postFixComment(params) {
|
|
|
7198
7138
|
Refresh the page in order to see the changes.`,
|
|
7199
7139
|
pull_number: pullRequest,
|
|
7200
7140
|
commit_id: commitSha,
|
|
7201
|
-
path:
|
|
7141
|
+
path: path8,
|
|
7202
7142
|
line: startLine
|
|
7203
7143
|
});
|
|
7204
7144
|
const commentId = commentRes.data.id;
|
|
@@ -7246,7 +7186,7 @@ ${summary.join("\n")}`;
|
|
|
7246
7186
|
}
|
|
7247
7187
|
async function getRelevantVulenrabilitiesFromDiff(params) {
|
|
7248
7188
|
const { gqlClient, diff, vulnerabilityReportId } = params;
|
|
7249
|
-
const parsedDiff =
|
|
7189
|
+
const parsedDiff = parseDiff(diff);
|
|
7250
7190
|
const fileHunks = parsedDiff.map((file) => {
|
|
7251
7191
|
const fileNumbers = file.chunks.flatMap((chunk) => chunk.changes).filter((change) => change.type === "add").map((_change) => {
|
|
7252
7192
|
const change = _change;
|
|
@@ -7254,7 +7194,7 @@ async function getRelevantVulenrabilitiesFromDiff(params) {
|
|
|
7254
7194
|
});
|
|
7255
7195
|
const lineAddedRanges = calculateRanges(fileNumbers);
|
|
7256
7196
|
const fileFilter = {
|
|
7257
|
-
path:
|
|
7197
|
+
path: z26.string().parse(file.to),
|
|
7258
7198
|
ranges: lineAddedRanges.map(([startLine, endLine]) => ({
|
|
7259
7199
|
endLine,
|
|
7260
7200
|
startLine
|
|
@@ -7606,30 +7546,30 @@ function subscribe(query, variables, callback, wsClientOptions) {
|
|
|
7606
7546
|
}
|
|
7607
7547
|
|
|
7608
7548
|
// src/features/analysis/graphql/types.ts
|
|
7609
|
-
import { z as
|
|
7610
|
-
var VulnerabilityReportIssueCodeNodeZ =
|
|
7611
|
-
vulnerabilityReportIssueId:
|
|
7612
|
-
path:
|
|
7613
|
-
startLine:
|
|
7614
|
-
vulnerabilityReportIssue:
|
|
7615
|
-
fixId:
|
|
7549
|
+
import { z as z27 } from "zod";
|
|
7550
|
+
var VulnerabilityReportIssueCodeNodeZ = z27.object({
|
|
7551
|
+
vulnerabilityReportIssueId: z27.string(),
|
|
7552
|
+
path: z27.string(),
|
|
7553
|
+
startLine: z27.number(),
|
|
7554
|
+
vulnerabilityReportIssue: z27.object({
|
|
7555
|
+
fixId: z27.string()
|
|
7616
7556
|
})
|
|
7617
7557
|
});
|
|
7618
|
-
var GetVulByNodesMetadataZ =
|
|
7619
|
-
vulnerabilityReportIssueCodeNodes:
|
|
7620
|
-
nonFixablePrVuls:
|
|
7621
|
-
aggregate:
|
|
7622
|
-
count:
|
|
7558
|
+
var GetVulByNodesMetadataZ = z27.object({
|
|
7559
|
+
vulnerabilityReportIssueCodeNodes: z27.array(VulnerabilityReportIssueCodeNodeZ),
|
|
7560
|
+
nonFixablePrVuls: z27.object({
|
|
7561
|
+
aggregate: z27.object({
|
|
7562
|
+
count: z27.number()
|
|
7623
7563
|
})
|
|
7624
7564
|
}),
|
|
7625
|
-
fixablePrVuls:
|
|
7626
|
-
aggregate:
|
|
7627
|
-
count:
|
|
7565
|
+
fixablePrVuls: z27.object({
|
|
7566
|
+
aggregate: z27.object({
|
|
7567
|
+
count: z27.number()
|
|
7628
7568
|
})
|
|
7629
7569
|
}),
|
|
7630
|
-
totalScanVulnerabilities:
|
|
7631
|
-
aggregate:
|
|
7632
|
-
count:
|
|
7570
|
+
totalScanVulnerabilities: z27.object({
|
|
7571
|
+
aggregate: z27.object({
|
|
7572
|
+
count: z27.number()
|
|
7633
7573
|
})
|
|
7634
7574
|
})
|
|
7635
7575
|
});
|
|
@@ -7919,24 +7859,24 @@ var GQLClient = class {
|
|
|
7919
7859
|
};
|
|
7920
7860
|
|
|
7921
7861
|
// src/features/analysis/pack.ts
|
|
7922
|
-
import
|
|
7923
|
-
import
|
|
7862
|
+
import fs2 from "node:fs";
|
|
7863
|
+
import path4 from "node:path";
|
|
7924
7864
|
import AdmZip from "adm-zip";
|
|
7925
7865
|
import Debug12 from "debug";
|
|
7926
7866
|
import { globby } from "globby";
|
|
7927
7867
|
import { isBinary } from "istextorbinary";
|
|
7928
7868
|
import { simpleGit as simpleGit3 } from "simple-git";
|
|
7929
7869
|
import { parseStringPromise } from "xml2js";
|
|
7930
|
-
import { z as
|
|
7870
|
+
import { z as z28 } from "zod";
|
|
7931
7871
|
var debug12 = Debug12("mobbdev:pack");
|
|
7932
7872
|
var MAX_FILE_SIZE = 1024 * 1024 * 5;
|
|
7933
|
-
var FPR_SOURCE_CODE_FILE_MAPPING_SCHEMA =
|
|
7934
|
-
properties:
|
|
7935
|
-
entry:
|
|
7936
|
-
|
|
7937
|
-
_:
|
|
7938
|
-
$:
|
|
7939
|
-
key:
|
|
7873
|
+
var FPR_SOURCE_CODE_FILE_MAPPING_SCHEMA = z28.object({
|
|
7874
|
+
properties: z28.object({
|
|
7875
|
+
entry: z28.array(
|
|
7876
|
+
z28.object({
|
|
7877
|
+
_: z28.string(),
|
|
7878
|
+
$: z28.object({
|
|
7879
|
+
key: z28.string()
|
|
7940
7880
|
})
|
|
7941
7881
|
})
|
|
7942
7882
|
)
|
|
@@ -7986,20 +7926,20 @@ async function pack(srcDirPath, vulnFiles) {
|
|
|
7986
7926
|
const zip = new AdmZip();
|
|
7987
7927
|
debug12("compressing files");
|
|
7988
7928
|
for (const filepath of filepaths) {
|
|
7989
|
-
const absFilepath =
|
|
7929
|
+
const absFilepath = path4.join(srcDirPath, filepath.toString());
|
|
7990
7930
|
vulnFiles = vulnFiles.concat(_get_manifest_files_suffixes());
|
|
7991
7931
|
if (!endsWithAny(
|
|
7992
|
-
absFilepath.toString().replaceAll(
|
|
7932
|
+
absFilepath.toString().replaceAll(path4.win32.sep, path4.posix.sep),
|
|
7993
7933
|
vulnFiles
|
|
7994
7934
|
)) {
|
|
7995
7935
|
debug12("ignoring %s because it is not a vulnerability file", filepath);
|
|
7996
7936
|
continue;
|
|
7997
7937
|
}
|
|
7998
|
-
if (
|
|
7938
|
+
if (fs2.lstatSync(absFilepath).size > MAX_FILE_SIZE) {
|
|
7999
7939
|
debug12("ignoring %s because the size is > 5MB", filepath);
|
|
8000
7940
|
continue;
|
|
8001
7941
|
}
|
|
8002
|
-
const data = git ? await git.showBuffer([`HEAD:./${filepath}`]) :
|
|
7942
|
+
const data = git ? await git.showBuffer([`HEAD:./${filepath}`]) : fs2.readFileSync(absFilepath);
|
|
8003
7943
|
if (isBinary(null, data)) {
|
|
8004
7944
|
debug12("ignoring %s because is seems to be a binary file", filepath);
|
|
8005
7945
|
continue;
|
|
@@ -8156,7 +8096,7 @@ import Debug14 from "debug";
|
|
|
8156
8096
|
import { existsSync } from "fs";
|
|
8157
8097
|
import { createSpinner as createSpinner2 } from "nanospinner";
|
|
8158
8098
|
import { type } from "os";
|
|
8159
|
-
import
|
|
8099
|
+
import path5 from "path";
|
|
8160
8100
|
var debug13 = Debug14("mobbdev:checkmarx");
|
|
8161
8101
|
var require2 = createRequire(import.meta.url);
|
|
8162
8102
|
var getCheckmarxPath = () => {
|
|
@@ -8216,9 +8156,9 @@ async function getCheckmarxReport({ reportPath, repositoryRoot, branch, projectN
|
|
|
8216
8156
|
await startCheckmarxConfigationPrompt();
|
|
8217
8157
|
await validateCheckamxCredentials();
|
|
8218
8158
|
}
|
|
8219
|
-
const extension =
|
|
8220
|
-
const filePath =
|
|
8221
|
-
const fileName =
|
|
8159
|
+
const extension = path5.extname(reportPath);
|
|
8160
|
+
const filePath = path5.dirname(reportPath);
|
|
8161
|
+
const fileName = path5.basename(reportPath, extension);
|
|
8222
8162
|
const checkmarxCommandArgs = getCheckmarxCommandArgs({
|
|
8223
8163
|
repoPath: repositoryRoot,
|
|
8224
8164
|
branch,
|
|
@@ -8400,7 +8340,7 @@ async function downloadRepo({
|
|
|
8400
8340
|
const { createSpinner: createSpinner5 } = Spinner2({ ci });
|
|
8401
8341
|
const repoSpinner = createSpinner5("\u{1F4BE} Downloading Repo").start();
|
|
8402
8342
|
debug16("download repo %s %s %s", repoUrl, dirname);
|
|
8403
|
-
const zipFilePath =
|
|
8343
|
+
const zipFilePath = path6.join(dirname, "repo.zip");
|
|
8404
8344
|
debug16("download URL: %s auth headers: %o", downloadUrl, authHeaders);
|
|
8405
8345
|
const response = await fetch4(downloadUrl, {
|
|
8406
8346
|
method: "GET",
|
|
@@ -8413,19 +8353,19 @@ async function downloadRepo({
|
|
|
8413
8353
|
repoSpinner.error({ text: "\u{1F4BE} Repo download failed" });
|
|
8414
8354
|
throw new Error(`Can't access ${chalk4.bold(repoUrl)}`);
|
|
8415
8355
|
}
|
|
8416
|
-
const fileWriterStream =
|
|
8356
|
+
const fileWriterStream = fs3.createWriteStream(zipFilePath);
|
|
8417
8357
|
if (!response.body) {
|
|
8418
8358
|
throw new Error("Response body is empty");
|
|
8419
8359
|
}
|
|
8420
8360
|
await pipeline(response.body, fileWriterStream);
|
|
8421
8361
|
await extract(zipFilePath, { dir: dirname });
|
|
8422
|
-
const repoRoot =
|
|
8362
|
+
const repoRoot = fs3.readdirSync(dirname, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name)[0];
|
|
8423
8363
|
if (!repoRoot) {
|
|
8424
8364
|
throw new Error("Repo root not found");
|
|
8425
8365
|
}
|
|
8426
8366
|
debug16("repo root %s", repoRoot);
|
|
8427
8367
|
repoSpinner.success({ text: "\u{1F4BE} Repo downloaded successfully" });
|
|
8428
|
-
return
|
|
8368
|
+
return path6.join(dirname, repoRoot);
|
|
8429
8369
|
}
|
|
8430
8370
|
var getReportUrl = ({
|
|
8431
8371
|
organizationId,
|
|
@@ -8436,7 +8376,7 @@ var debug16 = Debug17("mobbdev:index");
|
|
|
8436
8376
|
var config2 = new Configstore(packageJson.name, { apiToken: "" });
|
|
8437
8377
|
debug16("config %o", config2);
|
|
8438
8378
|
async function runAnalysis(params, options) {
|
|
8439
|
-
const tmpObj =
|
|
8379
|
+
const tmpObj = tmp.dirSync({
|
|
8440
8380
|
unsafeCleanup: true
|
|
8441
8381
|
});
|
|
8442
8382
|
try {
|
|
@@ -8535,7 +8475,7 @@ async function getReport(params, { skipPrompts }) {
|
|
|
8535
8475
|
authHeaders: scm.getAuthHeaders(),
|
|
8536
8476
|
downloadUrl
|
|
8537
8477
|
});
|
|
8538
|
-
const reportPath =
|
|
8478
|
+
const reportPath = path6.join(dirname, "report.json");
|
|
8539
8479
|
switch (scanner) {
|
|
8540
8480
|
case "snyk":
|
|
8541
8481
|
await getSnykReport(reportPath, repositoryRoot, { skipPrompts });
|
|
@@ -8695,7 +8635,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
8695
8635
|
spinner: mobbSpinner,
|
|
8696
8636
|
submitVulnerabilityReportVariables: {
|
|
8697
8637
|
fixReportId: reportUploadInfo.fixReportId,
|
|
8698
|
-
repoUrl:
|
|
8638
|
+
repoUrl: z29.string().parse(repo),
|
|
8699
8639
|
reference,
|
|
8700
8640
|
projectId,
|
|
8701
8641
|
vulnerabilityReportFileName: "report.json",
|
|
@@ -8722,6 +8662,15 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
8722
8662
|
});
|
|
8723
8663
|
}
|
|
8724
8664
|
await askToOpenAnalysis();
|
|
8665
|
+
if (command === "review") {
|
|
8666
|
+
await waitForAnaysisAndReviewPr({
|
|
8667
|
+
repo,
|
|
8668
|
+
githubActionToken,
|
|
8669
|
+
analysisId: reportUploadInfo.fixReportId,
|
|
8670
|
+
scanner,
|
|
8671
|
+
gqlClient
|
|
8672
|
+
});
|
|
8673
|
+
}
|
|
8725
8674
|
return reportUploadInfo.fixReportId;
|
|
8726
8675
|
async function askToOpenAnalysis() {
|
|
8727
8676
|
if (!repoUploadInfo || !reportUploadInfo) {
|
|
@@ -8814,7 +8763,7 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
8814
8763
|
const zippingSpinner = createSpinner5("\u{1F4E6} Zipping repo").start();
|
|
8815
8764
|
let zipBuffer;
|
|
8816
8765
|
let gitInfo = { success: false };
|
|
8817
|
-
if (srcFileStatus.isFile() &&
|
|
8766
|
+
if (srcFileStatus.isFile() && path6.extname(srcPath).toLowerCase() === ".fpr") {
|
|
8818
8767
|
zipBuffer = await repackFpr(srcPath);
|
|
8819
8768
|
} else {
|
|
8820
8769
|
gitInfo = await getGitInfo(srcPath);
|
|
@@ -8850,34 +8799,12 @@ async function _scan(params, { skipPrompts = false } = {}) {
|
|
|
8850
8799
|
}
|
|
8851
8800
|
});
|
|
8852
8801
|
if (command === "review") {
|
|
8853
|
-
|
|
8854
|
-
repo
|
|
8855
|
-
githubActionToken
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
url: params2.repo,
|
|
8860
|
-
accessToken: params2.githubActionToken,
|
|
8861
|
-
scmOrg: "",
|
|
8862
|
-
scmType: "GITHUB" /* GITHUB */
|
|
8863
|
-
},
|
|
8864
|
-
{
|
|
8865
|
-
propagateExceptions: true
|
|
8866
|
-
}
|
|
8867
|
-
);
|
|
8868
|
-
await gqlClient.subscribeToAnalysis({
|
|
8869
|
-
subscribeToAnalysisParams: {
|
|
8870
|
-
analysisId: reportUploadInfo.fixReportId
|
|
8871
|
-
},
|
|
8872
|
-
callback: (analysisId) => {
|
|
8873
|
-
return addFixCommentsForPr({
|
|
8874
|
-
analysisId,
|
|
8875
|
-
gqlClient,
|
|
8876
|
-
scm,
|
|
8877
|
-
scanner: z31.nativeEnum(SCANNERS).parse(scanner)
|
|
8878
|
-
});
|
|
8879
|
-
},
|
|
8880
|
-
callbackStates: ["Finished" /* Finished */]
|
|
8802
|
+
await waitForAnaysisAndReviewPr({
|
|
8803
|
+
repo,
|
|
8804
|
+
githubActionToken,
|
|
8805
|
+
analysisId: reportUploadInfo.fixReportId,
|
|
8806
|
+
scanner,
|
|
8807
|
+
gqlClient
|
|
8881
8808
|
});
|
|
8882
8809
|
}
|
|
8883
8810
|
} catch (e) {
|
|
@@ -8949,6 +8876,43 @@ async function _digestReport({
|
|
|
8949
8876
|
throw e;
|
|
8950
8877
|
}
|
|
8951
8878
|
}
|
|
8879
|
+
async function waitForAnaysisAndReviewPr({
|
|
8880
|
+
repo,
|
|
8881
|
+
githubActionToken,
|
|
8882
|
+
analysisId,
|
|
8883
|
+
scanner,
|
|
8884
|
+
gqlClient
|
|
8885
|
+
}) {
|
|
8886
|
+
const params = z29.object({
|
|
8887
|
+
repo: z29.string().url(),
|
|
8888
|
+
githubActionToken: z29.string()
|
|
8889
|
+
}).parse({ repo, githubActionToken });
|
|
8890
|
+
const scm = await createScmLib(
|
|
8891
|
+
{
|
|
8892
|
+
url: params.repo,
|
|
8893
|
+
accessToken: params.githubActionToken,
|
|
8894
|
+
scmOrg: "",
|
|
8895
|
+
scmType: "GITHUB" /* GITHUB */
|
|
8896
|
+
},
|
|
8897
|
+
{
|
|
8898
|
+
propagateExceptions: true
|
|
8899
|
+
}
|
|
8900
|
+
);
|
|
8901
|
+
await gqlClient.subscribeToAnalysis({
|
|
8902
|
+
subscribeToAnalysisParams: {
|
|
8903
|
+
analysisId
|
|
8904
|
+
},
|
|
8905
|
+
callback: (analysisId2) => {
|
|
8906
|
+
return addFixCommentsForPr({
|
|
8907
|
+
analysisId: analysisId2,
|
|
8908
|
+
gqlClient,
|
|
8909
|
+
scm,
|
|
8910
|
+
scanner: z29.nativeEnum(SCANNERS).parse(scanner)
|
|
8911
|
+
});
|
|
8912
|
+
},
|
|
8913
|
+
callbackStates: ["Finished" /* Finished */]
|
|
8914
|
+
});
|
|
8915
|
+
}
|
|
8952
8916
|
|
|
8953
8917
|
// src/commands/index.ts
|
|
8954
8918
|
import chalk5 from "chalk";
|
|
@@ -9260,8 +9224,8 @@ var scmTokenOption = {
|
|
|
9260
9224
|
|
|
9261
9225
|
// src/args/validation.ts
|
|
9262
9226
|
import chalk7 from "chalk";
|
|
9263
|
-
import
|
|
9264
|
-
import { z as
|
|
9227
|
+
import path7 from "path";
|
|
9228
|
+
import { z as z30 } from "zod";
|
|
9265
9229
|
function throwRepoUrlErrorMessage({
|
|
9266
9230
|
error,
|
|
9267
9231
|
repoUrl,
|
|
@@ -9278,11 +9242,11 @@ Example:
|
|
|
9278
9242
|
)}`;
|
|
9279
9243
|
throw new CliError(formattedErrorMessage);
|
|
9280
9244
|
}
|
|
9281
|
-
var UrlZ =
|
|
9245
|
+
var UrlZ = z30.string({
|
|
9282
9246
|
invalid_type_error: `is not a valid ${Object.values(ScmType).join("/ ")} URL`
|
|
9283
9247
|
});
|
|
9284
9248
|
function validateOrganizationId(organizationId) {
|
|
9285
|
-
const orgIdValidation =
|
|
9249
|
+
const orgIdValidation = z30.string().uuid().nullish().safeParse(organizationId);
|
|
9286
9250
|
if (!orgIdValidation.success) {
|
|
9287
9251
|
throw new CliError(`organizationId: ${organizationId} is not a valid UUID`);
|
|
9288
9252
|
}
|
|
@@ -9304,7 +9268,7 @@ function validateRepoUrl(args) {
|
|
|
9304
9268
|
}
|
|
9305
9269
|
var supportExtensions = [".json", ".xml", ".fpr", ".sarif"];
|
|
9306
9270
|
function validateReportFileFormat(reportFile) {
|
|
9307
|
-
if (!supportExtensions.includes(
|
|
9271
|
+
if (!supportExtensions.includes(path7.extname(reportFile))) {
|
|
9308
9272
|
throw new CliError(
|
|
9309
9273
|
`
|
|
9310
9274
|
${chalk7.bold(
|
|
@@ -9347,7 +9311,7 @@ function analyzeBuilder(yargs2) {
|
|
|
9347
9311
|
).help();
|
|
9348
9312
|
}
|
|
9349
9313
|
function validateAnalyzeOptions(argv) {
|
|
9350
|
-
if (!
|
|
9314
|
+
if (!fs4.existsSync(argv.f)) {
|
|
9351
9315
|
throw new CliError(`
|
|
9352
9316
|
Can't access ${chalk8.bold(argv.f)}`);
|
|
9353
9317
|
}
|
|
@@ -9379,7 +9343,7 @@ async function analyzeHandler(args) {
|
|
|
9379
9343
|
}
|
|
9380
9344
|
|
|
9381
9345
|
// src/args/commands/review.ts
|
|
9382
|
-
import
|
|
9346
|
+
import fs5 from "node:fs";
|
|
9383
9347
|
import chalk9 from "chalk";
|
|
9384
9348
|
function reviewBuilder(yargs2) {
|
|
9385
9349
|
return yargs2.option("f", {
|
|
@@ -9409,14 +9373,14 @@ function reviewBuilder(yargs2) {
|
|
|
9409
9373
|
"Path to the repository folder with the source code"
|
|
9410
9374
|
),
|
|
9411
9375
|
type: "string",
|
|
9412
|
-
demandOption:
|
|
9376
|
+
demandOption: false
|
|
9413
9377
|
}).example(
|
|
9414
9378
|
"npx mobbdev@latest review -r https://github.com/WebGoat/WebGoat -f <your_vulnerability_report_path> --ch <pr_last_commit> --pr <pr_number> --ref <pr_branch_name> --api-key <api_key> --src-path <your_repo_path>",
|
|
9415
9379
|
"add fixes to your pr"
|
|
9416
9380
|
).help();
|
|
9417
9381
|
}
|
|
9418
9382
|
function validateReviewOptions(argv) {
|
|
9419
|
-
if (!
|
|
9383
|
+
if (!fs5.existsSync(argv.f)) {
|
|
9420
9384
|
throw new CliError(`
|
|
9421
9385
|
Can't access ${chalk9.bold(argv.f)}`);
|
|
9422
9386
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobbdev",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.58",
|
|
4
4
|
"description": "Automated secure code remediation tool",
|
|
5
5
|
"repository": "git+https://github.com/mobb-dev/bugsy.git",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"eslint-plugin-import": "2.31.0",
|
|
101
101
|
"eslint-plugin-prettier": "5.2.3",
|
|
102
102
|
"eslint-plugin-simple-import-sort": "10.0.0",
|
|
103
|
+
"nock": "14.0.1",
|
|
103
104
|
"prettier": "3.5.1",
|
|
104
105
|
"tsup": "7.2.0",
|
|
105
106
|
"typescript": "4.9.5",
|