@contrast/contrast 1.0.3 → 1.0.6
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/.prettierignore +4 -0
- package/README.md +20 -14
- package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
- package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
- package/dist/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +6 -14
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +29 -0
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +101 -234
- package/dist/audit/languageAnalysisEngine/report/models/reportLibraryModel.js +19 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +24 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +24 -0
- package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +12 -0
- package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +13 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +24 -129
- package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +99 -0
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +2 -14
- package/dist/commands/audit/auditConfig.js +8 -2
- package/dist/commands/audit/auditController.js +14 -5
- package/dist/commands/scan/processScan.js +10 -6
- package/dist/commands/scan/sca/scaAnalysis.js +49 -0
- package/dist/common/HTTPClient.js +18 -26
- package/dist/common/errorHandling.js +7 -17
- package/dist/common/versionChecker.js +14 -12
- package/dist/constants/constants.js +24 -2
- package/dist/constants/lambda.js +3 -1
- package/dist/constants/locales.js +42 -42
- package/dist/constants.js +25 -1
- package/dist/index.js +2 -2
- package/dist/lambda/help.js +22 -14
- package/dist/lambda/lambda.js +6 -0
- package/dist/scaAnalysis/common/formatMessage.js +19 -0
- package/dist/scaAnalysis/common/treeUpload.js +29 -0
- package/dist/scaAnalysis/go/goAnalysis.js +17 -0
- package/dist/scaAnalysis/go/goParseDeps.js +158 -0
- package/dist/scaAnalysis/go/goReadDepFile.js +23 -0
- package/dist/scaAnalysis/java/analysis.js +108 -0
- package/dist/scaAnalysis/java/index.js +18 -0
- package/dist/scaAnalysis/java/javaBuildDepsParser.js +339 -0
- package/dist/scan/autoDetection.js +46 -1
- package/dist/scan/fileUtils.js +73 -1
- package/dist/scan/formatScanOutput.js +215 -0
- package/dist/scan/help.js +3 -1
- package/dist/scan/models/groupedResultsModel.js +11 -0
- package/dist/scan/models/resultContentModel.js +2 -0
- package/dist/scan/models/scanResultsModel.js +11 -0
- package/dist/scan/scan.js +27 -126
- package/dist/scan/scanConfig.js +1 -1
- package/dist/scan/scanController.js +11 -5
- package/dist/scan/scanResults.js +15 -19
- package/dist/utils/getConfig.js +3 -0
- package/dist/utils/oraWrapper.js +5 -1
- package/package.json +3 -2
- package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
- package/src/audit/catalogueApplication/catalogueApplication.js +4 -16
- package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +11 -21
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +72 -0
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +204 -0
- package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +30 -0
- package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +32 -0
- package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +29 -0
- package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +13 -0
- package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +16 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +56 -0
- package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +116 -0
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +2 -22
- package/src/commands/audit/auditConfig.ts +12 -3
- package/src/commands/audit/auditController.ts +20 -5
- package/src/commands/audit/processAudit.ts +3 -0
- package/src/commands/scan/processScan.js +13 -9
- package/src/commands/scan/sca/scaAnalysis.js +75 -0
- package/src/common/HTTPClient.js +31 -38
- package/src/common/errorHandling.ts +7 -25
- package/src/common/versionChecker.ts +24 -22
- package/src/constants/constants.js +24 -2
- package/src/constants/lambda.js +3 -1
- package/src/constants/locales.js +47 -56
- package/src/constants.js +29 -1
- package/src/index.ts +2 -3
- package/src/lambda/help.ts +22 -14
- package/src/lambda/lambda.ts +8 -0
- package/src/scaAnalysis/common/formatMessage.js +20 -0
- package/src/scaAnalysis/common/treeUpload.js +30 -0
- package/src/scaAnalysis/go/goAnalysis.js +20 -0
- package/src/scaAnalysis/go/goParseDeps.js +203 -0
- package/src/scaAnalysis/go/goReadDepFile.js +32 -0
- package/src/scaAnalysis/java/analysis.js +143 -0
- package/src/scaAnalysis/java/index.js +21 -0
- package/src/scaAnalysis/java/javaBuildDepsParser.js +404 -0
- package/src/scan/autoDetection.js +54 -1
- package/src/scan/fileUtils.js +91 -1
- package/src/scan/formatScanOutput.ts +250 -0
- package/src/scan/help.js +3 -1
- package/src/scan/models/groupedResultsModel.ts +20 -0
- package/src/scan/models/resultContentModel.ts +86 -0
- package/src/scan/models/scanResultsModel.ts +52 -0
- package/src/scan/scan.ts +63 -0
- package/src/scan/scanConfig.js +1 -1
- package/src/scan/scanController.js +15 -7
- package/src/scan/scanResults.js +21 -18
- package/src/utils/getConfig.ts +10 -0
- package/src/utils/oraWrapper.js +6 -1
- package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -17
- package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -81
- package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -27
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +0 -303
- package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -124
- package/src/audit/languageAnalysisEngine/report/reportingFeature.js +0 -190
- package/src/scan/scan.js +0 -195
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReportOutputBodyModel = exports.ReportOutputHeaderModel = exports.ReportOutputModel = void 0;
|
|
4
|
+
class ReportOutputModel {
|
|
5
|
+
constructor(header, body) {
|
|
6
|
+
this.header = header;
|
|
7
|
+
this.body = body;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ReportOutputModel = ReportOutputModel;
|
|
11
|
+
class ReportOutputHeaderModel {
|
|
12
|
+
constructor(vulnMessage, introducesMessage) {
|
|
13
|
+
this.vulnMessage = vulnMessage;
|
|
14
|
+
this.introducesMessage = introducesMessage;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ReportOutputHeaderModel = ReportOutputHeaderModel;
|
|
18
|
+
class ReportOutputBodyModel {
|
|
19
|
+
constructor(bodyIssueMessage, bodyAdviceMessage) {
|
|
20
|
+
this.issueMessage = bodyIssueMessage;
|
|
21
|
+
this.adviceMessage = bodyAdviceMessage;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ReportOutputBodyModel = ReportOutputBodyModel;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReportSeverityModel = void 0;
|
|
4
|
+
class ReportSeverityModel {
|
|
5
|
+
constructor(severity, priority, outputColour, cveName) {
|
|
6
|
+
this.severity = severity;
|
|
7
|
+
this.priority = priority;
|
|
8
|
+
this.outputColour = outputColour;
|
|
9
|
+
this.cveName = cveName;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ReportSeverityModel = ReportSeverityModel;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeverityCountModel = void 0;
|
|
4
|
+
class SeverityCountModel {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.critical = 0;
|
|
7
|
+
this.high = 0;
|
|
8
|
+
this.medium = 0;
|
|
9
|
+
this.low = 0;
|
|
10
|
+
this.note = 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.SeverityCountModel = SeverityCountModel;
|
|
@@ -1,133 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (config['report']) {
|
|
14
|
-
const reportResponse = await commonReport.getReport(applicationId);
|
|
15
|
-
if (reportResponse !== undefined) {
|
|
16
|
-
const libraryVulnerabilityInput = createLibraryVulnerabilityInput(reportResponse.reports);
|
|
17
|
-
const libraryVulnerabilityResponse = await getLibraryVulnerabilities(libraryVulnerabilityInput, applicationId);
|
|
18
|
-
const severity = config['cve_severity'];
|
|
19
|
-
const id = applicationId;
|
|
20
|
-
const name = config.applicationName;
|
|
21
|
-
const hasSomeVulnerabilitiesReported = formatVulnerabilityOutput(libraryVulnerabilityResponse, severity, id, name, depRiskReportCount, config);
|
|
22
|
-
commonReport.analyseReportOptions(hasSomeVulnerabilitiesReported);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
const createLibraryVulnerabilityInput = report => {
|
|
27
|
-
const language = Object.keys(report[0].report)[0];
|
|
28
|
-
const reportTree = report[0].report[language].dependencyTree;
|
|
29
|
-
const libraries = reportTree[Object.keys(reportTree)[0]];
|
|
30
|
-
let gav = [];
|
|
31
|
-
for (const key of Object.keys(libraries)) {
|
|
32
|
-
gav.push({
|
|
33
|
-
name: libraries[key].name,
|
|
34
|
-
group: libraries[key].group,
|
|
35
|
-
version: libraries[key].resolved
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
name_group_versions: gav,
|
|
40
|
-
language: language.toUpperCase()
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
const oldCountSeverity = vulnerableLibraries => {
|
|
44
|
-
const severityCount = {
|
|
45
|
-
critical: 0,
|
|
46
|
-
high: 0,
|
|
47
|
-
medium: 0,
|
|
48
|
-
low: 0
|
|
49
|
-
};
|
|
50
|
-
vulnerableLibraries.forEach(lib => {
|
|
51
|
-
lib.vulns.forEach(vuln => {
|
|
52
|
-
if (vuln.severity_code === 'HIGH') {
|
|
53
|
-
severityCount['high'] += 1;
|
|
54
|
-
}
|
|
55
|
-
else if (vuln.severity_code === 'MEDIUM') {
|
|
56
|
-
severityCount['medium'] += 1;
|
|
57
|
-
}
|
|
58
|
-
else if (vuln.severity_code === 'LOW') {
|
|
59
|
-
severityCount['low'] += 1;
|
|
60
|
-
}
|
|
61
|
-
else if (vuln.severity_code === 'CRITICAL') {
|
|
62
|
-
severityCount['critical'] += 1;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
return severityCount;
|
|
67
|
-
};
|
|
68
|
-
const parseVulnerabilites = libraryVulnerabilityResponse => {
|
|
69
|
-
let parsedVulnerabilites = {};
|
|
70
|
-
let vulnName = libraryVulnerabilityResponse.libraries;
|
|
71
|
-
for (let x in vulnName) {
|
|
72
|
-
let vuln = vulnName[x].vulns;
|
|
73
|
-
if (vuln.length > 0) {
|
|
74
|
-
let libname = vulnName[x].group +
|
|
75
|
-
'/' +
|
|
76
|
-
vulnName[x].file_name +
|
|
77
|
-
'@' +
|
|
78
|
-
vulnName[x].file_version;
|
|
79
|
-
parsedVulnerabilites[libname] = vulnName[x].vulns;
|
|
80
|
-
}
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatVulnerabilityOutput = exports.vulnerabilityReport = void 0;
|
|
4
|
+
const commonReportingFunctions_1 = require("./commonReportingFunctions");
|
|
5
|
+
const reportUtils_1 = require("./utils/reportUtils");
|
|
6
|
+
async function vulnerabilityReport(analysis, applicationId, reportId) {
|
|
7
|
+
const reportResponse = await (0, commonReportingFunctions_1.getReport)(analysis.config, reportId);
|
|
8
|
+
if (reportResponse !== undefined) {
|
|
9
|
+
const id = applicationId;
|
|
10
|
+
const name = analysis.config.applicationName;
|
|
11
|
+
formatVulnerabilityOutput(reportResponse.vulnerabilities, id, name, analysis.config);
|
|
81
12
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return data.vulns.length > 0;
|
|
87
|
-
});
|
|
13
|
+
}
|
|
14
|
+
exports.vulnerabilityReport = vulnerabilityReport;
|
|
15
|
+
function formatVulnerabilityOutput(libraryVulnerabilityResponse, id, name, config) {
|
|
16
|
+
const vulnerableLibraries = (0, reportUtils_1.convertGenericToTypedLibraries)(libraryVulnerabilityResponse);
|
|
88
17
|
const numberOfVulnerableLibraries = vulnerableLibraries.length;
|
|
89
18
|
let numberOfCves = 0;
|
|
90
|
-
vulnerableLibraries.forEach(lib => (numberOfCves += lib.
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (depRiskReportCount && depRiskReportCount.scopedCount === 0) {
|
|
101
|
-
console.log(' No private libraries that are not scoped detected');
|
|
102
|
-
}
|
|
103
|
-
console.log(' \n Please go to the Contrast UI to view your dependency tree: \n' +
|
|
104
|
-
` \n ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`);
|
|
105
|
-
return [hasSomeVulnerabilitiesReported, numberOfCves, severityCount];
|
|
106
|
-
};
|
|
107
|
-
const getLibraryVulnerabilities = async (input, applicationId) => {
|
|
108
|
-
const requestBody = input;
|
|
109
|
-
const addParams = agent.getAdditionalParams();
|
|
110
|
-
const userParams = await util.getParams(applicationId);
|
|
111
|
-
const protocol = getValidHost(userParams.host);
|
|
112
|
-
const client = commonApi.getHttpClient(userParams, protocol, addParams);
|
|
113
|
-
return client
|
|
114
|
-
.getLibraryVulnerabilities(requestBody, userParams)
|
|
115
|
-
.then(res => {
|
|
116
|
-
if (res.statusCode === 200) {
|
|
117
|
-
displaySuccessMessageVulnerabilities();
|
|
118
|
-
return res.body;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
handleResponseErrors(res, 'vulnerabilities');
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
.catch(err => {
|
|
125
|
-
console.log(err);
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
module.exports = {
|
|
129
|
-
vulnerabilityReport: vulnerabilityReport,
|
|
130
|
-
getLibraryVulnerabilities: getLibraryVulnerabilities,
|
|
131
|
-
formatVulnerabilityOutput: formatVulnerabilityOutput,
|
|
132
|
-
createLibraryVulnerabilityInput: createLibraryVulnerabilityInput
|
|
133
|
-
};
|
|
19
|
+
vulnerableLibraries.forEach(lib => (numberOfCves += lib.cveArray.length));
|
|
20
|
+
(0, commonReportingFunctions_1.createLibraryHeader)(id, numberOfVulnerableLibraries, numberOfCves);
|
|
21
|
+
const hasSomeVulnerabilitiesReported = (0, commonReportingFunctions_1.printVulnerabilityResponse)(vulnerableLibraries, config);
|
|
22
|
+
return [
|
|
23
|
+
hasSomeVulnerabilitiesReported,
|
|
24
|
+
numberOfCves,
|
|
25
|
+
(0, reportUtils_1.severityCountAllLibraries)(vulnerableLibraries)
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
exports.formatVulnerabilityOutput = formatVulnerabilityOutput;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findNameAndVersion = exports.severityCountSingleCVE = exports.severityCountAllCVEs = exports.severityCountAllLibraries = exports.convertGenericToTypedLibraries = exports.findCVESeverity = exports.findCVESeveritiesAndOrderByHighestPriority = exports.findHighestSeverityCVE = void 0;
|
|
7
|
+
const reportLibraryModel_1 = require("../models/reportLibraryModel");
|
|
8
|
+
const reportSeverityModel_1 = require("../models/reportSeverityModel");
|
|
9
|
+
const constants_1 = __importDefault(require("../../../languageAnalysisEngine/constants"));
|
|
10
|
+
const constants_2 = require("../../../../constants/constants");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
const severityCountModel_1 = require("../models/severityCountModel");
|
|
13
|
+
const { supportedLanguages: { GO } } = constants_1.default;
|
|
14
|
+
function findHighestSeverityCVE(cveArray) {
|
|
15
|
+
const mappedToReportSeverityModels = cveArray.map(cve => findCVESeverity(cve));
|
|
16
|
+
return (0, lodash_1.orderBy)(mappedToReportSeverityModels, cve => cve?.priority)[0];
|
|
17
|
+
}
|
|
18
|
+
exports.findHighestSeverityCVE = findHighestSeverityCVE;
|
|
19
|
+
function findCVESeveritiesAndOrderByHighestPriority(cves) {
|
|
20
|
+
return (0, lodash_1.orderBy)(cves.map(cve => findCVESeverity(cve)), ['priority'], ['asc']);
|
|
21
|
+
}
|
|
22
|
+
exports.findCVESeveritiesAndOrderByHighestPriority = findCVESeveritiesAndOrderByHighestPriority;
|
|
23
|
+
function findCVESeverity(cve) {
|
|
24
|
+
const cveName = cve.name;
|
|
25
|
+
if (cve.cvss3SeverityCode === 'CRITICAL' || cve.severityCode === 'CRITICAL') {
|
|
26
|
+
return new reportSeverityModel_1.ReportSeverityModel('CRITICAL', constants_2.CRITICAL_PRIORITY, constants_2.CRITICAL_COLOUR, cveName);
|
|
27
|
+
}
|
|
28
|
+
else if (cve.cvss3SeverityCode === 'HIGH' || cve.severityCode === 'HIGH') {
|
|
29
|
+
return new reportSeverityModel_1.ReportSeverityModel('HIGH', constants_2.HIGH_PRIORITY, constants_2.HIGH_COLOUR, cveName);
|
|
30
|
+
}
|
|
31
|
+
else if (cve.cvss3SeverityCode === 'MEDIUM' || cve.severityCode === 'MEDIUM') {
|
|
32
|
+
return new reportSeverityModel_1.ReportSeverityModel('MEDIUM', constants_2.MEDIUM_PRIORITY, constants_2.MEDIUM_COLOUR, cveName);
|
|
33
|
+
}
|
|
34
|
+
else if (cve.cvss3SeverityCode === 'LOW' || cve.severityCode === 'LOW') {
|
|
35
|
+
return new reportSeverityModel_1.ReportSeverityModel('LOW', constants_2.LOW_PRIORITY, constants_2.LOW_COLOUR, cveName);
|
|
36
|
+
}
|
|
37
|
+
else if (cve.cvss3SeverityCode === 'NOTE' || cve.severityCode === 'NOTE') {
|
|
38
|
+
return new reportSeverityModel_1.ReportSeverityModel('NOTE', constants_2.NOTE_PRIORITY, constants_2.NOTE_COLOUR, cveName);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.findCVESeverity = findCVESeverity;
|
|
42
|
+
function convertGenericToTypedLibraries(libraries) {
|
|
43
|
+
return Object.entries(libraries).map(([name, cveArray]) => {
|
|
44
|
+
return new reportLibraryModel_1.ReportLibraryModel(name, cveArray);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.convertGenericToTypedLibraries = convertGenericToTypedLibraries;
|
|
48
|
+
function severityCountAllLibraries(vulnerableLibraries) {
|
|
49
|
+
const severityCount = new severityCountModel_1.SeverityCountModel();
|
|
50
|
+
vulnerableLibraries.forEach(lib => severityCountAllCVEs(lib.cveArray, severityCount));
|
|
51
|
+
return severityCount;
|
|
52
|
+
}
|
|
53
|
+
exports.severityCountAllLibraries = severityCountAllLibraries;
|
|
54
|
+
function severityCountAllCVEs(cveArray, severityCount) {
|
|
55
|
+
const severityCountInner = severityCount;
|
|
56
|
+
cveArray.forEach(cve => severityCountSingleCVE(cve, severityCountInner));
|
|
57
|
+
return severityCountInner;
|
|
58
|
+
}
|
|
59
|
+
exports.severityCountAllCVEs = severityCountAllCVEs;
|
|
60
|
+
function severityCountSingleCVE(cve, severityCount) {
|
|
61
|
+
if (cve.cvss3SeverityCode === 'CRITICAL' ||
|
|
62
|
+
cve.severityCode === 'CRITICAL') {
|
|
63
|
+
severityCount.critical += 1;
|
|
64
|
+
}
|
|
65
|
+
else if (cve.cvss3SeverityCode === 'HIGH' ||
|
|
66
|
+
cve.severityCode === 'HIGH') {
|
|
67
|
+
severityCount.high += 1;
|
|
68
|
+
}
|
|
69
|
+
else if (cve.cvss3SeverityCode === 'MEDIUM' ||
|
|
70
|
+
cve.severityCode === 'MEDIUM') {
|
|
71
|
+
severityCount.medium += 1;
|
|
72
|
+
}
|
|
73
|
+
else if (cve.cvss3SeverityCode === 'LOW' ||
|
|
74
|
+
cve.severityCode === 'LOW') {
|
|
75
|
+
severityCount.low += 1;
|
|
76
|
+
}
|
|
77
|
+
else if (cve.cvss3SeverityCode === 'NOTE' ||
|
|
78
|
+
cve.severityCode === 'NOTE') {
|
|
79
|
+
severityCount.note += 1;
|
|
80
|
+
}
|
|
81
|
+
return severityCount;
|
|
82
|
+
}
|
|
83
|
+
exports.severityCountSingleCVE = severityCountSingleCVE;
|
|
84
|
+
function findNameAndVersion(library, config) {
|
|
85
|
+
if (config.language.toUpperCase() === GO) {
|
|
86
|
+
const nameVersion = library.name.split('@');
|
|
87
|
+
const name = nameVersion[0];
|
|
88
|
+
const version = nameVersion[1];
|
|
89
|
+
return { name, version };
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const splitLibraryName = library.name.split('/');
|
|
93
|
+
const nameVersion = splitLibraryName[1].split('@');
|
|
94
|
+
const name = nameVersion[0];
|
|
95
|
+
const version = nameVersion[1];
|
|
96
|
+
return { name, version };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.findNameAndVersion = findNameAndVersion;
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const prettyjson = require('prettyjson');
|
|
3
|
-
const i18n = require('i18n');
|
|
4
2
|
const { getHttpClient } = require('../../utils/commonApi');
|
|
5
3
|
const { handleResponseErrors } = require('../../common/errorHandling');
|
|
6
4
|
const { APP_VERSION } = require('../../constants/constants');
|
|
7
|
-
|
|
8
|
-
console.log('\n **************************' +
|
|
9
|
-
i18n.__('successHeader') +
|
|
10
|
-
'************************** ');
|
|
11
|
-
console.log('\n' + i18n.__('snapshotSuccessMessage') + '\n');
|
|
12
|
-
console.log(` ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`);
|
|
13
|
-
console.log('\n ***********************************************************');
|
|
14
|
-
}
|
|
15
|
-
const newSendSnapShot = async (analysis, applicationId) => {
|
|
5
|
+
const newSendSnapShot = async (analysis) => {
|
|
16
6
|
const analysisLanguage = analysis.config.language.toLowerCase();
|
|
17
7
|
const requestBody = {
|
|
18
8
|
appID: analysis.config.applicationId,
|
|
@@ -24,7 +14,6 @@ const newSendSnapShot = async (analysis, applicationId) => {
|
|
|
24
14
|
.sendSnapshot(requestBody, analysis.config)
|
|
25
15
|
.then(res => {
|
|
26
16
|
if (res.statusCode === 201) {
|
|
27
|
-
displaySnapshotSuccessMessage(analysis.config);
|
|
28
17
|
return res.body;
|
|
29
18
|
}
|
|
30
19
|
else {
|
|
@@ -36,6 +25,5 @@ const newSendSnapShot = async (analysis, applicationId) => {
|
|
|
36
25
|
});
|
|
37
26
|
};
|
|
38
27
|
module.exports = {
|
|
39
|
-
newSendSnapShot: newSendSnapShot
|
|
40
|
-
displaySnapshotSuccessMessage: displaySnapshotSuccessMessage
|
|
28
|
+
newSendSnapShot: newSendSnapShot
|
|
41
29
|
};
|
|
@@ -8,14 +8,20 @@ const paramHandler_1 = __importDefault(require("../../utils/paramsUtil/paramHand
|
|
|
8
8
|
const constants_1 = __importDefault(require("../../constants"));
|
|
9
9
|
const parsedCLIOptions_1 = __importDefault(require("../../utils/parsedCLIOptions"));
|
|
10
10
|
const constants_2 = __importDefault(require("../../audit/languageAnalysisEngine/constants"));
|
|
11
|
+
const autoDetectLanguage_1 = require("../../audit/autodetection/autoDetectLanguage");
|
|
11
12
|
const { supportedLanguages: { NODE, JAVASCRIPT } } = constants_2.default;
|
|
12
13
|
const getAuditConfig = (argv) => {
|
|
13
14
|
const auditParameters = parsedCLIOptions_1.default.getCommandLineArgsCustom(argv, constants_1.default.commandLineDefinitions.auditOptionDefinitions);
|
|
14
15
|
const paramsAuth = paramHandler_1.default.getAuth(auditParameters);
|
|
15
16
|
if (auditParameters.language === undefined ||
|
|
16
17
|
auditParameters.language === null) {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
try {
|
|
19
|
+
auditParameters.language = (0, autoDetectLanguage_1.determineProjectLanguage)((0, autoDetectLanguage_1.identifyLanguages)(auditParameters));
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.log(err.message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
else if (auditParameters.language.toUpperCase() === JAVASCRIPT) {
|
|
21
27
|
auditParameters.language = NODE.toLowerCase();
|
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.startAudit = void 0;
|
|
6
|
+
exports.startAudit = exports.dealWithNoAppId = void 0;
|
|
7
7
|
const catalogueApplication_1 = require("../../audit/catalogueApplication/catalogueApplication");
|
|
8
8
|
const commonApi_1 = __importDefault(require("../../audit/languageAnalysisEngine/commonApi"));
|
|
9
9
|
const identifyLanguageAE = require('./../../audit/languageAnalysisEngine');
|
|
10
|
-
const languageFactory = require('
|
|
10
|
+
const languageFactory = require('../../audit/languageAnalysisEngine/languageAnalysisFactory');
|
|
11
|
+
const { v4: uuidv4 } = require('uuid');
|
|
11
12
|
const dealWithNoAppId = async (config) => {
|
|
12
13
|
let appID;
|
|
13
14
|
try {
|
|
@@ -15,16 +16,24 @@ const dealWithNoAppId = async (config) => {
|
|
|
15
16
|
if (!appID && config.applicationName) {
|
|
16
17
|
return await (0, catalogueApplication_1.catalogueApplication)(config);
|
|
17
18
|
}
|
|
19
|
+
if (!appID && !config.applicationName) {
|
|
20
|
+
config.applicationName = uuidv4();
|
|
21
|
+
return await (0, catalogueApplication_1.catalogueApplication)(config);
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
catch (e) {
|
|
20
|
-
|
|
25
|
+
if (e.toString().includes('tunneling socket could not be established')) {
|
|
26
|
+
console.log(e.message.toString());
|
|
27
|
+
console.log('There seems to be an issue with your proxy, please check and try again');
|
|
28
|
+
}
|
|
29
|
+
process.exit(1);
|
|
21
30
|
}
|
|
22
|
-
console.log(appID);
|
|
23
31
|
return appID;
|
|
24
32
|
};
|
|
33
|
+
exports.dealWithNoAppId = dealWithNoAppId;
|
|
25
34
|
const startAudit = async (config) => {
|
|
26
35
|
if (!config.applicationId) {
|
|
27
|
-
config.applicationId = await dealWithNoAppId(config);
|
|
36
|
+
config.applicationId = await (0, exports.dealWithNoAppId)(config);
|
|
28
37
|
}
|
|
29
38
|
identifyLanguageAE(config.projectPath, languageFactory, config.applicationId, config);
|
|
30
39
|
};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const { startScan } = require('../../scan/scanController');
|
|
3
|
-
const { formatScanOutput } = require('../../scan/scan');
|
|
4
|
-
const { scanUsageGuide } = require('../../scan/help');
|
|
5
2
|
const scanConfig = require('../../scan/scanConfig');
|
|
3
|
+
const { startScan } = require('../../scan/scanController');
|
|
6
4
|
const { saveScanFile } = require('../../utils/saveFile');
|
|
5
|
+
const { ScanResultsModel } = require('../../scan/models/scanResultsModel');
|
|
6
|
+
const { formatScanOutput } = require('../../scan/formatScanOutput');
|
|
7
|
+
const { processSca } = require('./sca/scaAnalysis');
|
|
7
8
|
const processScan = async (argvMain) => {
|
|
8
9
|
let config = scanConfig.getScanConfig(argvMain);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
if (config.experimental) {
|
|
11
|
+
await processSca(config);
|
|
12
|
+
}
|
|
13
|
+
let scanResults = new ScanResultsModel(await startScan(config));
|
|
14
|
+
if (scanResults.scanResultsInstances !== undefined) {
|
|
15
|
+
formatScanOutput(scanResults);
|
|
12
16
|
}
|
|
13
17
|
if (config.save !== undefined) {
|
|
14
18
|
await saveScanFile(config, scanResults);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const autoDetection = require('../../../scan/autoDetection');
|
|
3
|
+
const javaAnalysis = require('../../../scaAnalysis/java');
|
|
4
|
+
const treeUpload = require('../../../scaAnalysis/common/treeUpload');
|
|
5
|
+
const { manualDetectAuditFilesAndLanguages } = require('../../../scan/autoDetection');
|
|
6
|
+
const auditController = require('../../audit/auditController');
|
|
7
|
+
const { supportedLanguages: { JAVA, GO } } = require('../../../audit/languageAnalysisEngine/constants');
|
|
8
|
+
const goAnalysis = require('../../../scaAnalysis/go/goAnalysis');
|
|
9
|
+
const processSca = async (config) => {
|
|
10
|
+
let filesFound;
|
|
11
|
+
if (config.projectPath) {
|
|
12
|
+
filesFound = await manualDetectAuditFilesAndLanguages(config.projectPath);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config);
|
|
16
|
+
}
|
|
17
|
+
let messageToSend = undefined;
|
|
18
|
+
if (filesFound.length === 1) {
|
|
19
|
+
switch (Object.keys(filesFound[0])[0]) {
|
|
20
|
+
case JAVA:
|
|
21
|
+
messageToSend = javaAnalysis.javaAnalysis(config, filesFound[0]);
|
|
22
|
+
config.language = JAVA;
|
|
23
|
+
break;
|
|
24
|
+
case GO:
|
|
25
|
+
messageToSend = goAnalysis.goAnalysis(config, filesFound[0]);
|
|
26
|
+
config.language = GO;
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
console.log('language detected not supported');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!config.applicationId) {
|
|
33
|
+
config.applicationId = await auditController.dealWithNoAppId(config);
|
|
34
|
+
}
|
|
35
|
+
console.log('processing dependencies');
|
|
36
|
+
const response = await treeUpload.commonSendSnapShot(messageToSend, config);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (filesFound.length === 0) {
|
|
40
|
+
console.log('no compatible dependency files detected. Continuing...');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.log('multiple language files detected, please use --project-path to specify a directory or the file where dependencies are declared');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
module.exports = {
|
|
48
|
+
processSca
|
|
49
|
+
};
|
|
@@ -77,7 +77,9 @@ HTTPClient.prototype.getScanId = function getScanId(config, codeArtifactId) {
|
|
|
77
77
|
options.url = url;
|
|
78
78
|
options.body = {
|
|
79
79
|
codeArtifactId: codeArtifactId,
|
|
80
|
-
label:
|
|
80
|
+
label: config.label
|
|
81
|
+
? config.label
|
|
82
|
+
: `Started by CLI tool at ${new Date().toString()}`
|
|
81
83
|
};
|
|
82
84
|
return requestUtils.sendRequest({ method: 'post', options });
|
|
83
85
|
};
|
|
@@ -143,28 +145,27 @@ HTTPClient.prototype.catalogueCommand = function catalogueCommand(config) {
|
|
|
143
145
|
return requestUtils.sendRequest({ method: 'post', options });
|
|
144
146
|
};
|
|
145
147
|
HTTPClient.prototype.sendSnapshot = function sendSnapshot(requestBody, config) {
|
|
148
|
+
if (config.language.toUpperCase() === 'RUBY') {
|
|
149
|
+
}
|
|
146
150
|
const options = _.cloneDeep(this.requestOptions);
|
|
147
151
|
let url = createSnapshotURL(config);
|
|
148
152
|
options.url = url;
|
|
149
153
|
options.body = requestBody;
|
|
150
154
|
return requestUtils.sendRequest({ method: 'post', options });
|
|
151
155
|
};
|
|
152
|
-
HTTPClient.prototype.
|
|
153
|
-
const options = _.cloneDeep(this.requestOptions);
|
|
154
|
-
let url = createReportUrl(config);
|
|
155
|
-
options.url = url;
|
|
156
|
-
return requestUtils.sendRequest({ method: 'get', options });
|
|
157
|
-
};
|
|
158
|
-
HTTPClient.prototype.getSpecificReport = function getSpecificReport(config, reportId) {
|
|
156
|
+
HTTPClient.prototype.getReportById = function getReportById(config, reportId) {
|
|
159
157
|
const options = _.cloneDeep(this.requestOptions);
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
if (config.ignoreDev) {
|
|
159
|
+
options.url = createSpecificReportWithProdUrl(config, reportId);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
options.url = createSpecificReportUrl(config, reportId);
|
|
163
|
+
}
|
|
162
164
|
return requestUtils.sendRequest({ method: 'get', options });
|
|
163
165
|
};
|
|
164
|
-
HTTPClient.prototype.getLibraryVulnerabilities = function getLibraryVulnerabilities(
|
|
166
|
+
HTTPClient.prototype.getLibraryVulnerabilities = function getLibraryVulnerabilities(config, requestBody) {
|
|
165
167
|
const options = _.cloneDeep(this.requestOptions);
|
|
166
|
-
|
|
167
|
-
options.url = url;
|
|
168
|
+
options.url = createLibraryVulnerabilitiesUrl(config);
|
|
168
169
|
options.body = requestBody;
|
|
169
170
|
return requestUtils.sendRequest({ method: 'put', options });
|
|
170
171
|
};
|
|
@@ -174,12 +175,6 @@ HTTPClient.prototype.getAppId = function getAppId(config) {
|
|
|
174
175
|
options.url = url;
|
|
175
176
|
return requestUtils.sendRequest({ method: 'get', options });
|
|
176
177
|
};
|
|
177
|
-
HTTPClient.prototype.getDependencyTree = function getReport(orgUuid, appId, reportId) {
|
|
178
|
-
const options = _.cloneDeep(this.requestOptions);
|
|
179
|
-
let url = createGetDependencyTree(options.uri, orgUuid, appId, reportId);
|
|
180
|
-
options.url = url;
|
|
181
|
-
return requestUtils.sendRequest({ method: 'get', options });
|
|
182
|
-
};
|
|
183
178
|
function getServerlessHost(config = {}) {
|
|
184
179
|
const originalHost = config?.host || config?.get('host');
|
|
185
180
|
const host = originalHost?.endsWith('/')
|
|
@@ -271,18 +266,15 @@ const createAppNameUrl = config => {
|
|
|
271
266
|
function createLibraryVulnerabilitiesUrl(config) {
|
|
272
267
|
return `${config.host}/Contrast/api/ng/${config.organizationId}/libraries/artifactsByGroupNameVersion`;
|
|
273
268
|
}
|
|
274
|
-
function createReportUrl(config) {
|
|
275
|
-
return `${config.host}/Contrast/api/ng/sca/organizations/${config.organizationId}/applications/${config.applicationId}/reports`;
|
|
276
|
-
}
|
|
277
269
|
function createSpecificReportUrl(config, reportId) {
|
|
278
|
-
return `${config.host}/Contrast/api/ng/sca/organizations/${config.organizationId}/applications/${config.applicationId}/reports/${reportId}
|
|
270
|
+
return `${config.host}/Contrast/api/ng/sca/organizations/${config.organizationId}/applications/${config.applicationId}/reports/${reportId}`;
|
|
271
|
+
}
|
|
272
|
+
function createSpecificReportWithProdUrl(config, reportId) {
|
|
273
|
+
return createSpecificReportUrl(config, reportId).concat(`?nodesToInclude=PROD`);
|
|
279
274
|
}
|
|
280
275
|
function createDataUrl() {
|
|
281
276
|
return `https://ardy.contrastsecurity.com/production`;
|
|
282
277
|
}
|
|
283
|
-
const createGetDependencyTree = (protocol, orgUuid, appId, reportId) => {
|
|
284
|
-
return `${protocol}/Contrast/api/ng/sca/organizations/${orgUuid}/applications/${appId}/reports/${reportId}`;
|
|
285
|
-
};
|
|
286
278
|
function createSbomCycloneDXUrl(config) {
|
|
287
279
|
return `${config.host}/Contrast/api/ng/${config.organizationId}/applications/${config.applicationId}/libraries/sbom/cyclonedx`;
|
|
288
280
|
}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.findCommandOnError = exports.libraryAnalysisError = exports.handleResponseErrors = exports.getErrorMessage = exports.generalError = exports.
|
|
6
|
+
exports.reportFailureError = exports.vulnerabilitiesFailureError = exports.snapshotFailureError = exports.findCommandOnError = exports.libraryAnalysisError = exports.handleResponseErrors = exports.getErrorMessage = exports.generalError = exports.failOptionError = exports.proxyError = exports.forbiddenError = exports.badRequestError = exports.unauthenticatedError = exports.genericError = void 0;
|
|
7
7
|
const i18n_1 = __importDefault(require("i18n"));
|
|
8
8
|
const handleResponseErrors = (res, api) => {
|
|
9
9
|
if (res.statusCode === 400) {
|
|
@@ -36,23 +36,17 @@ const libraryAnalysisError = () => {
|
|
|
36
36
|
};
|
|
37
37
|
exports.libraryAnalysisError = libraryAnalysisError;
|
|
38
38
|
const snapshotFailureError = () => {
|
|
39
|
-
console.log('
|
|
40
|
-
i18n_1.default.__('snapshotFailureHeader') +
|
|
41
|
-
' *********************************\n' +
|
|
42
|
-
i18n_1.default.__('snapshotFailureMessage'));
|
|
39
|
+
console.log(i18n_1.default.__('snapshotFailureMessage'));
|
|
43
40
|
};
|
|
41
|
+
exports.snapshotFailureError = snapshotFailureError;
|
|
44
42
|
const vulnerabilitiesFailureError = () => {
|
|
45
|
-
console.log('
|
|
46
|
-
i18n_1.default.__('snapshotFailureHeader') +
|
|
47
|
-
' *********************************\n' +
|
|
48
|
-
i18n_1.default.__('vulnerabilitiesFailureMessage'));
|
|
43
|
+
console.log(i18n_1.default.__('vulnerabilitiesFailureMessage'));
|
|
49
44
|
};
|
|
45
|
+
exports.vulnerabilitiesFailureError = vulnerabilitiesFailureError;
|
|
50
46
|
const reportFailureError = () => {
|
|
51
|
-
console.log('
|
|
52
|
-
i18n_1.default.__('snapshotFailureHeader') +
|
|
53
|
-
' *********************************\n' +
|
|
54
|
-
i18n_1.default.__('reportFailureMessage'));
|
|
47
|
+
console.log(i18n_1.default.__('auditReportFailureMessage'));
|
|
55
48
|
};
|
|
49
|
+
exports.reportFailureError = reportFailureError;
|
|
56
50
|
const genericError = (missingCliOption) => {
|
|
57
51
|
console.log(`*************************** ${i18n_1.default.__('yamlMissingParametersHeader')} ***************************\n${missingCliOption}`);
|
|
58
52
|
console.error(i18n_1.default.__('yamlMissingParametersMessage'));
|
|
@@ -78,10 +72,6 @@ const proxyError = () => {
|
|
|
78
72
|
generalError('proxyErrorHeader', 'proxyErrorMessage');
|
|
79
73
|
};
|
|
80
74
|
exports.proxyError = proxyError;
|
|
81
|
-
const hostWarningError = () => {
|
|
82
|
-
console.log(i18n_1.default.__('snapshotHostMessage'));
|
|
83
|
-
};
|
|
84
|
-
exports.hostWarningError = hostWarningError;
|
|
85
75
|
const failOptionError = () => {
|
|
86
76
|
console.log('\n ******************************** ' +
|
|
87
77
|
i18n_1.default.__('snapshotFailureHeader') +
|