@contrast/contrast 1.0.7 → 1.0.10
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/README.md +1 -1
- package/dist/audit/catalogueApplication/catalogueApplication.js +23 -5
- package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +17 -26
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +98 -37
- package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +2 -1
- package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +4 -3
- package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +3 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +87 -19
- package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +40 -7
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +6 -30
- package/dist/audit/save.js +37 -0
- package/dist/commands/audit/auditConfig.js +0 -16
- package/dist/commands/audit/auditController.js +18 -11
- package/dist/commands/audit/help.js +31 -25
- package/dist/commands/audit/processAudit.js +2 -2
- package/dist/commands/audit/saveFile.js +8 -4
- package/dist/commands/scan/sca/scaAnalysis.js +54 -16
- package/dist/common/HTTPClient.js +14 -8
- package/dist/common/errorHandling.js +2 -2
- package/dist/common/versionChecker.js +19 -4
- package/dist/constants/constants.js +7 -2
- package/dist/constants/locales.js +44 -44
- package/dist/constants.js +31 -14
- package/dist/index.js +55 -45
- package/dist/lambda/lambda.js +5 -2
- package/dist/sbom/generateSbom.js +5 -4
- package/dist/scaAnalysis/common/formatMessage.js +33 -6
- package/dist/scaAnalysis/common/treeUpload.js +4 -6
- package/dist/scaAnalysis/dotnet/analysis.js +43 -0
- package/dist/scaAnalysis/dotnet/index.js +10 -0
- package/dist/scaAnalysis/go/goReadDepFile.js +1 -3
- package/dist/scaAnalysis/java/analysis.js +5 -5
- package/dist/scaAnalysis/javascript/analysis.js +107 -0
- package/dist/scaAnalysis/javascript/index.js +53 -0
- package/dist/scaAnalysis/php/analysis.js +70 -0
- package/dist/scaAnalysis/php/index.js +17 -0
- package/dist/scaAnalysis/python/analysis.js +8 -7
- package/dist/scaAnalysis/ruby/analysis.js +8 -16
- package/dist/scaAnalysis/ruby/index.js +2 -2
- package/dist/scan/autoDetection.js +13 -24
- package/dist/scan/fileUtils.js +44 -14
- package/dist/scan/formatScanOutput.js +3 -3
- package/dist/scan/scanConfig.js +2 -2
- package/dist/utils/commonApi.js +1 -1
- package/dist/utils/filterProjectPath.js +7 -2
- package/dist/utils/getConfig.js +1 -6
- package/package.json +2 -3
- package/src/audit/catalogueApplication/catalogueApplication.js +28 -6
- package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +22 -58
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +157 -47
- package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +4 -1
- package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +11 -5
- package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +4 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +86 -32
- package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +44 -5
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +6 -32
- package/src/audit/save.js +48 -0
- package/src/commands/audit/auditConfig.ts +0 -25
- package/src/commands/audit/auditController.ts +18 -20
- package/src/commands/audit/help.ts +31 -25
- package/src/commands/audit/processAudit.ts +2 -5
- package/src/commands/audit/saveFile.ts +6 -2
- package/src/commands/scan/processScan.js +0 -1
- package/src/commands/scan/sca/scaAnalysis.js +87 -32
- package/src/common/HTTPClient.js +16 -9
- package/src/common/errorHandling.ts +2 -3
- package/src/common/versionChecker.ts +23 -4
- package/src/constants/constants.js +9 -3
- package/src/constants/locales.js +72 -50
- package/src/constants.js +32 -15
- package/src/index.ts +70 -58
- package/src/lambda/lambda.ts +5 -2
- package/src/lambda/types.ts +1 -0
- package/src/sbom/generateSbom.ts +2 -2
- package/src/scaAnalysis/common/formatMessage.js +35 -6
- package/src/scaAnalysis/common/treeUpload.js +4 -6
- package/src/scaAnalysis/dotnet/analysis.js +54 -0
- package/src/scaAnalysis/dotnet/index.js +11 -0
- package/src/scaAnalysis/go/goReadDepFile.js +1 -3
- package/src/scaAnalysis/java/analysis.js +5 -5
- package/src/scaAnalysis/javascript/analysis.js +126 -0
- package/src/scaAnalysis/javascript/index.js +75 -0
- package/src/scaAnalysis/php/analysis.js +78 -0
- package/src/scaAnalysis/php/index.js +22 -0
- package/src/scaAnalysis/python/analysis.js +8 -7
- package/src/scaAnalysis/ruby/analysis.js +8 -17
- package/src/scaAnalysis/ruby/index.js +2 -2
- package/src/scan/autoDetection.js +14 -27
- package/src/scan/fileUtils.js +46 -14
- package/src/scan/formatScanOutput.ts +3 -3
- package/src/scan/scanConfig.js +2 -4
- package/src/utils/commonApi.js +1 -1
- package/src/utils/filterProjectPath.js +6 -2
- package/src/utils/getConfig.ts +1 -12
- package/dist/audit/AnalysisEngine.js +0 -37
- package/dist/audit/autodetection/autoDetectLanguage.js +0 -32
- package/dist/audit/dotnetAnalysisEngine/index.js +0 -25
- package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -35
- package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -15
- package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -18
- package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -14
- package/dist/audit/dotnetAnalysisEngine/sanitizer.js +0 -9
- package/dist/audit/goAnalysisEngine/index.js +0 -17
- package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +0 -164
- package/dist/audit/goAnalysisEngine/readProjectFileContents.js +0 -21
- package/dist/audit/goAnalysisEngine/sanitizer.js +0 -5
- package/dist/audit/javaAnalysisEngine/index.js +0 -34
- package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -155
- package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -353
- package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +0 -98
- package/dist/audit/javaAnalysisEngine/sanitizer.js +0 -5
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -25
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -25
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -35
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -24
- package/dist/audit/languageAnalysisEngine/constants.js +0 -20
- package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -25
- package/dist/audit/languageAnalysisEngine/index.js +0 -39
- package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -89
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -159
- package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -40
- package/dist/audit/nodeAnalysisEngine/index.js +0 -31
- package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -18
- package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -18
- package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -17
- package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -14
- package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -24
- package/dist/audit/nodeAnalysisEngine/sanitizer.js +0 -9
- package/dist/audit/phpAnalysisEngine/index.js +0 -23
- package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +0 -52
- package/dist/audit/phpAnalysisEngine/readLockFileContents.js +0 -13
- package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +0 -16
- package/dist/audit/phpAnalysisEngine/sanitizer.js +0 -5
- package/dist/audit/pythonAnalysisEngine/index.js +0 -25
- package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -17
- package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -21
- package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -13
- package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -14
- package/dist/audit/pythonAnalysisEngine/sanitizer.js +0 -7
- package/dist/audit/rubyAnalysisEngine/index.js +0 -25
- package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -176
- package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +0 -22
- package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +0 -14
- package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -14
- package/dist/audit/rubyAnalysisEngine/sanitizer.js +0 -6
- package/src/audit/AnalysisEngine.js +0 -103
- package/src/audit/autodetection/autoDetectLanguage.ts +0 -40
- package/src/audit/dotnetAnalysisEngine/index.js +0 -26
- package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -47
- package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -29
- package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -30
- package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -26
- package/src/audit/dotnetAnalysisEngine/sanitizer.js +0 -11
- package/src/audit/goAnalysisEngine/index.js +0 -18
- package/src/audit/goAnalysisEngine/parseProjectFileContents.js +0 -209
- package/src/audit/goAnalysisEngine/readProjectFileContents.js +0 -31
- package/src/audit/goAnalysisEngine/sanitizer.js +0 -7
- package/src/audit/javaAnalysisEngine/index.js +0 -41
- package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -225
- package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -420
- package/src/audit/javaAnalysisEngine/readProjectFileContents.js +0 -141
- package/src/audit/javaAnalysisEngine/sanitizer.js +0 -6
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -36
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -42
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -54
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -33
- package/src/audit/languageAnalysisEngine/constants.js +0 -23
- package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -41
- package/src/audit/languageAnalysisEngine/index.js +0 -45
- package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -124
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -250
- package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -49
- package/src/audit/nodeAnalysisEngine/index.js +0 -35
- package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -20
- package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -26
- package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -23
- package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -27
- package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -36
- package/src/audit/nodeAnalysisEngine/sanitizer.js +0 -11
- package/src/audit/phpAnalysisEngine/index.js +0 -27
- package/src/audit/phpAnalysisEngine/parseLockFileContents.js +0 -60
- package/src/audit/phpAnalysisEngine/readLockFileContents.js +0 -14
- package/src/audit/phpAnalysisEngine/readProjectFileContents.js +0 -25
- package/src/audit/phpAnalysisEngine/sanitizer.js +0 -4
- package/src/audit/pythonAnalysisEngine/index.js +0 -55
- package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -23
- package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -33
- package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -16
- package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -22
- package/src/audit/pythonAnalysisEngine/sanitizer.js +0 -9
- package/src/audit/rubyAnalysisEngine/index.js +0 -30
- package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -215
- package/src/audit/rubyAnalysisEngine/parsedGemfile.js +0 -39
- package/src/audit/rubyAnalysisEngine/readGemfileContents.js +0 -18
- package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -17
- package/src/audit/rubyAnalysisEngine/sanitizer.js +0 -8
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ export AWS_SECRET_ACCESS_KEY=<YOUR_SECRET_ACCESS_KEY>
|
|
|
52
52
|
|
|
53
53
|
- These permissions are required to gather all required information on an AWS Lambda to use the `contrast lambda` command:
|
|
54
54
|
|
|
55
|
-
- Lambda: [GetFunction](https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html) | [GetLayerVersion](https://docs.aws.amazon.com/lambda/latest/dg/API_GetLayerVersion.html)
|
|
55
|
+
- Lambda: [GetFunction](https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html) | [GetLayerVersion](https://docs.aws.amazon.com/lambda/latest/dg/API_GetLayerVersion.html) | [ListFunctions](https://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctions.html)
|
|
56
56
|
- IAM: [GetRolePolicy](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetRolePolicy.html) | [GetPolicy](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicy.html) | [GetPolicyVersion](https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicyVersion.html) | [ListRolePolicies](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListRolePolicies.html) | [ListAttachedRolePolicies](https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListAttachedRolePolicies.html)
|
|
57
57
|
|
|
58
58
|
### Start scanning
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const i18n = require('i18n');
|
|
3
2
|
const { getHttpClient, handleResponseErrors } = require('../../utils/commonApi');
|
|
4
|
-
const displaySuccessMessage = () => {
|
|
5
|
-
console.log(i18n.__('catalogueSuccessCommand'));
|
|
6
|
-
};
|
|
7
3
|
const catalogueApplication = async (config) => {
|
|
8
4
|
const client = getHttpClient(config);
|
|
9
5
|
let appId;
|
|
@@ -13,6 +9,9 @@ const catalogueApplication = async (config) => {
|
|
|
13
9
|
if (res.statusCode === 201) {
|
|
14
10
|
appId = res.body.application.app_id;
|
|
15
11
|
}
|
|
12
|
+
else if (doesMessagesContainAppId(res)) {
|
|
13
|
+
appId = tryRetrieveAppIdFromMessages(res.body.messages);
|
|
14
|
+
}
|
|
16
15
|
else {
|
|
17
16
|
handleResponseErrors(res, 'catalogue');
|
|
18
17
|
}
|
|
@@ -22,6 +21,25 @@ const catalogueApplication = async (config) => {
|
|
|
22
21
|
});
|
|
23
22
|
return appId;
|
|
24
23
|
};
|
|
24
|
+
const doesMessagesContainAppId = res => {
|
|
25
|
+
const regex = /(Application ID =)/;
|
|
26
|
+
if (res.statusCode === 400 &&
|
|
27
|
+
res.body.messages.filter(message => regex.exec(message))[0]) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
const tryRetrieveAppIdFromMessages = messages => {
|
|
33
|
+
let appId;
|
|
34
|
+
messages.forEach(message => {
|
|
35
|
+
if (message.includes('Application ID')) {
|
|
36
|
+
appId = message.split('=')[1].replace(/\s+/g, '');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return appId;
|
|
40
|
+
};
|
|
25
41
|
module.exports = {
|
|
26
|
-
catalogueApplication: catalogueApplication
|
|
42
|
+
catalogueApplication: catalogueApplication,
|
|
43
|
+
doesMessagesContainAppId,
|
|
44
|
+
tryRetrieveAppIdFromMessages
|
|
27
45
|
};
|
|
@@ -2,38 +2,29 @@
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const i18n = require('i18n');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const getDirectoryFromPathGiven = file => {
|
|
6
|
+
let projectStats = getProjectStats(file);
|
|
7
|
+
if (projectStats.isFile()) {
|
|
8
|
+
let newPath = path.resolve(file);
|
|
9
|
+
return path.dirname(newPath);
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return;
|
|
11
|
+
if (projectStats.isDirectory()) {
|
|
12
|
+
return file;
|
|
13
13
|
}
|
|
14
|
-
next();
|
|
15
14
|
};
|
|
16
|
-
const
|
|
17
|
-
let projectStats = null;
|
|
15
|
+
const getProjectStats = file => {
|
|
18
16
|
try {
|
|
19
|
-
|
|
17
|
+
if (file.endsWith('/')) {
|
|
18
|
+
file = file.slice(0, -1);
|
|
19
|
+
}
|
|
20
|
+
return fs.statSync(file);
|
|
20
21
|
}
|
|
21
22
|
catch (err) {
|
|
22
|
-
throw new Error(i18n.__('languageAnalysisProjectRootFileNameFailure',
|
|
23
|
+
throw new Error(i18n.__('languageAnalysisProjectRootFileNameFailure', file) +
|
|
23
24
|
`${err.message}`);
|
|
24
25
|
}
|
|
25
|
-
if (projectStats.isDirectory()) {
|
|
26
|
-
try {
|
|
27
|
-
return fs.readdirSync(projectPath);
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
throw new Error(i18n.__('languageAnalysisProjectRootFileNameReadError', projectPath) +
|
|
31
|
-
`${err.message}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (projectStats.isFile()) {
|
|
35
|
-
return [path.basename(projectPath)];
|
|
36
|
-
}
|
|
37
|
-
throw new Error(i18n.__('languageAnalysisProjectRootFileNameMissingError'), projectPath);
|
|
38
26
|
};
|
|
39
|
-
exports
|
|
27
|
+
module.exports = {
|
|
28
|
+
getProjectStats,
|
|
29
|
+
getDirectoryFromPathGiven: getDirectoryFromPathGiven
|
|
30
|
+
};
|
|
@@ -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.getNumOfAndSeverityType = exports.buildFormattedHeaderNum = exports.buildBody = exports.buildHeader = exports.printFormattedOutput = exports.printVulnerabilityResponse = exports.getReport = exports.
|
|
6
|
+
exports.getNumOfAndSeverityType = exports.buildFormattedHeaderNum = exports.gatherRemediationAdvice = exports.buildBody = exports.buildHeader = exports.printFormattedOutput = exports.printVulnerabilityResponse = exports.getReport = exports.createSummaryMessage = void 0;
|
|
7
7
|
const commonApi_1 = require("../../../utils/commonApi");
|
|
8
8
|
const reportListModel_1 = require("./models/reportListModel");
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
@@ -11,12 +11,14 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
11
11
|
const reportUtils_1 = require("./utils/reportUtils");
|
|
12
12
|
const severityCountModel_1 = require("./models/severityCountModel");
|
|
13
13
|
const reportOutputModel_1 = require("./models/reportOutputModel");
|
|
14
|
-
const
|
|
14
|
+
const constants_1 = require("../../../constants/constants");
|
|
15
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
16
|
+
const createSummaryMessage = (numberOfVulnerableLibraries, numberOfCves) => {
|
|
15
17
|
numberOfVulnerableLibraries === 1
|
|
16
|
-
? console.log(`
|
|
17
|
-
: console.log(`
|
|
18
|
+
? console.log(`Found 1 vulnerable library containing ${numberOfCves} CVE`)
|
|
19
|
+
: console.log(`Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVEs`);
|
|
18
20
|
};
|
|
19
|
-
exports.
|
|
21
|
+
exports.createSummaryMessage = createSummaryMessage;
|
|
20
22
|
const getReport = async (config, reportId) => {
|
|
21
23
|
const client = (0, commonApi_1.getHttpClient)(config);
|
|
22
24
|
return client
|
|
@@ -26,10 +28,6 @@ const getReport = async (config, reportId) => {
|
|
|
26
28
|
return res.body;
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
console.log('config-------------------');
|
|
30
|
-
console.log(config);
|
|
31
|
-
console.log('reportId----------------');
|
|
32
|
-
console.log(reportId);
|
|
33
31
|
console.log(JSON.stringify(res));
|
|
34
32
|
(0, commonApi_1.handleResponseErrors)(res, 'report');
|
|
35
33
|
}
|
|
@@ -39,75 +37,121 @@ const getReport = async (config, reportId) => {
|
|
|
39
37
|
});
|
|
40
38
|
};
|
|
41
39
|
exports.getReport = getReport;
|
|
42
|
-
const printVulnerabilityResponse = (
|
|
40
|
+
const printVulnerabilityResponse = (config, vulnerableLibraries, numberOfVulnerableLibraries, numberOfCves, guidance) => {
|
|
43
41
|
let hasSomeVulnerabilitiesReported = false;
|
|
44
|
-
(0, exports.printFormattedOutput)(
|
|
45
|
-
if (Object.keys(
|
|
42
|
+
(0, exports.printFormattedOutput)(config, vulnerableLibraries, numberOfVulnerableLibraries, numberOfCves, guidance);
|
|
43
|
+
if (Object.keys(vulnerableLibraries).length > 0) {
|
|
46
44
|
hasSomeVulnerabilitiesReported = true;
|
|
47
45
|
}
|
|
48
46
|
return hasSomeVulnerabilitiesReported;
|
|
49
47
|
};
|
|
50
48
|
exports.printVulnerabilityResponse = printVulnerabilityResponse;
|
|
51
|
-
const printFormattedOutput = (libraries,
|
|
49
|
+
const printFormattedOutput = (config, libraries, numberOfVulnerableLibraries, numberOfCves, guidance) => {
|
|
50
|
+
(0, exports.createSummaryMessage)(numberOfVulnerableLibraries, numberOfCves);
|
|
51
|
+
console.log();
|
|
52
52
|
const report = new reportListModel_1.ReportList();
|
|
53
53
|
for (const library of libraries) {
|
|
54
54
|
const { name, version } = (0, reportUtils_1.findNameAndVersion)(library, config);
|
|
55
|
-
const newOutputModel = new reportListModel_1.ReportModelStructure(new reportListModel_1.ReportCompositeKey(name, version, (0, reportUtils_1.findHighestSeverityCVE)(library.cveArray)), library.cveArray);
|
|
55
|
+
const newOutputModel = new reportListModel_1.ReportModelStructure(new reportListModel_1.ReportCompositeKey(name, version, (0, reportUtils_1.findHighestSeverityCVE)(library.cveArray), (0, reportUtils_1.severityCountAllCVEs)(library.cveArray, new severityCountModel_1.SeverityCountModel()).getTotal), library.cveArray);
|
|
56
56
|
report.reportOutputList.push(newOutputModel);
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const outputOrderedByLowestSeverityAndLowestNumOfCvesFirst = (0, lodash_1.orderBy)(report.reportOutputList, [
|
|
59
|
+
(reportListItem) => {
|
|
60
|
+
return reportListItem.compositeKey.highestSeverity.priority;
|
|
61
|
+
},
|
|
62
|
+
(reportListItem) => {
|
|
63
|
+
return reportListItem.compositeKey.numberOfSeverities;
|
|
64
|
+
}
|
|
65
|
+
], ['asc', 'desc']);
|
|
59
66
|
let contrastHeaderNumCounter = 0;
|
|
60
|
-
for (const reportModel of
|
|
67
|
+
for (const reportModel of outputOrderedByLowestSeverityAndLowestNumOfCvesFirst) {
|
|
61
68
|
contrastHeaderNumCounter++;
|
|
62
69
|
const { libraryName, libraryVersion, highestSeverity } = reportModel.compositeKey;
|
|
63
70
|
const numOfCVEs = reportModel.cveArray.length;
|
|
71
|
+
const table = new cli_table3_1.default({
|
|
72
|
+
chars: {
|
|
73
|
+
top: '',
|
|
74
|
+
'top-mid': '',
|
|
75
|
+
'top-left': '',
|
|
76
|
+
'top-right': '',
|
|
77
|
+
bottom: '',
|
|
78
|
+
'bottom-mid': '',
|
|
79
|
+
'bottom-left': '',
|
|
80
|
+
'bottom-right': '',
|
|
81
|
+
left: '',
|
|
82
|
+
'left-mid': '',
|
|
83
|
+
mid: '',
|
|
84
|
+
'mid-mid': '',
|
|
85
|
+
right: '',
|
|
86
|
+
'right-mid': '',
|
|
87
|
+
middle: ' '
|
|
88
|
+
},
|
|
89
|
+
style: { 'padding-left': 0, 'padding-right': 0 },
|
|
90
|
+
colAligns: ['right'],
|
|
91
|
+
wordWrap: true,
|
|
92
|
+
colWidths: [12, 1, 100]
|
|
93
|
+
});
|
|
64
94
|
const header = buildHeader(highestSeverity, contrastHeaderNumCounter, libraryName, libraryVersion, numOfCVEs);
|
|
65
|
-
const
|
|
95
|
+
const advice = gatherRemediationAdvice(guidance, reportModel);
|
|
96
|
+
const body = buildBody(reportModel.cveArray, advice);
|
|
66
97
|
const reportOutputModel = new reportOutputModel_1.ReportOutputModel(header, body);
|
|
98
|
+
table.push(reportOutputModel.body.issueMessage, reportOutputModel.body.issueMessageCves, reportOutputModel.body.adviceMessage);
|
|
67
99
|
console.log(reportOutputModel.header.vulnMessage, reportOutputModel.header.introducesMessage);
|
|
68
|
-
console.log(
|
|
69
|
-
console.log(reportOutputModel.body.adviceMessage);
|
|
100
|
+
console.log(table.toString() + '\n');
|
|
70
101
|
}
|
|
102
|
+
(0, exports.createSummaryMessage)(numberOfVulnerableLibraries, numberOfCves);
|
|
103
|
+
const { criticalMessage, highMessage, mediumMessage, lowMessage, noteMessage } = buildFooter(outputOrderedByLowestSeverityAndLowestNumOfCvesFirst);
|
|
104
|
+
console.log(`${criticalMessage} | ${highMessage} | ${mediumMessage} | ${lowMessage} | ${noteMessage}`);
|
|
71
105
|
};
|
|
72
106
|
exports.printFormattedOutput = printFormattedOutput;
|
|
73
107
|
function buildHeader(highestSeverity, contrastHeaderNum, libraryName, version, numOfCVEs) {
|
|
74
|
-
const vulnerabilityPluralised = numOfCVEs > 1 ? '
|
|
108
|
+
const vulnerabilityPluralised = numOfCVEs > 1 ? 'vulnerabilities' : 'vulnerability';
|
|
75
109
|
const formattedHeaderNum = buildFormattedHeaderNum(contrastHeaderNum);
|
|
76
110
|
const vulnMessage = chalk_1.default
|
|
77
111
|
.hex(highestSeverity.outputColour)
|
|
78
112
|
.bold(`${formattedHeaderNum} - [${highestSeverity.severity}] ${libraryName}-${version}`);
|
|
79
|
-
const introducesMessage =
|
|
113
|
+
const introducesMessage = `introduces ${numOfCVEs} ${vulnerabilityPluralised}`;
|
|
80
114
|
return new reportOutputModel_1.ReportOutputHeaderModel(vulnMessage, introducesMessage);
|
|
81
115
|
}
|
|
82
116
|
exports.buildHeader = buildHeader;
|
|
83
|
-
function buildBody(cveArray) {
|
|
117
|
+
function buildBody(cveArray, advice) {
|
|
84
118
|
const cveMessages = [];
|
|
85
119
|
(0, reportUtils_1.findCVESeveritiesAndOrderByHighestPriority)(cveArray).forEach(reportSeverityModel => {
|
|
86
120
|
const { outputColour, severity, cveName } = reportSeverityModel;
|
|
87
121
|
const severityShorthand = chalk_1.default
|
|
88
122
|
.hex(outputColour)
|
|
89
123
|
.bold(`[${severity.charAt(0).toUpperCase()}]`);
|
|
90
|
-
const builtMessage =
|
|
124
|
+
const builtMessage = severityShorthand + cveName;
|
|
91
125
|
cveMessages.push(builtMessage);
|
|
92
126
|
});
|
|
93
127
|
const numAndSeverityType = getNumOfAndSeverityType(cveArray);
|
|
94
|
-
const issueMessage =
|
|
95
|
-
const
|
|
96
|
-
|
|
128
|
+
const issueMessage = [chalk_1.default.bold('Issue'), ':', `${numAndSeverityType}`];
|
|
129
|
+
const issueMessageCves = ['', '', cveMessages.join(', ')];
|
|
130
|
+
const displayAdvice = advice?.minimum
|
|
131
|
+
? `Update to version ${chalk_1.default.bold(advice.minimum)}`
|
|
132
|
+
: `Update to latest version`;
|
|
133
|
+
const adviceMessage = [chalk_1.default.bold('Advice'), ':', displayAdvice];
|
|
134
|
+
return new reportOutputModel_1.ReportOutputBodyModel(issueMessage, issueMessageCves, adviceMessage);
|
|
97
135
|
}
|
|
98
136
|
exports.buildBody = buildBody;
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
137
|
+
function gatherRemediationAdvice(guidance, reportModel) {
|
|
138
|
+
const guidanceData = {
|
|
139
|
+
minimum: undefined,
|
|
140
|
+
maximum: undefined,
|
|
141
|
+
latest: undefined
|
|
142
|
+
};
|
|
143
|
+
const data = guidance[reportModel.compositeKey.libraryName +
|
|
144
|
+
'@' +
|
|
145
|
+
reportModel.compositeKey.libraryVersion];
|
|
146
|
+
if (data) {
|
|
147
|
+
guidanceData.minimum = data.minUpgradeVersion;
|
|
148
|
+
guidanceData.maximum = data.maxUpgradeVersion;
|
|
109
149
|
}
|
|
110
|
-
return
|
|
150
|
+
return guidanceData;
|
|
151
|
+
}
|
|
152
|
+
exports.gatherRemediationAdvice = gatherRemediationAdvice;
|
|
153
|
+
function buildFormattedHeaderNum(contrastHeaderNum) {
|
|
154
|
+
return `CONTRAST-${contrastHeaderNum.toString().padStart(3, '0')}`;
|
|
111
155
|
}
|
|
112
156
|
exports.buildFormattedHeaderNum = buildFormattedHeaderNum;
|
|
113
157
|
function getNumOfAndSeverityType(cveArray) {
|
|
@@ -122,3 +166,20 @@ function getNumOfAndSeverityType(cveArray) {
|
|
|
122
166
|
.trim();
|
|
123
167
|
}
|
|
124
168
|
exports.getNumOfAndSeverityType = getNumOfAndSeverityType;
|
|
169
|
+
const buildFooter = (reportModelStructure) => {
|
|
170
|
+
const { critical, high, medium, low, note } = (0, reportUtils_1.countVulnerableLibrariesBySeverity)(reportModelStructure);
|
|
171
|
+
const criticalMessage = chalk_1.default
|
|
172
|
+
.hex(constants_1.CRITICAL_COLOUR)
|
|
173
|
+
.bold(`${critical} Critical`);
|
|
174
|
+
const highMessage = chalk_1.default.hex(constants_1.HIGH_COLOUR).bold(`${high} High`);
|
|
175
|
+
const mediumMessage = chalk_1.default.hex(constants_1.MEDIUM_COLOUR).bold(`${medium} Medium`);
|
|
176
|
+
const lowMessage = chalk_1.default.hex(constants_1.LOW_COLOUR).bold(`${low} Low`);
|
|
177
|
+
const noteMessage = chalk_1.default.hex(constants_1.NOTE_COLOUR).bold(`${note} Note`);
|
|
178
|
+
return {
|
|
179
|
+
criticalMessage,
|
|
180
|
+
highMessage,
|
|
181
|
+
mediumMessage,
|
|
182
|
+
lowMessage,
|
|
183
|
+
noteMessage
|
|
184
|
+
};
|
|
185
|
+
};
|
|
@@ -15,10 +15,11 @@ class ReportModelStructure {
|
|
|
15
15
|
}
|
|
16
16
|
exports.ReportModelStructure = ReportModelStructure;
|
|
17
17
|
class ReportCompositeKey {
|
|
18
|
-
constructor(libraryName, libraryVersion, highestSeverity) {
|
|
18
|
+
constructor(libraryName, libraryVersion, highestSeverity, numberOfSeverities) {
|
|
19
19
|
this.libraryName = libraryName;
|
|
20
20
|
this.libraryVersion = libraryVersion;
|
|
21
21
|
this.highestSeverity = highestSeverity;
|
|
22
|
+
this.numberOfSeverities = numberOfSeverities;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
exports.ReportCompositeKey = ReportCompositeKey;
|
|
@@ -16,9 +16,10 @@ class ReportOutputHeaderModel {
|
|
|
16
16
|
}
|
|
17
17
|
exports.ReportOutputHeaderModel = ReportOutputHeaderModel;
|
|
18
18
|
class ReportOutputBodyModel {
|
|
19
|
-
constructor(
|
|
20
|
-
this.issueMessage =
|
|
21
|
-
this.
|
|
19
|
+
constructor(issueMessage, issueMessageCves, adviceMessage) {
|
|
20
|
+
this.issueMessage = issueMessage;
|
|
21
|
+
this.issueMessageCves = issueMessageCves;
|
|
22
|
+
this.adviceMessage = adviceMessage;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
exports.ReportOutputBodyModel = ReportOutputBodyModel;
|
|
@@ -1,28 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatVulnerabilityOutput = exports.
|
|
29
|
+
exports.vulnerabilityReportV2 = exports.formatVulnerabilityOutput = exports.convertJSDotNetPython = exports.convertKeysToStandardFormat = void 0;
|
|
4
30
|
const commonReportingFunctions_1 = require("./commonReportingFunctions");
|
|
5
31
|
const reportUtils_1 = require("./utils/reportUtils");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
32
|
+
const i18n_1 = __importDefault(require("i18n"));
|
|
33
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
34
|
+
const constants = __importStar(require("../../../constants/constants"));
|
|
35
|
+
function convertKeysToStandardFormat(config, guidance) {
|
|
36
|
+
let convertedGuidance = guidance;
|
|
37
|
+
switch (config.language) {
|
|
38
|
+
case constants.supportedLanguages.JAVA:
|
|
39
|
+
case constants.supportedLanguages.GO:
|
|
40
|
+
case constants.supportedLanguages.PHP:
|
|
41
|
+
break;
|
|
42
|
+
case constants.supportedLanguages.NODE:
|
|
43
|
+
case constants.supportedLanguages.DOTNET:
|
|
44
|
+
case constants.supportedLanguages.PYTHON:
|
|
45
|
+
case constants.supportedLanguages.RUBY:
|
|
46
|
+
convertedGuidance = convertJSDotNetPython(guidance);
|
|
47
|
+
break;
|
|
12
48
|
}
|
|
49
|
+
return convertedGuidance;
|
|
13
50
|
}
|
|
14
|
-
exports.
|
|
15
|
-
function
|
|
16
|
-
const
|
|
51
|
+
exports.convertKeysToStandardFormat = convertKeysToStandardFormat;
|
|
52
|
+
function convertJSDotNetPython(guidance) {
|
|
53
|
+
const returnObject = {};
|
|
54
|
+
Object.entries(guidance).forEach(([key, value]) => {
|
|
55
|
+
const splitKey = key.split('/');
|
|
56
|
+
if (splitKey.length === 2) {
|
|
57
|
+
returnObject[splitKey[1]] = value;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return returnObject;
|
|
61
|
+
}
|
|
62
|
+
exports.convertJSDotNetPython = convertJSDotNetPython;
|
|
63
|
+
function formatVulnerabilityOutput(libraryVulnerabilityResponse, id, config, remediationGuidance) {
|
|
64
|
+
const vulnerableLibraries = (0, reportUtils_1.convertGenericToTypedLibraryVulns)(libraryVulnerabilityResponse);
|
|
65
|
+
const guidance = convertKeysToStandardFormat(config, remediationGuidance);
|
|
17
66
|
const numberOfVulnerableLibraries = vulnerableLibraries.length;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
67
|
+
if (numberOfVulnerableLibraries === 0) {
|
|
68
|
+
console.log(i18n_1.default.__('scanNoVulnerabilitiesFound'));
|
|
69
|
+
console.log(i18n_1.default.__('scanNoVulnerabilitiesFoundSecureCode'));
|
|
70
|
+
console.log(i18n_1.default.__('scanNoVulnerabilitiesFoundGoodWork'));
|
|
71
|
+
console.log(chalk_1.default.bold(`Found ${numberOfVulnerableLibraries} vulnerabilities`));
|
|
72
|
+
console.log(i18n_1.default.__('foundDetailedVulnerabilities', String(0), String(0), String(0), String(0), String(0)));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
let numberOfCves = 0;
|
|
76
|
+
vulnerableLibraries.forEach(lib => (numberOfCves += lib.cveArray.length));
|
|
77
|
+
const hasSomeVulnerabilitiesReported = (0, commonReportingFunctions_1.printVulnerabilityResponse)(config, vulnerableLibraries, numberOfVulnerableLibraries, numberOfCves, guidance);
|
|
78
|
+
return [
|
|
79
|
+
hasSomeVulnerabilitiesReported,
|
|
80
|
+
numberOfCves,
|
|
81
|
+
(0, reportUtils_1.severityCountAllLibraries)(vulnerableLibraries)
|
|
82
|
+
];
|
|
83
|
+
}
|
|
27
84
|
}
|
|
28
85
|
exports.formatVulnerabilityOutput = formatVulnerabilityOutput;
|
|
86
|
+
async function vulnerabilityReportV2(config, reportId) {
|
|
87
|
+
console.log();
|
|
88
|
+
const reportResponse = await (0, commonReportingFunctions_1.getReport)(config, reportId);
|
|
89
|
+
if (reportResponse !== undefined) {
|
|
90
|
+
const name = config.applicationName;
|
|
91
|
+
formatVulnerabilityOutput(reportResponse.vulnerabilities, config.applicationId, config, reportResponse.remediationGuidance
|
|
92
|
+
? reportResponse.remediationGuidance
|
|
93
|
+
: {});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.vulnerabilityReportV2 = vulnerabilityReportV2;
|
|
@@ -3,10 +3,10 @@ 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.findNameAndVersion = exports.severityCountSingleCVE = exports.severityCountAllCVEs = exports.severityCountAllLibraries = exports.
|
|
6
|
+
exports.countVulnerableLibrariesBySeverity = exports.findNameAndVersion = exports.severityCountSingleCVE = exports.severityCountAllCVEs = exports.severityCountAllLibraries = exports.convertGenericToTypedLibraryVulns = exports.findCVESeverity = exports.findCVESeveritiesAndOrderByHighestPriority = exports.findHighestSeverityCVE = void 0;
|
|
7
7
|
const reportLibraryModel_1 = require("../models/reportLibraryModel");
|
|
8
8
|
const reportSeverityModel_1 = require("../models/reportSeverityModel");
|
|
9
|
-
const constants_1 = __importDefault(require("
|
|
9
|
+
const constants_1 = __importDefault(require("./../../../../constants/constants"));
|
|
10
10
|
const constants_2 = require("../../../../constants/constants");
|
|
11
11
|
const lodash_1 = require("lodash");
|
|
12
12
|
const severityCountModel_1 = require("../models/severityCountModel");
|
|
@@ -40,12 +40,12 @@ function findCVESeverity(cve) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.findCVESeverity = findCVESeverity;
|
|
43
|
-
function
|
|
43
|
+
function convertGenericToTypedLibraryVulns(libraries) {
|
|
44
44
|
return Object.entries(libraries).map(([name, cveArray]) => {
|
|
45
45
|
return new reportLibraryModel_1.ReportLibraryModel(name, cveArray);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
exports.
|
|
48
|
+
exports.convertGenericToTypedLibraryVulns = convertGenericToTypedLibraryVulns;
|
|
49
49
|
function severityCountAllLibraries(vulnerableLibraries) {
|
|
50
50
|
const severityCount = new severityCountModel_1.SeverityCountModel();
|
|
51
51
|
vulnerableLibraries.forEach(lib => severityCountAllCVEs(lib.cveArray, severityCount));
|
|
@@ -86,11 +86,44 @@ function findNameAndVersion(library, config) {
|
|
|
86
86
|
return { name, version };
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
|
-
const
|
|
90
|
-
const nameVersion =
|
|
91
|
-
|
|
89
|
+
const uniqueSplitLibraryName = [...new Set(library.name.split('/'))];
|
|
90
|
+
const nameVersion = uniqueSplitLibraryName[1].split('@');
|
|
91
|
+
let parentLibrary;
|
|
92
|
+
let name;
|
|
93
|
+
if (uniqueSplitLibraryName[0] !== 'null' &&
|
|
94
|
+
uniqueSplitLibraryName[0] !== '' &&
|
|
95
|
+
!uniqueSplitLibraryName[1].includes(uniqueSplitLibraryName[0])) {
|
|
96
|
+
parentLibrary = uniqueSplitLibraryName[0];
|
|
97
|
+
name = `${parentLibrary}/${nameVersion[0]}`;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
name = nameVersion[0];
|
|
101
|
+
}
|
|
92
102
|
const version = nameVersion[1];
|
|
93
103
|
return { name, version };
|
|
94
104
|
}
|
|
95
105
|
}
|
|
96
106
|
exports.findNameAndVersion = findNameAndVersion;
|
|
107
|
+
function countVulnerableLibrariesBySeverity(reportModelStructure) {
|
|
108
|
+
const severityCount = new severityCountModel_1.SeverityCountModel();
|
|
109
|
+
reportModelStructure.forEach(vuln => {
|
|
110
|
+
const currentSeverity = vuln.compositeKey.highestSeverity.severity;
|
|
111
|
+
if (currentSeverity === 'CRITICAL') {
|
|
112
|
+
severityCount.critical += 1;
|
|
113
|
+
}
|
|
114
|
+
else if (currentSeverity === 'HIGH') {
|
|
115
|
+
severityCount.high += 1;
|
|
116
|
+
}
|
|
117
|
+
else if (currentSeverity === 'MEDIUM') {
|
|
118
|
+
severityCount.medium += 1;
|
|
119
|
+
}
|
|
120
|
+
else if (currentSeverity === 'LOW') {
|
|
121
|
+
severityCount.low += 1;
|
|
122
|
+
}
|
|
123
|
+
else if (currentSeverity === 'NOTE') {
|
|
124
|
+
severityCount.note += 1;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return severityCount;
|
|
128
|
+
}
|
|
129
|
+
exports.countVulnerableLibrariesBySeverity = countVulnerableLibrariesBySeverity;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const { handleResponseErrors } = require('../../common/errorHandling');
|
|
3
|
-
const { APP_VERSION } = require('../../constants/constants');
|
|
4
2
|
const commonApi = require('../../utils/commonApi');
|
|
5
3
|
const _ = require('lodash');
|
|
6
4
|
const oraFunctions = require('../../utils/oraWrapper');
|
|
@@ -8,28 +6,6 @@ const i18n = require('i18n');
|
|
|
8
6
|
const oraWrapper = require('../../utils/oraWrapper');
|
|
9
7
|
const requestUtils = require('../../utils/requestUtils');
|
|
10
8
|
const { performance } = require('perf_hooks');
|
|
11
|
-
const newSendSnapShot = async (analysis) => {
|
|
12
|
-
const analysisLanguage = analysis.config.language.toLowerCase();
|
|
13
|
-
const requestBody = {
|
|
14
|
-
appID: analysis.config.applicationId,
|
|
15
|
-
cliVersion: APP_VERSION,
|
|
16
|
-
snapshot: { [analysisLanguage]: analysis[analysisLanguage] }
|
|
17
|
-
};
|
|
18
|
-
const client = commonApi.getHttpClient(analysis.config);
|
|
19
|
-
return client
|
|
20
|
-
.sendSnapshot(requestBody, analysis.config)
|
|
21
|
-
.then(res => {
|
|
22
|
-
if (res.statusCode === 201) {
|
|
23
|
-
return res.body;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
handleResponseErrors(res, 'snapshot');
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
.catch(err => {
|
|
30
|
-
console.log(err);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
9
|
const pollSnapshotResults = async (config, snapshotId, client) => {
|
|
34
10
|
await requestUtils.sleep(5000);
|
|
35
11
|
return client
|
|
@@ -47,9 +23,9 @@ const getTimeout = config => {
|
|
|
47
23
|
}
|
|
48
24
|
else {
|
|
49
25
|
if (config.verbose) {
|
|
50
|
-
console.log('Timeout set to
|
|
26
|
+
console.log('Timeout set to 5 minutes');
|
|
51
27
|
}
|
|
52
|
-
return
|
|
28
|
+
return 300;
|
|
53
29
|
}
|
|
54
30
|
};
|
|
55
31
|
const pollForSnapshotCompletition = async (config, snapshotId, reportSpinner) => {
|
|
@@ -78,14 +54,14 @@ const pollForSnapshotCompletition = async (config, snapshotId, reportSpinner) =>
|
|
|
78
54
|
}
|
|
79
55
|
const endTime = performance.now() - startTime;
|
|
80
56
|
if (requestUtils.millisToSeconds(endTime) > timeout) {
|
|
81
|
-
oraFunctions.failSpinner(reportSpinner, 'Contrast audit timed out at the specified
|
|
82
|
-
|
|
83
|
-
|
|
57
|
+
oraFunctions.failSpinner(reportSpinner, 'Contrast audit timed out at the specified timeout of ' +
|
|
58
|
+
timeout +
|
|
59
|
+
' seconds.');
|
|
60
|
+
throw new Error('You can update the timeout using --timeout');
|
|
84
61
|
}
|
|
85
62
|
}
|
|
86
63
|
}
|
|
87
64
|
};
|
|
88
65
|
module.exports = {
|
|
89
|
-
newSendSnapShot: newSendSnapShot,
|
|
90
66
|
pollForSnapshotCompletition: pollForSnapshotCompletition
|
|
91
67
|
};
|