@contrast/contrast 1.0.12 → 1.0.14
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/audit/report/commonReportingFunctions.js +175 -116
- package/dist/audit/report/models/reportSeverityModel.js +3 -3
- package/dist/audit/report/reportingFeature.js +1 -10
- package/dist/audit/report/utils/reportUtils.js +4 -4
- package/dist/commands/audit/processAudit.js +10 -0
- package/dist/commands/scan/processScan.js +9 -0
- package/dist/commands/scan/sca/scaAnalysis.js +2 -0
- package/dist/common/HTTPClient.js +30 -2
- package/dist/common/errorHandling.js +1 -2
- package/dist/common/fail.js +7 -3
- package/dist/common/versionChecker.js +11 -5
- package/dist/constants/constants.js +1 -1
- package/dist/constants/locales.js +16 -8
- package/dist/constants.js +2 -2
- package/dist/index.js +5 -3
- package/dist/lambda/lambda.js +8 -1
- package/dist/scaAnalysis/common/auditReport.js +78 -0
- package/dist/scaAnalysis/common/scaServicesUpload.js +53 -0
- package/dist/scaAnalysis/javascript/index.js +4 -0
- package/dist/scaAnalysis/javascript/scaServiceParser.js +109 -0
- package/dist/scaAnalysis/ruby/analysis.js +106 -9
- package/dist/scaAnalysis/ruby/index.js +6 -1
- package/dist/scan/formatScanOutput.js +4 -29
- package/dist/scan/scanResults.js +1 -1
- package/dist/{audit/languageAnalysisEngine/util → utils}/capabilities.js +0 -0
- package/dist/{audit/languageAnalysisEngine/util → utils}/generalAPI.js +14 -5
- package/package.json +4 -1
- package/src/audit/report/commonReportingFunctions.js +432 -0
- package/src/audit/report/models/reportSeverityModel.ts +6 -6
- package/src/audit/report/reportingFeature.ts +2 -16
- package/src/audit/report/utils/reportUtils.ts +2 -8
- package/src/commands/audit/processAudit.ts +8 -0
- package/src/commands/scan/processScan.js +14 -0
- package/src/commands/scan/sca/scaAnalysis.js +9 -0
- package/src/common/HTTPClient.js +44 -2
- package/src/common/errorHandling.ts +1 -2
- package/src/common/fail.js +7 -3
- package/src/common/versionChecker.ts +16 -6
- package/src/constants/constants.js +1 -1
- package/src/constants/locales.js +17 -9
- package/src/constants.js +2 -2
- package/src/index.ts +5 -8
- package/src/lambda/lambda.ts +13 -1
- package/src/lambda/lambdaUtils.ts +1 -1
- package/src/scaAnalysis/common/auditReport.js +108 -0
- package/src/scaAnalysis/common/scaServicesUpload.js +56 -0
- package/src/scaAnalysis/javascript/index.js +4 -0
- package/src/scaAnalysis/javascript/scaServiceParser.js +145 -0
- package/src/scaAnalysis/ruby/analysis.js +137 -9
- package/src/scaAnalysis/ruby/index.js +6 -1
- package/src/scan/formatScanOutput.ts +5 -42
- package/src/scan/scanResults.js +1 -1
- package/src/{audit/languageAnalysisEngine/util → utils}/capabilities.js +0 -0
- package/src/{audit/languageAnalysisEngine/util → utils}/generalAPI.js +16 -6
- package/src/audit/report/commonReportingFunctions.ts +0 -355
|
@@ -1,72 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const reportOutputModel_1 = require("./models/reportOutputModel");
|
|
14
|
-
const constants_1 = require("../../constants/constants");
|
|
15
|
-
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
16
|
-
const reportGuidanceModel_1 = require("./models/reportGuidanceModel");
|
|
2
|
+
const commonApi = require('../../utils/commonApi');
|
|
3
|
+
const { ReportCompositeKey, ReportList, ReportModelStructure } = require('./models/reportListModel');
|
|
4
|
+
const { orderBy } = require('lodash');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const { countVulnerableLibrariesBySeverity, orderByHighestPriority, findHighestSeverityCVE, findNameAndVersion, severityCountAllCVEs, findCVESeverity } = require('./utils/reportUtils');
|
|
7
|
+
const { SeverityCountModel } = require('./models/severityCountModel');
|
|
8
|
+
const { ReportOutputBodyModel, ReportOutputHeaderModel, ReportOutputModel } = require('./models/reportOutputModel');
|
|
9
|
+
const { CE_URL, CRITICAL_COLOUR, HIGH_COLOUR, LOW_COLOUR, MEDIUM_COLOUR, NOTE_COLOUR } = require('../../constants/constants');
|
|
10
|
+
const Table = require('cli-table3');
|
|
11
|
+
const { ReportGuidanceModel } = require('./models/reportGuidanceModel');
|
|
12
|
+
const i18n = require('i18n');
|
|
17
13
|
const createSummaryMessageTop = (numberOfVulnerableLibraries, numberOfCves) => {
|
|
18
14
|
numberOfVulnerableLibraries === 1
|
|
19
15
|
? console.log(`Found 1 vulnerable library containing ${numberOfCves} CVE`)
|
|
20
16
|
: console.log(`Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVEs`);
|
|
21
17
|
};
|
|
22
|
-
|
|
23
|
-
const createSummaryMessageBottom = (numberOfVulnerableLibraries) => {
|
|
18
|
+
const createSummaryMessageBottom = numberOfVulnerableLibraries => {
|
|
24
19
|
numberOfVulnerableLibraries === 1
|
|
25
|
-
? console.log(`Found 1
|
|
26
|
-
: console.log(`Found ${numberOfVulnerableLibraries}
|
|
20
|
+
? console.log(`Found 1 vulnerability`)
|
|
21
|
+
: console.log(`Found ${numberOfVulnerableLibraries} vulnerabilities`);
|
|
27
22
|
};
|
|
28
|
-
exports.createSummaryMessageBottom = createSummaryMessageBottom;
|
|
29
23
|
const getReport = async (config, reportId) => {
|
|
30
|
-
const client =
|
|
24
|
+
const client = commonApi.getHttpClient(config);
|
|
31
25
|
return client
|
|
32
26
|
.getReportById(config, reportId)
|
|
33
|
-
.then(
|
|
27
|
+
.then(res => {
|
|
34
28
|
if (res.statusCode === 200) {
|
|
35
29
|
return res.body;
|
|
36
30
|
}
|
|
37
31
|
else {
|
|
38
|
-
console.log(JSON.stringify(res));
|
|
39
|
-
|
|
32
|
+
console.log(JSON.stringify(res.statusCode));
|
|
33
|
+
commonApi.handleResponseErrors(res, 'report');
|
|
40
34
|
}
|
|
41
35
|
})
|
|
42
|
-
.catch(
|
|
36
|
+
.catch(err => {
|
|
43
37
|
console.log(err);
|
|
44
38
|
});
|
|
45
39
|
};
|
|
46
|
-
exports.getReport = getReport;
|
|
47
40
|
const printVulnerabilityResponse = (config, vulnerableLibraries, numberOfVulnerableLibraries, numberOfCves, guidance) => {
|
|
48
41
|
let hasSomeVulnerabilitiesReported = false;
|
|
49
|
-
|
|
42
|
+
printFormattedOutput(config, vulnerableLibraries, numberOfVulnerableLibraries, numberOfCves, guidance);
|
|
50
43
|
if (Object.keys(vulnerableLibraries).length > 0) {
|
|
51
44
|
hasSomeVulnerabilitiesReported = true;
|
|
52
45
|
}
|
|
53
46
|
return hasSomeVulnerabilitiesReported;
|
|
54
47
|
};
|
|
55
|
-
exports.printVulnerabilityResponse = printVulnerabilityResponse;
|
|
56
48
|
const printFormattedOutput = (config, libraries, numberOfVulnerableLibraries, numberOfCves, guidance) => {
|
|
57
|
-
|
|
49
|
+
createSummaryMessageTop(numberOfVulnerableLibraries, numberOfCves);
|
|
58
50
|
console.log();
|
|
59
|
-
const report = new
|
|
51
|
+
const report = new ReportList();
|
|
60
52
|
for (const library of libraries) {
|
|
61
|
-
const { name, version } =
|
|
62
|
-
const newOutputModel = new
|
|
53
|
+
const { name, version } = findNameAndVersion(library, config);
|
|
54
|
+
const newOutputModel = new ReportModelStructure(new ReportCompositeKey(name, version, findHighestSeverityCVE(library.cveArray), severityCountAllCVEs(library.cveArray, new SeverityCountModel()).getTotal), library.cveArray);
|
|
63
55
|
report.reportOutputList.push(newOutputModel);
|
|
64
56
|
}
|
|
65
|
-
const outputOrderedByLowestSeverityAndLowestNumOfCvesFirst =
|
|
66
|
-
|
|
57
|
+
const outputOrderedByLowestSeverityAndLowestNumOfCvesFirst = orderBy(report.reportOutputList, [
|
|
58
|
+
reportListItem => {
|
|
67
59
|
return reportListItem.compositeKey.highestSeverity.priority;
|
|
68
60
|
},
|
|
69
|
-
|
|
61
|
+
reportListItem => {
|
|
70
62
|
return reportListItem.compositeKey.numberOfSeverities;
|
|
71
63
|
}
|
|
72
64
|
], ['asc', 'desc']);
|
|
@@ -75,83 +67,81 @@ const printFormattedOutput = (config, libraries, numberOfVulnerableLibraries, nu
|
|
|
75
67
|
contrastHeaderNumCounter++;
|
|
76
68
|
const { libraryName, libraryVersion, highestSeverity } = reportModel.compositeKey;
|
|
77
69
|
const numOfCVEs = reportModel.cveArray.length;
|
|
78
|
-
const table =
|
|
79
|
-
chars: {
|
|
80
|
-
top: '',
|
|
81
|
-
'top-mid': '',
|
|
82
|
-
'top-left': '',
|
|
83
|
-
'top-right': '',
|
|
84
|
-
bottom: '',
|
|
85
|
-
'bottom-mid': '',
|
|
86
|
-
'bottom-left': '',
|
|
87
|
-
'bottom-right': '',
|
|
88
|
-
left: '',
|
|
89
|
-
'left-mid': '',
|
|
90
|
-
mid: '',
|
|
91
|
-
'mid-mid': '',
|
|
92
|
-
right: '',
|
|
93
|
-
'right-mid': '',
|
|
94
|
-
middle: ' '
|
|
95
|
-
},
|
|
96
|
-
style: { 'padding-left': 0, 'padding-right': 0 },
|
|
97
|
-
colAligns: ['right'],
|
|
98
|
-
wordWrap: true,
|
|
99
|
-
colWidths: [12, 1, 100]
|
|
100
|
-
});
|
|
70
|
+
const table = getReportTable();
|
|
101
71
|
const header = buildHeader(highestSeverity, contrastHeaderNumCounter, libraryName, libraryVersion, numOfCVEs);
|
|
102
72
|
const advice = gatherRemediationAdvice(guidance, libraryName, libraryVersion);
|
|
103
73
|
const body = buildBody(reportModel.cveArray, advice);
|
|
104
|
-
const reportOutputModel = new
|
|
74
|
+
const reportOutputModel = new ReportOutputModel(header, body);
|
|
105
75
|
table.push(reportOutputModel.body.issueMessage, reportOutputModel.body.adviceMessage);
|
|
106
76
|
console.log(reportOutputModel.header.vulnMessage, reportOutputModel.header.introducesMessage);
|
|
107
77
|
console.log(table.toString() + '\n');
|
|
108
78
|
}
|
|
109
|
-
|
|
79
|
+
createSummaryMessageBottom(numberOfVulnerableLibraries);
|
|
110
80
|
const { criticalMessage, highMessage, mediumMessage, lowMessage, noteMessage } = buildFooter(outputOrderedByLowestSeverityAndLowestNumOfCvesFirst);
|
|
111
81
|
console.log(`${criticalMessage} | ${highMessage} | ${mediumMessage} | ${lowMessage} | ${noteMessage}`);
|
|
112
|
-
if (config.host !==
|
|
113
|
-
console.log('\n' +
|
|
82
|
+
if (config.host !== CE_URL) {
|
|
83
|
+
console.log('\n' + chalk.bold('View your full dependency tree in Contrast:'));
|
|
114
84
|
console.log(`${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`);
|
|
115
85
|
}
|
|
116
86
|
};
|
|
117
|
-
|
|
87
|
+
function getReportTable() {
|
|
88
|
+
return new Table({
|
|
89
|
+
chars: {
|
|
90
|
+
top: '',
|
|
91
|
+
'top-mid': '',
|
|
92
|
+
'top-left': '',
|
|
93
|
+
'top-right': '',
|
|
94
|
+
bottom: '',
|
|
95
|
+
'bottom-mid': '',
|
|
96
|
+
'bottom-left': '',
|
|
97
|
+
'bottom-right': '',
|
|
98
|
+
left: '',
|
|
99
|
+
'left-mid': '',
|
|
100
|
+
mid: '',
|
|
101
|
+
'mid-mid': '',
|
|
102
|
+
right: '',
|
|
103
|
+
'right-mid': '',
|
|
104
|
+
middle: ' '
|
|
105
|
+
},
|
|
106
|
+
style: { 'padding-left': 0, 'padding-right': 0 },
|
|
107
|
+
colAligns: ['right'],
|
|
108
|
+
wordWrap: true,
|
|
109
|
+
colWidths: [12, 1, 100]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
118
112
|
function buildHeader(highestSeverity, contrastHeaderNum, libraryName, version, numOfCVEs) {
|
|
119
113
|
const vulnerabilityPluralised = numOfCVEs > 1 ? 'vulnerabilities' : 'vulnerability';
|
|
120
114
|
const formattedHeaderNum = buildFormattedHeaderNum(contrastHeaderNum);
|
|
121
|
-
const headerColour =
|
|
115
|
+
const headerColour = chalk.hex(highestSeverity.colour);
|
|
122
116
|
const headerNumAndSeverity = headerColour(`${formattedHeaderNum} - [${highestSeverity.severity}]`);
|
|
123
117
|
const libraryNameAndVersion = headerColour.bold(`${libraryName}-${version}`);
|
|
124
118
|
const vulnMessage = `${headerNumAndSeverity} ${libraryNameAndVersion}`;
|
|
125
119
|
const introducesMessage = `introduces ${numOfCVEs} ${vulnerabilityPluralised}`;
|
|
126
|
-
return new
|
|
120
|
+
return new ReportOutputHeaderModel(vulnMessage, introducesMessage);
|
|
127
121
|
}
|
|
128
|
-
exports.buildHeader = buildHeader;
|
|
129
122
|
function buildBody(cveArray, advice) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const { outputColour, severity, cveName } = reportSeverityModel;
|
|
133
|
-
const severityShorthand = chalk_1.default
|
|
134
|
-
.hex(outputColour)
|
|
135
|
-
.bold(`[${severity.charAt(0).toUpperCase()}]`);
|
|
136
|
-
const builtMessage = severityShorthand + cveName;
|
|
137
|
-
cveMessages.push(builtMessage);
|
|
138
|
-
});
|
|
139
|
-
const numAndSeverityType = getNumOfAndSeverityType(cveArray);
|
|
140
|
-
const issueMessage = [
|
|
141
|
-
chalk_1.default.bold('Issue'),
|
|
142
|
-
':',
|
|
143
|
-
`${numAndSeverityType} ${cveMessages.join(', ')}`
|
|
144
|
-
];
|
|
123
|
+
let assignPriorityToVulns = cveArray.map(result => findCVESeverity(result));
|
|
124
|
+
const issueMessage = getIssueRow(assignPriorityToVulns);
|
|
145
125
|
const minOrMax = advice.maximum ? advice.maximum : advice.minimum;
|
|
146
126
|
const displayAdvice = minOrMax
|
|
147
|
-
? `Change to version ${
|
|
127
|
+
? `Change to version ${chalk.bold(minOrMax)}`
|
|
148
128
|
: 'No recommendation is available according to our data. Upgrade to the latest stable is the best advice we can give.';
|
|
149
|
-
const adviceMessage = [
|
|
150
|
-
return new
|
|
129
|
+
const adviceMessage = [chalk.bold('Advice'), ':', displayAdvice];
|
|
130
|
+
return new ReportOutputBodyModel(issueMessage, adviceMessage);
|
|
131
|
+
}
|
|
132
|
+
function getIssueRow(cveArray) {
|
|
133
|
+
orderByHighestPriority(cveArray);
|
|
134
|
+
const cveMessagesList = getIssueCveMsgList(cveArray);
|
|
135
|
+
const cveNumbers = getSeverityCounts(cveArray);
|
|
136
|
+
const numAndSeverityTypeDesc = getNumOfAndSeverityType(cveNumbers);
|
|
137
|
+
return [
|
|
138
|
+
chalk.bold('Issue'),
|
|
139
|
+
':',
|
|
140
|
+
`${numAndSeverityTypeDesc} ${cveMessagesList.join(', ')}`
|
|
141
|
+
];
|
|
151
142
|
}
|
|
152
|
-
exports.buildBody = buildBody;
|
|
153
143
|
function gatherRemediationAdvice(guidance, libraryName, libraryVersion) {
|
|
154
|
-
const guidanceModel = new
|
|
144
|
+
const guidanceModel = new ReportGuidanceModel();
|
|
155
145
|
const data = guidance[libraryName + '@' + libraryVersion];
|
|
156
146
|
if (data) {
|
|
157
147
|
guidanceModel.minimum = data.minUpgradeVersion;
|
|
@@ -159,43 +149,29 @@ function gatherRemediationAdvice(guidance, libraryName, libraryVersion) {
|
|
|
159
149
|
}
|
|
160
150
|
return guidanceModel;
|
|
161
151
|
}
|
|
162
|
-
exports.gatherRemediationAdvice = gatherRemediationAdvice;
|
|
163
152
|
function buildFormattedHeaderNum(contrastHeaderNum) {
|
|
164
153
|
return `CONTRAST-${contrastHeaderNum.toString().padStart(3, '0')}`;
|
|
165
154
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
const lowNumCheck = low > 0;
|
|
175
|
-
const lowDivider = lowNumCheck ? '|' : '';
|
|
176
|
-
const noteNumCheck = low > 0;
|
|
177
|
-
const noteDivider = noteNumCheck ? '|' : '';
|
|
178
|
-
const criticalMessage = criticalNumCheck
|
|
179
|
-
? `${critical} Critical ${highDivider}`
|
|
180
|
-
: '';
|
|
181
|
-
const highMessage = highNumCheck ? `${high} High ${mediumDivider}` : '';
|
|
182
|
-
const mediumMessage = mediumNumCheck ? `${medium} Medium ${lowDivider}` : '';
|
|
183
|
-
const lowMessage = lowNumCheck ? `${low} Low ${noteDivider}` : '';
|
|
184
|
-
const noteMessage = noteNumCheck ? `${note} Note` : '';
|
|
185
|
-
return `${criticalMessage} ${highMessage} ${mediumMessage} ${lowMessage} ${noteMessage}`
|
|
155
|
+
function getNumOfAndSeverityType(cveNumbers) {
|
|
156
|
+
const { critical, high, medium, low, note } = cveNumbers;
|
|
157
|
+
const criticalMsg = critical > 0 ? `${critical} Critical | ` : '';
|
|
158
|
+
const highMsg = high > 0 ? `${high} High | ` : '';
|
|
159
|
+
const mediumMsg = medium > 0 ? `${medium} Medium | ` : '';
|
|
160
|
+
const lowMsg = low > 0 ? `${low} Low | ` : '';
|
|
161
|
+
const noteMsg = note > 0 ? `${note} Note` : '';
|
|
162
|
+
return `${criticalMsg} ${highMsg} ${mediumMsg} ${lowMsg} ${noteMsg}`
|
|
186
163
|
.replace(/\s+/g, ' ')
|
|
187
164
|
.trim();
|
|
188
165
|
}
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
.hex(constants_1.CRITICAL_COLOUR)
|
|
166
|
+
const buildFooter = reportModelStructure => {
|
|
167
|
+
const { critical, high, medium, low, note } = countVulnerableLibrariesBySeverity(reportModelStructure);
|
|
168
|
+
const criticalMessage = chalk
|
|
169
|
+
.hex(CRITICAL_COLOUR)
|
|
194
170
|
.bold(`${critical} Critical`);
|
|
195
|
-
const highMessage =
|
|
196
|
-
const mediumMessage =
|
|
197
|
-
const lowMessage =
|
|
198
|
-
const noteMessage =
|
|
171
|
+
const highMessage = chalk.hex(HIGH_COLOUR).bold(`${high} High`);
|
|
172
|
+
const mediumMessage = chalk.hex(MEDIUM_COLOUR).bold(`${medium} Medium`);
|
|
173
|
+
const lowMessage = chalk.hex(LOW_COLOUR).bold(`${low} Low`);
|
|
174
|
+
const noteMessage = chalk.hex(NOTE_COLOUR).bold(`${note} Note`);
|
|
199
175
|
return {
|
|
200
176
|
criticalMessage,
|
|
201
177
|
highMessage,
|
|
@@ -204,3 +180,86 @@ const buildFooter = (reportModelStructure) => {
|
|
|
204
180
|
noteMessage
|
|
205
181
|
};
|
|
206
182
|
};
|
|
183
|
+
const getIssueCveMsgList = results => {
|
|
184
|
+
const cveMessages = [];
|
|
185
|
+
results.forEach(reportSeverityModel => {
|
|
186
|
+
const { colour, severity, name } = reportSeverityModel;
|
|
187
|
+
const severityShorthand = chalk
|
|
188
|
+
.hex(colour)
|
|
189
|
+
.bold(`[${severity.charAt(0).toUpperCase()}]`);
|
|
190
|
+
const builtMessage = severityShorthand + name;
|
|
191
|
+
cveMessages.push(builtMessage);
|
|
192
|
+
});
|
|
193
|
+
return cveMessages;
|
|
194
|
+
};
|
|
195
|
+
const getSeverityCounts = results => {
|
|
196
|
+
const acc = {
|
|
197
|
+
critical: 0,
|
|
198
|
+
high: 0,
|
|
199
|
+
medium: 0,
|
|
200
|
+
low: 0,
|
|
201
|
+
note: 0,
|
|
202
|
+
total: 0
|
|
203
|
+
};
|
|
204
|
+
if (results && results.length > 0) {
|
|
205
|
+
results.forEach(i => {
|
|
206
|
+
acc[i.severity.toLowerCase()] += 1;
|
|
207
|
+
acc.total += 1;
|
|
208
|
+
return acc;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return acc;
|
|
212
|
+
};
|
|
213
|
+
const printNoVulnFoundMsg = () => {
|
|
214
|
+
console.log(i18n.__('scanNoVulnerabilitiesFound'));
|
|
215
|
+
console.log(i18n.__('scanNoVulnerabilitiesFoundSecureCode'));
|
|
216
|
+
console.log(i18n.__('scanNoVulnerabilitiesFoundGoodWork'));
|
|
217
|
+
console.log(chalk.bold(`Found 0 vulnerabilities`));
|
|
218
|
+
console.log(i18n.__('foundDetailedVulnerabilities', String(0), String(0), String(0), String(0), String(0)));
|
|
219
|
+
};
|
|
220
|
+
const printVulnInfo = projectOverview => {
|
|
221
|
+
const totalVulnerabilities = projectOverview.total;
|
|
222
|
+
createSummaryMessageBottom(totalVulnerabilities);
|
|
223
|
+
const formattedValues = severityFormatted(projectOverview);
|
|
224
|
+
console.log(i18n.__('foundDetailedVulnerabilities', String(formattedValues.criticalFormatted), String(formattedValues.highFormatted), String(formattedValues.mediumFormatted), String(formattedValues.lowFormatted), String(formattedValues.noteFormatted)));
|
|
225
|
+
};
|
|
226
|
+
const severityFormatted = projectOverview => {
|
|
227
|
+
const criticalFormatted = chalk
|
|
228
|
+
.hex(CRITICAL_COLOUR)
|
|
229
|
+
.bold(`${projectOverview.critical} Critical`);
|
|
230
|
+
const highFormatted = chalk
|
|
231
|
+
.hex(HIGH_COLOUR)
|
|
232
|
+
.bold(`${projectOverview.high} High`);
|
|
233
|
+
const mediumFormatted = chalk
|
|
234
|
+
.hex(MEDIUM_COLOUR)
|
|
235
|
+
.bold(`${projectOverview.medium} Medium`);
|
|
236
|
+
const lowFormatted = chalk.hex(LOW_COLOUR).bold(`${projectOverview.low} Low`);
|
|
237
|
+
const noteFormatted = chalk
|
|
238
|
+
.hex(NOTE_COLOUR)
|
|
239
|
+
.bold(`${projectOverview.note} Note`);
|
|
240
|
+
return {
|
|
241
|
+
criticalFormatted,
|
|
242
|
+
highFormatted,
|
|
243
|
+
mediumFormatted,
|
|
244
|
+
lowFormatted,
|
|
245
|
+
noteFormatted
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
module.exports = {
|
|
249
|
+
createSummaryMessageTop,
|
|
250
|
+
getReport,
|
|
251
|
+
createSummaryMessageBottom,
|
|
252
|
+
printVulnerabilityResponse,
|
|
253
|
+
printFormattedOutput,
|
|
254
|
+
getReportTable,
|
|
255
|
+
buildHeader,
|
|
256
|
+
buildBody,
|
|
257
|
+
getIssueRow,
|
|
258
|
+
gatherRemediationAdvice,
|
|
259
|
+
buildFormattedHeaderNum,
|
|
260
|
+
getNumOfAndSeverityType,
|
|
261
|
+
getIssueCveMsgList,
|
|
262
|
+
getSeverityCounts,
|
|
263
|
+
printNoVulnFoundMsg,
|
|
264
|
+
printVulnInfo
|
|
265
|
+
};
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReportSeverityModel = void 0;
|
|
4
4
|
class ReportSeverityModel {
|
|
5
|
-
constructor(severity, priority,
|
|
5
|
+
constructor(severity, priority, colour, name) {
|
|
6
6
|
this.severity = severity;
|
|
7
7
|
this.priority = priority;
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
8
|
+
this.colour = colour;
|
|
9
|
+
this.name = name;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.ReportSeverityModel = ReportSeverityModel;
|
|
@@ -22,15 +22,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.vulnerabilityReportV2 = exports.formatVulnerabilityOutput = exports.convertJSDotNetPython = exports.convertKeysToStandardFormat = void 0;
|
|
30
27
|
const commonReportingFunctions_1 = require("./commonReportingFunctions");
|
|
31
28
|
const reportUtils_1 = require("./utils/reportUtils");
|
|
32
|
-
const i18n_1 = __importDefault(require("i18n"));
|
|
33
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
34
29
|
const constants = __importStar(require("../../constants/constants"));
|
|
35
30
|
const severityCountModel_1 = require("./models/severityCountModel");
|
|
36
31
|
const common = __importStar(require("../../common/fail"));
|
|
@@ -67,11 +62,7 @@ function formatVulnerabilityOutput(libraryVulnerabilityResponse, id, config, rem
|
|
|
67
62
|
const guidance = convertKeysToStandardFormat(config, remediationGuidance);
|
|
68
63
|
const numberOfVulnerableLibraries = vulnerableLibraries.length;
|
|
69
64
|
if (numberOfVulnerableLibraries === 0) {
|
|
70
|
-
|
|
71
|
-
console.log(i18n_1.default.__('scanNoVulnerabilitiesFoundSecureCode'));
|
|
72
|
-
console.log(i18n_1.default.__('scanNoVulnerabilitiesFoundGoodWork'));
|
|
73
|
-
console.log(chalk_1.default.bold(`Found ${numberOfVulnerableLibraries} vulnerabilities`));
|
|
74
|
-
console.log(i18n_1.default.__('foundDetailedVulnerabilities', String(0), String(0), String(0), String(0), String(0)));
|
|
65
|
+
(0, commonReportingFunctions_1.printNoVulnFoundMsg)();
|
|
75
66
|
return [false, 0, [new severityCountModel_1.SeverityCountModel()]];
|
|
76
67
|
}
|
|
77
68
|
else {
|
|
@@ -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.countVulnerableLibrariesBySeverity = exports.findNameAndVersion = exports.severityCountSingleCVE = exports.severityCountAllCVEs = exports.severityCountAllLibraries = exports.convertGenericToTypedLibraryVulns = exports.findCVESeverity = exports.
|
|
6
|
+
exports.countVulnerableLibrariesBySeverity = exports.findNameAndVersion = exports.severityCountSingleCVE = exports.severityCountAllCVEs = exports.severityCountAllLibraries = exports.convertGenericToTypedLibraryVulns = exports.findCVESeverity = exports.orderByHighestPriority = exports.findHighestSeverityCVE = void 0;
|
|
7
7
|
const reportLibraryModel_1 = require("../models/reportLibraryModel");
|
|
8
8
|
const reportSeverityModel_1 = require("../models/reportSeverityModel");
|
|
9
9
|
const constants_1 = __importDefault(require("../../../constants/constants"));
|
|
@@ -16,10 +16,10 @@ function findHighestSeverityCVE(cveArray) {
|
|
|
16
16
|
return (0, lodash_1.orderBy)(mappedToReportSeverityModels, cve => cve?.priority)[0];
|
|
17
17
|
}
|
|
18
18
|
exports.findHighestSeverityCVE = findHighestSeverityCVE;
|
|
19
|
-
function
|
|
20
|
-
return (0, lodash_1.orderBy)(cves
|
|
19
|
+
function orderByHighestPriority(cves) {
|
|
20
|
+
return (0, lodash_1.orderBy)(cves, ['priority'], ['asc']);
|
|
21
21
|
}
|
|
22
|
-
exports.
|
|
22
|
+
exports.orderByHighestPriority = orderByHighestPriority;
|
|
23
23
|
function findCVESeverity(cve) {
|
|
24
24
|
const cveName = cve.name;
|
|
25
25
|
if (cve.cvss3SeverityCode === 'CRITICAL' || cve.severityCode === 'CRITICAL') {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.processAudit = void 0;
|
|
4
7
|
const auditConfig_1 = require("./auditConfig");
|
|
5
8
|
const help_1 = require("./help");
|
|
6
9
|
const scaAnalysis_1 = require("../scan/sca/scaAnalysis");
|
|
7
10
|
const telemetry_1 = require("../../telemetry/telemetry");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
12
|
const processAudit = async (contrastConf, argv) => {
|
|
9
13
|
if (argv.indexOf('--help') != -1) {
|
|
10
14
|
printHelpMessage();
|
|
@@ -12,9 +16,15 @@ const processAudit = async (contrastConf, argv) => {
|
|
|
12
16
|
}
|
|
13
17
|
const config = await (0, auditConfig_1.getAuditConfig)(contrastConf, 'audit', argv);
|
|
14
18
|
await (0, scaAnalysis_1.processSca)(config);
|
|
19
|
+
postRunMessage();
|
|
15
20
|
await (0, telemetry_1.sendTelemetryConfigAsObject)(config, 'audit', argv, 'SUCCESS', config.language);
|
|
16
21
|
};
|
|
17
22
|
exports.processAudit = processAudit;
|
|
18
23
|
const printHelpMessage = () => {
|
|
19
24
|
console.log(help_1.auditUsageGuide);
|
|
20
25
|
};
|
|
26
|
+
const postRunMessage = () => {
|
|
27
|
+
console.log('\n' + chalk_1.default.underline.bold('Other Codesec Features:'));
|
|
28
|
+
console.log("'contrast scan' to run CodeSec’s industry leading SAST scanner");
|
|
29
|
+
console.log("'contrast lambda' to secure your AWS serverless functions\n");
|
|
30
|
+
};
|
|
@@ -7,9 +7,12 @@ const { formatScanOutput } = require('../../scan/formatScanOutput');
|
|
|
7
7
|
const { processSca } = require('./sca/scaAnalysis');
|
|
8
8
|
const common = require('../../common/fail');
|
|
9
9
|
const { sendTelemetryConfigAsObject } = require('../../telemetry/telemetry');
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const generalAPI = require('../../utils/generalAPI');
|
|
10
12
|
const processScan = async (contrastConf, argv) => {
|
|
11
13
|
let config = await scanConfig.getScanConfig(contrastConf, 'scan', argv);
|
|
12
14
|
let output = undefined;
|
|
15
|
+
config.mode = await generalAPI.getMode(config);
|
|
13
16
|
if (config.experimental) {
|
|
14
17
|
await processSca(config, argv);
|
|
15
18
|
}
|
|
@@ -24,6 +27,12 @@ const processScan = async (contrastConf, argv) => {
|
|
|
24
27
|
if (config.fail) {
|
|
25
28
|
common.processFail(config, output);
|
|
26
29
|
}
|
|
30
|
+
postRunMessage();
|
|
31
|
+
};
|
|
32
|
+
const postRunMessage = () => {
|
|
33
|
+
console.log('\n' + chalk.underline.bold('Other Codesec Features:'));
|
|
34
|
+
console.log("'contrast audit' to find vulnerabilities in your open source dependencies");
|
|
35
|
+
console.log("'contrast lambda' to secure your AWS serverless functions\n");
|
|
27
36
|
};
|
|
28
37
|
module.exports = {
|
|
29
38
|
processScan
|
|
@@ -18,7 +18,9 @@ const { dotNetAnalysis } = require('../../../scaAnalysis/dotnet');
|
|
|
18
18
|
const { auditUsageGuide } = require('../../audit/help');
|
|
19
19
|
const rootFile = require('../../../audit/languageAnalysisEngine/getProjectRootFilenames');
|
|
20
20
|
const path = require('path');
|
|
21
|
+
const generalAPI = require('../../../utils/generalAPI');
|
|
21
22
|
const processSca = async (config) => {
|
|
23
|
+
config.mode = await generalAPI.getMode(config);
|
|
22
24
|
const startTime = performance.now();
|
|
23
25
|
let filesFound;
|
|
24
26
|
if (config.help) {
|
|
@@ -130,9 +130,9 @@ HTTPClient.prototype.getScanProjectById = function getScanProjectById(config) {
|
|
|
130
130
|
options.url = createScanProjectUrl(config);
|
|
131
131
|
return requestUtils.sendRequest({ method: 'get', options });
|
|
132
132
|
};
|
|
133
|
-
HTTPClient.prototype.getGlobalProperties = function getGlobalProperties() {
|
|
133
|
+
HTTPClient.prototype.getGlobalProperties = function getGlobalProperties(host) {
|
|
134
134
|
const options = _.cloneDeep(this.requestOptions);
|
|
135
|
-
let url = createGlobalPropertiesUrl(
|
|
135
|
+
let url = createGlobalPropertiesUrl(host);
|
|
136
136
|
options.url = url;
|
|
137
137
|
return requestUtils.sendRequest({ method: 'get', options });
|
|
138
138
|
};
|
|
@@ -166,6 +166,25 @@ HTTPClient.prototype.sendSnapshot = function sendSnapshot(requestBody, config) {
|
|
|
166
166
|
options.body = requestBody;
|
|
167
167
|
return requestUtils.sendRequest({ method: 'post', options });
|
|
168
168
|
};
|
|
169
|
+
HTTPClient.prototype.scaServiceIngest = function scaServiceIngest(requestBody, config) {
|
|
170
|
+
const options = _.cloneDeep(this.requestOptions);
|
|
171
|
+
let url = createScaServiceIngestURL(config);
|
|
172
|
+
options.url = url;
|
|
173
|
+
options.body = requestBody;
|
|
174
|
+
return requestUtils.sendRequest({ method: 'post', options });
|
|
175
|
+
};
|
|
176
|
+
HTTPClient.prototype.scaServiceReport = function scaServiceReport(config, reportId) {
|
|
177
|
+
const options = _.cloneDeep(this.requestOptions);
|
|
178
|
+
let url = createScaServiceReportURL(config, reportId);
|
|
179
|
+
options.url = url;
|
|
180
|
+
return requestUtils.sendRequest({ method: 'get', options });
|
|
181
|
+
};
|
|
182
|
+
HTTPClient.prototype.scaServiceReportStatus = function scaServiceReport(config, reportId) {
|
|
183
|
+
const options = _.cloneDeep(this.requestOptions);
|
|
184
|
+
let url = createScaServiceReportStatusURL(config, reportId);
|
|
185
|
+
options.url = url;
|
|
186
|
+
return requestUtils.sendRequest({ method: 'get', options });
|
|
187
|
+
};
|
|
169
188
|
HTTPClient.prototype.getReportById = function getReportById(config, reportId) {
|
|
170
189
|
const options = _.cloneDeep(this.requestOptions);
|
|
171
190
|
if (config.ignoreDev) {
|
|
@@ -301,6 +320,15 @@ const pollForAuthUrl = () => {
|
|
|
301
320
|
function createSnapshotURL(config) {
|
|
302
321
|
return `${config.host}/Contrast/api/ng/sca/organizations/${config.organizationId}/applications/${config.applicationId}/snapshots`;
|
|
303
322
|
}
|
|
323
|
+
function createScaServiceReportURL(config, reportId) {
|
|
324
|
+
return ``;
|
|
325
|
+
}
|
|
326
|
+
function createScaServiceReportStatusURL(config, reportId) {
|
|
327
|
+
return ``;
|
|
328
|
+
}
|
|
329
|
+
function createScaServiceIngestURL(config) {
|
|
330
|
+
return ``;
|
|
331
|
+
}
|
|
304
332
|
const createAppCreateURL = config => {
|
|
305
333
|
return `${config.host}/Contrast/api/ng/sca/organizations/${config.organizationId}/applications/create`;
|
|
306
334
|
};
|
|
@@ -47,8 +47,7 @@ const reportFailureError = () => {
|
|
|
47
47
|
console.log(i18n_1.default.__('auditReportFailureMessage'));
|
|
48
48
|
};
|
|
49
49
|
exports.reportFailureError = reportFailureError;
|
|
50
|
-
const genericError = (
|
|
51
|
-
console.log(missingCliOption);
|
|
50
|
+
const genericError = () => {
|
|
52
51
|
console.error(i18n_1.default.__('genericErrorMessage'));
|
|
53
52
|
process.exit(1);
|
|
54
53
|
};
|
package/dist/common/fail.js
CHANGED
|
@@ -21,11 +21,15 @@ const isSeverityViolation = (severity, reportResults) => {
|
|
|
21
21
|
count += reportResults.high + reportResults.critical;
|
|
22
22
|
break;
|
|
23
23
|
case 'medium':
|
|
24
|
-
count +=
|
|
24
|
+
count +=
|
|
25
|
+
reportResults.medium + reportResults.high + reportResults.critical;
|
|
25
26
|
break;
|
|
26
27
|
case 'low':
|
|
27
28
|
count +=
|
|
28
|
-
reportResults.high +
|
|
29
|
+
reportResults.high +
|
|
30
|
+
reportResults.critical +
|
|
31
|
+
reportResults.medium +
|
|
32
|
+
reportResults.low;
|
|
29
33
|
break;
|
|
30
34
|
case 'note':
|
|
31
35
|
if (reportResults.note == reportResults.total) {
|
|
@@ -45,7 +49,7 @@ const failPipeline = (message = '') => {
|
|
|
45
49
|
i18n.__('snapshotFailureHeader') +
|
|
46
50
|
' *********************************\n' +
|
|
47
51
|
i18n.__(message));
|
|
48
|
-
process.exit(
|
|
52
|
+
process.exit(2);
|
|
49
53
|
};
|
|
50
54
|
const parseSeverity = severity => {
|
|
51
55
|
const severities = ['NOTE', 'LOW', 'MEDIUM', 'HIGH', 'CRITICAL'];
|
|
@@ -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.isCorrectNodeVersion = exports.findLatestCLIVersion = void 0;
|
|
6
|
+
exports.isCorrectNodeVersion = exports.findLatestCLIVersion = exports.getLatestVersion = void 0;
|
|
7
7
|
const constants_1 = require("../constants/constants");
|
|
8
8
|
const boxen_1 = __importDefault(require("boxen"));
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -19,16 +19,22 @@ const getLatestVersion = async (config) => {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
return;
|
|
22
|
+
return undefined;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
exports.getLatestVersion = getLatestVersion;
|
|
25
26
|
async function findLatestCLIVersion(config) {
|
|
26
27
|
const isCI = process.env.CONTRAST_CODESEC_CI
|
|
27
|
-
? JSON.parse(process.env.CONTRAST_CODESEC_CI)
|
|
28
|
+
? JSON.parse(process.env.CONTRAST_CODESEC_CI.toLowerCase())
|
|
28
29
|
: false;
|
|
29
30
|
if (!isCI) {
|
|
30
|
-
let latestCLIVersion = await getLatestVersion(config);
|
|
31
|
-
latestCLIVersion
|
|
31
|
+
let latestCLIVersion = await (0, exports.getLatestVersion)(config);
|
|
32
|
+
if (latestCLIVersion === undefined) {
|
|
33
|
+
config.set('numOfRuns', 0);
|
|
34
|
+
console.log('Failed to retrieve latest version info. Continuing execution.');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
latestCLIVersion = latestCLIVersion.substring(8).replace('\n', '');
|
|
32
38
|
if (semver_1.default.lt(constants_1.APP_VERSION, latestCLIVersion)) {
|
|
33
39
|
const updateAvailableMessage = `Update available ${chalk_1.default.yellow(constants_1.APP_VERSION)} → ${chalk_1.default.green(latestCLIVersion)}`;
|
|
34
40
|
const npmUpdateAvailableCommand = `Run ${chalk_1.default.cyan('npm i @contrast/contrast -g')} to update via npm`;
|