@contrast/contrast 1.0.0 → 1.0.1
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 +2 -0
- package/README.md +120 -47
- package/dist/audit/AnalysisEngine.js +37 -0
- package/dist/audit/catalogueApplication/catalogueApplication.js +36 -0
- package/dist/audit/dotnetAnalysisEngine/index.js +25 -0
- package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +35 -0
- package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +15 -0
- package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +18 -0
- package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +14 -0
- package/dist/audit/dotnetAnalysisEngine/sanitizer.js +9 -0
- package/dist/audit/goAnalysisEngine/index.js +17 -0
- package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +164 -0
- package/dist/audit/goAnalysisEngine/readProjectFileContents.js +21 -0
- package/dist/audit/goAnalysisEngine/sanitizer.js +5 -0
- package/dist/audit/javaAnalysisEngine/index.js +34 -0
- package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +153 -0
- package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +353 -0
- package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +98 -0
- package/dist/audit/javaAnalysisEngine/sanitizer.js +5 -0
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +24 -0
- package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +24 -0
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +35 -0
- package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +23 -0
- package/dist/audit/languageAnalysisEngine/commonApi.js +18 -0
- package/dist/audit/languageAnalysisEngine/constants.js +20 -0
- package/dist/audit/languageAnalysisEngine/filterProjectPath.js +20 -0
- package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +25 -0
- package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +39 -0
- package/dist/audit/languageAnalysisEngine/index.js +39 -0
- package/dist/audit/languageAnalysisEngine/langugageAnalysisFactory.js +70 -0
- package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +121 -0
- package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +17 -0
- package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +257 -0
- package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +81 -0
- package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +133 -0
- package/dist/audit/languageAnalysisEngine/sendSnapshot.js +41 -0
- package/dist/audit/languageAnalysisEngine/util/capabilities.js +11 -0
- package/dist/audit/languageAnalysisEngine/util/generalAPI.js +39 -0
- package/dist/audit/languageAnalysisEngine/util/requestUtils.js +14 -0
- package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +40 -0
- package/dist/audit/nodeAnalysisEngine/index.js +31 -0
- package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +18 -0
- package/dist/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +51 -0
- package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +18 -0
- package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +17 -0
- package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +14 -0
- package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +24 -0
- package/dist/audit/nodeAnalysisEngine/sanitizer.js +9 -0
- package/dist/audit/phpAnalysisEngine/index.js +23 -0
- package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +52 -0
- package/dist/audit/phpAnalysisEngine/readLockFileContents.js +13 -0
- package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +16 -0
- package/dist/audit/phpAnalysisEngine/sanitizer.js +5 -0
- package/dist/audit/pythonAnalysisEngine/index.js +25 -0
- package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +17 -0
- package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +21 -0
- package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +13 -0
- package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +14 -0
- package/dist/audit/pythonAnalysisEngine/sanitizer.js +7 -0
- package/dist/audit/rubyAnalysisEngine/index.js +25 -0
- package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +176 -0
- package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +22 -0
- package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +14 -0
- package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +14 -0
- package/dist/audit/rubyAnalysisEngine/sanitizer.js +6 -0
- package/dist/commands/audit/auditConfig.js +25 -0
- package/dist/commands/audit/auditController.js +31 -0
- package/dist/commands/audit/help.js +52 -0
- package/dist/commands/audit/processAudit.js +18 -0
- package/dist/commands/auth/auth.js +1 -1
- package/dist/commands/scan/processScan.js +19 -5
- package/dist/common/HTTPClient.js +101 -13
- package/dist/common/errorHandling.js +49 -1
- package/dist/common/findLatestCLIVersion.js +23 -0
- package/dist/constants/constants.js +1 -1
- package/dist/constants/lambda.js +32 -4
- package/dist/constants/locales.js +39 -16
- package/dist/constants.js +148 -20
- package/dist/index.js +7 -1
- package/dist/lambda/aws.js +14 -11
- package/dist/lambda/help.js +4 -0
- package/dist/lambda/lambda.js +50 -27
- package/dist/lambda/lambdaUtils.js +72 -0
- package/dist/lambda/logUtils.js +11 -1
- package/dist/lambda/scanDetailCompletion.js +4 -4
- package/dist/lambda/scanRequest.js +11 -5
- package/dist/lambda/utils.js +110 -53
- package/dist/scan/autoDetection.js +0 -32
- package/dist/scan/fileUtils.js +1 -1
- package/dist/scan/help.js +12 -40
- package/dist/scan/populateProjectIdAndProjectName.js +4 -0
- package/dist/scan/saveResults.js +15 -0
- package/dist/scan/scan.js +77 -42
- package/dist/scan/scanConfig.js +20 -0
- package/dist/scan/scanController.js +13 -15
- package/dist/scan/scanResults.js +18 -16
- package/dist/utils/commonApi.js +3 -3
- package/dist/utils/fileUtils.js +31 -0
- package/dist/utils/paramsUtil/commandlineParams.js +1 -20
- package/dist/utils/paramsUtil/genericCommandLineParams.js +12 -0
- package/dist/utils/paramsUtil/paramHandler.js +3 -6
- package/dist/utils/parsedCLIOptions.js +14 -8
- package/package.json +26 -21
- package/src/audit/AnalysisEngine.js +103 -0
- package/src/audit/catalogueApplication/catalogueApplication.js +42 -0
- package/src/audit/dotnetAnalysisEngine/index.js +26 -0
- package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +47 -0
- package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +29 -0
- package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +30 -0
- package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +26 -0
- package/src/audit/dotnetAnalysisEngine/sanitizer.js +11 -0
- package/src/audit/goAnalysisEngine/index.js +18 -0
- package/src/audit/goAnalysisEngine/parseProjectFileContents.js +209 -0
- package/src/audit/goAnalysisEngine/readProjectFileContents.js +31 -0
- package/src/audit/goAnalysisEngine/sanitizer.js +7 -0
- package/src/audit/javaAnalysisEngine/index.js +41 -0
- package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +222 -0
- package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +420 -0
- package/src/audit/javaAnalysisEngine/readProjectFileContents.js +141 -0
- package/src/audit/javaAnalysisEngine/sanitizer.js +6 -0
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +35 -0
- package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +41 -0
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +54 -0
- package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +32 -0
- package/src/audit/languageAnalysisEngine/commonApi.js +20 -0
- package/src/audit/languageAnalysisEngine/constants.js +23 -0
- package/src/audit/languageAnalysisEngine/filterProjectPath.js +21 -0
- package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +41 -0
- package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +72 -0
- package/src/audit/languageAnalysisEngine/index.js +45 -0
- package/src/audit/languageAnalysisEngine/langugageAnalysisFactory.js +94 -0
- package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +177 -0
- package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +27 -0
- package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +303 -0
- package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +124 -0
- package/src/audit/languageAnalysisEngine/report/reportingFeature.js +190 -0
- package/src/audit/languageAnalysisEngine/sendSnapshot.js +51 -0
- package/src/audit/languageAnalysisEngine/util/capabilities.js +12 -0
- package/src/audit/languageAnalysisEngine/util/generalAPI.js +43 -0
- package/src/audit/languageAnalysisEngine/util/requestUtils.js +17 -0
- package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +49 -0
- package/src/audit/nodeAnalysisEngine/index.js +35 -0
- package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +20 -0
- package/src/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +63 -0
- package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +26 -0
- package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +23 -0
- package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +27 -0
- package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +36 -0
- package/src/audit/nodeAnalysisEngine/sanitizer.js +11 -0
- package/src/audit/phpAnalysisEngine/index.js +27 -0
- package/src/audit/phpAnalysisEngine/parseLockFileContents.js +60 -0
- package/src/audit/phpAnalysisEngine/readLockFileContents.js +14 -0
- package/src/audit/phpAnalysisEngine/readProjectFileContents.js +25 -0
- package/src/audit/phpAnalysisEngine/sanitizer.js +4 -0
- package/src/audit/pythonAnalysisEngine/index.js +55 -0
- package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +23 -0
- package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +33 -0
- package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +16 -0
- package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +22 -0
- package/src/audit/pythonAnalysisEngine/sanitizer.js +9 -0
- package/src/audit/rubyAnalysisEngine/index.js +30 -0
- package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +215 -0
- package/src/audit/rubyAnalysisEngine/parsedGemfile.js +39 -0
- package/src/audit/rubyAnalysisEngine/readGemfileContents.js +18 -0
- package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +17 -0
- package/src/audit/rubyAnalysisEngine/sanitizer.js +8 -0
- package/src/commands/audit/auditConfig.ts +30 -0
- package/src/commands/audit/auditController.ts +31 -0
- package/src/commands/audit/help.ts +48 -0
- package/src/commands/audit/processAudit.ts +19 -0
- package/src/commands/auth/auth.js +1 -1
- package/src/commands/scan/processScan.js +20 -5
- package/src/common/HTTPClient.js +136 -14
- package/src/common/errorHandling.ts +56 -1
- package/src/common/findLatestCLIVersion.ts +27 -0
- package/src/constants/constants.js +1 -1
- package/src/constants/lambda.js +45 -4
- package/src/constants/locales.js +48 -20
- package/src/constants.js +168 -22
- package/src/index.ts +9 -2
- package/src/lambda/aws.ts +13 -12
- package/src/lambda/help.ts +4 -0
- package/src/lambda/lambda.ts +53 -34
- package/src/lambda/lambdaUtils.ts +111 -0
- package/src/lambda/logUtils.ts +19 -1
- package/src/lambda/scanDetailCompletion.ts +4 -4
- package/src/lambda/scanRequest.ts +13 -11
- package/src/lambda/utils.ts +149 -81
- package/src/scan/autoDetection.js +0 -29
- package/src/scan/fileUtils.js +1 -1
- package/src/scan/help.js +12 -45
- package/src/scan/populateProjectIdAndProjectName.js +4 -0
- package/src/scan/saveResults.js +15 -0
- package/src/scan/scan.js +95 -59
- package/src/scan/scanConfig.js +29 -0
- package/src/scan/scanController.js +13 -13
- package/src/scan/scanResults.js +21 -19
- package/src/utils/commonApi.js +2 -3
- package/src/utils/paramsUtil/commandlineParams.js +1 -26
- package/src/utils/paramsUtil/paramHandler.js +3 -7
- package/src/utils/parsedCLIOptions.js +11 -9
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const i18n = require('i18n');
|
|
3
|
+
module.exports = exports = (analysis, next) => {
|
|
4
|
+
const { languageAnalysis } = analysis;
|
|
5
|
+
try {
|
|
6
|
+
checkIdentifiedLanguageHasProjectFile(languageAnalysis.identifiedLanguages);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
next(err);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
next();
|
|
13
|
+
};
|
|
14
|
+
const checkIdentifiedLanguageHasProjectFile = identifiedLanguages => {
|
|
15
|
+
if (Object.keys(identifiedLanguages).length == 1) {
|
|
16
|
+
let { projectFilenames } = Object.values(identifiedLanguages)[0];
|
|
17
|
+
if (projectFilenames.length == 0) {
|
|
18
|
+
const [language] = Object.keys(identifiedLanguages);
|
|
19
|
+
throw new Error(i18n.__('languageAnalysisProjectFileError', language));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.checkIdentifiedLanguageHasProjectFile = checkIdentifiedLanguageHasProjectFile;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { getHttpClient } = require('../../utils/commonApi');
|
|
3
|
+
const returnAppId = async (config) => {
|
|
4
|
+
const client = getHttpClient(config);
|
|
5
|
+
let appId;
|
|
6
|
+
await client.getAppId(config).then(res => {
|
|
7
|
+
if (res.body) {
|
|
8
|
+
let obj = res.body['applications'];
|
|
9
|
+
if (obj) {
|
|
10
|
+
appId = obj.length === 0 ? '' : obj[0].app_id;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return appId;
|
|
15
|
+
};
|
|
16
|
+
module.exports = {
|
|
17
|
+
returnAppId: returnAppId
|
|
18
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const NODE = 'NODE';
|
|
3
|
+
const JAVASCRIPT = 'JAVASCRIPT';
|
|
4
|
+
const DOTNET = 'DOTNET';
|
|
5
|
+
const JAVA = 'JAVA';
|
|
6
|
+
const RUBY = 'RUBY';
|
|
7
|
+
const PYTHON = 'PYTHON';
|
|
8
|
+
const GO = 'GO';
|
|
9
|
+
const PHP = 'PHP';
|
|
10
|
+
const LOW = 'LOW';
|
|
11
|
+
const MEDIUM = 'MEDIUM';
|
|
12
|
+
const HIGH = 'HIGH';
|
|
13
|
+
const CRITICAL = 'CRITICAL';
|
|
14
|
+
module.exports = {
|
|
15
|
+
supportedLanguages: { NODE, DOTNET, JAVA, RUBY, PYTHON, GO, PHP, JAVASCRIPT },
|
|
16
|
+
LOW: LOW,
|
|
17
|
+
MEDIUM: MEDIUM,
|
|
18
|
+
HIGH: HIGH,
|
|
19
|
+
CRITICAL: CRITICAL
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const path = require('path');
|
|
3
|
+
function resolveFilePath(filepath) {
|
|
4
|
+
if (filepath[0] === '~') {
|
|
5
|
+
return path.join(process.env.HOME, filepath.slice(1));
|
|
6
|
+
}
|
|
7
|
+
return filepath;
|
|
8
|
+
}
|
|
9
|
+
const returnProjectPath = () => {
|
|
10
|
+
if (process.env.PWD !== (undefined || null || 'undefined')) {
|
|
11
|
+
return process.env.PWD;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return process.argv[process.argv.indexOf('--project_path') + 1];
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
module.exports = {
|
|
18
|
+
returnProjectPath: returnProjectPath,
|
|
19
|
+
resolveFilePath: resolveFilePath
|
|
20
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const path = require('path');
|
|
3
|
+
module.exports = exports = (analysis, next) => {
|
|
4
|
+
const { projectPath, languageAnalysis } = analysis;
|
|
5
|
+
languageAnalysis.identifiedLanguageInfo = getIdentifiedLanguageInfo(projectPath, languageAnalysis.identifiedLanguages);
|
|
6
|
+
next();
|
|
7
|
+
};
|
|
8
|
+
const getIdentifiedLanguageInfo = (projectPath, identifiedLanguages) => {
|
|
9
|
+
const [language] = Object.keys(identifiedLanguages);
|
|
10
|
+
const { projectFilenames: [projectFilename], lockFilenames: [lockFilename] } = Object.values(identifiedLanguages)[0];
|
|
11
|
+
let identifiedLanguageInfo = {
|
|
12
|
+
language,
|
|
13
|
+
projectFilename,
|
|
14
|
+
projectFilePath: path.join(projectPath, projectFilename)
|
|
15
|
+
};
|
|
16
|
+
if (lockFilename) {
|
|
17
|
+
identifiedLanguageInfo = {
|
|
18
|
+
...identifiedLanguageInfo,
|
|
19
|
+
lockFilename,
|
|
20
|
+
lockFilePath: path.join(projectPath, lockFilename)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return identifiedLanguageInfo;
|
|
24
|
+
};
|
|
25
|
+
exports.getIdentifiedLanguageInfo = getIdentifiedLanguageInfo;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const i18n = require('i18n');
|
|
5
|
+
module.exports = exports = (analysis, next) => {
|
|
6
|
+
const { projectPath, languageAnalysis } = analysis;
|
|
7
|
+
try {
|
|
8
|
+
languageAnalysis.projectRootFilenames = getProjectRootFilenames(projectPath);
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
next(err);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
next();
|
|
15
|
+
};
|
|
16
|
+
const getProjectRootFilenames = projectPath => {
|
|
17
|
+
let projectStats = null;
|
|
18
|
+
try {
|
|
19
|
+
projectStats = fs.statSync(projectPath);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
throw new Error(i18n.__('languageAnalysisProjectRootFileNameFailure', projectPath) +
|
|
23
|
+
`${err.message}`);
|
|
24
|
+
}
|
|
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
|
+
};
|
|
39
|
+
exports.getProjectRootFilenames = getProjectRootFilenames;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const AnalysisEngine = require('./../AnalysisEngine');
|
|
3
|
+
const i18n = require('i18n');
|
|
4
|
+
const getProjectRootFilenames = require('./getProjectRootFilenames');
|
|
5
|
+
const reduceIdentifiedLanguages = require('./reduceIdentifiedLanguages');
|
|
6
|
+
const checkForMultipleIdentifiedLanguages = require('./checkForMultipleIdentifiedLanguages');
|
|
7
|
+
const checkForMultipleIdentifiedProjectFiles = require('./checkForMultipleIdentifiedProjectFiles');
|
|
8
|
+
const checkIdentifiedLanguageHasProjectFile = require('./checkIdentifiedLanguageHasProjectFile');
|
|
9
|
+
const checkIdentifiedLanguageHasLockFile = require('./checkIdentifiedLanguageHasLockFile');
|
|
10
|
+
const getIdentifiedLanguageInfo = require('./getIdentifiedLanguageInfo');
|
|
11
|
+
const { libraryAnalysisError } = require('../../common/errorHandling');
|
|
12
|
+
module.exports = exports = (projectPath, callback, appId, config) => {
|
|
13
|
+
const ae = new AnalysisEngine({
|
|
14
|
+
projectPath,
|
|
15
|
+
appId,
|
|
16
|
+
languageAnalysis: { appId: appId },
|
|
17
|
+
config
|
|
18
|
+
});
|
|
19
|
+
ae.use([
|
|
20
|
+
getProjectRootFilenames,
|
|
21
|
+
reduceIdentifiedLanguages,
|
|
22
|
+
checkForMultipleIdentifiedLanguages,
|
|
23
|
+
checkForMultipleIdentifiedProjectFiles,
|
|
24
|
+
checkIdentifiedLanguageHasProjectFile,
|
|
25
|
+
checkIdentifiedLanguageHasLockFile,
|
|
26
|
+
getIdentifiedLanguageInfo
|
|
27
|
+
]);
|
|
28
|
+
ae.analyze((err, analysis) => {
|
|
29
|
+
if (err) {
|
|
30
|
+
console.log('*******************' +
|
|
31
|
+
i18n.__('languageAnalysisFailureMessage') +
|
|
32
|
+
'****************');
|
|
33
|
+
console.error(`${err.message}`);
|
|
34
|
+
libraryAnalysisError();
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
callback(null, analysis);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { supportedLanguages: { DOTNET, NODE, JAVA, RUBY, PYTHON, GO, PHP } } = require('../languageAnalysisEngine/constants');
|
|
3
|
+
const i18n = require('i18n');
|
|
4
|
+
const dotnetAE = require('../dotnetAnalysisEngine');
|
|
5
|
+
const nodeAE = require('../nodeAnalysisEngine');
|
|
6
|
+
const javaAE = require('../javaAnalysisEngine');
|
|
7
|
+
const rubyAE = require('../rubyAnalysisEngine');
|
|
8
|
+
const pythonAE = require('../pythonAnalysisEngine');
|
|
9
|
+
const phpAE = require('../phpAnalysisEngine');
|
|
10
|
+
const goAE = require('../goAnalysisEngine');
|
|
11
|
+
const { vulnerabilityReport } = require('./report/reportingFeature');
|
|
12
|
+
const { vulnReportWithoutDevDep } = require('./report/newReportingFeature');
|
|
13
|
+
const { checkDevDeps } = require('./report/checkIgnoreDevDep');
|
|
14
|
+
const { newSendSnapShot } = require('../languageAnalysisEngine/sendSnapshot');
|
|
15
|
+
module.exports = exports = (err, analysis) => {
|
|
16
|
+
const { identifiedLanguageInfo } = analysis.languageAnalysis;
|
|
17
|
+
const catalogueAppId = analysis.languageAnalysis.appId;
|
|
18
|
+
if (err) {
|
|
19
|
+
console.error(err);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const langCallback = async (err, analysis) => {
|
|
23
|
+
const config = analysis.config;
|
|
24
|
+
if (err) {
|
|
25
|
+
console.log();
|
|
26
|
+
console.log('***********' +
|
|
27
|
+
i18n.__('languageAnalysisFactoryFailureHeader') +
|
|
28
|
+
'****************');
|
|
29
|
+
console.log(identifiedLanguageInfo.language);
|
|
30
|
+
console.log();
|
|
31
|
+
console.error(`${identifiedLanguageInfo.language}` +
|
|
32
|
+
i18n.__('languageAnalysisFailure') +
|
|
33
|
+
err);
|
|
34
|
+
return process.exit(5);
|
|
35
|
+
}
|
|
36
|
+
console.log('\n **************CONTRAST OSS ANALYSIS BEGINS**************');
|
|
37
|
+
const snapshotResponse = await newSendSnapShot(analysis, catalogueAppId);
|
|
38
|
+
if (config.report) {
|
|
39
|
+
const ignoreDevUrl = await checkDevDeps(config);
|
|
40
|
+
if (ignoreDevUrl) {
|
|
41
|
+
await vulnReportWithoutDevDep(analysis, catalogueAppId, snapshotResponse.id, config);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
await vulnerabilityReport(analysis, catalogueAppId, config);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
console.log('\n ***************CONTRAST OSS ANALYSIS COMPLETE************** \n');
|
|
48
|
+
};
|
|
49
|
+
if (identifiedLanguageInfo.language === DOTNET) {
|
|
50
|
+
dotnetAE(identifiedLanguageInfo, analysis.config, langCallback);
|
|
51
|
+
}
|
|
52
|
+
if (identifiedLanguageInfo.language === NODE) {
|
|
53
|
+
nodeAE(identifiedLanguageInfo, analysis.config, langCallback);
|
|
54
|
+
}
|
|
55
|
+
if (identifiedLanguageInfo.language === JAVA) {
|
|
56
|
+
javaAE(identifiedLanguageInfo, analysis.config, langCallback);
|
|
57
|
+
}
|
|
58
|
+
if (identifiedLanguageInfo.language === RUBY) {
|
|
59
|
+
rubyAE(identifiedLanguageInfo, analysis.config, langCallback);
|
|
60
|
+
}
|
|
61
|
+
if (identifiedLanguageInfo.language === PYTHON) {
|
|
62
|
+
pythonAE(identifiedLanguageInfo, analysis.config, langCallback);
|
|
63
|
+
}
|
|
64
|
+
if (identifiedLanguageInfo.language === PHP) {
|
|
65
|
+
phpAE(identifiedLanguageInfo, analysis.config, langCallback);
|
|
66
|
+
}
|
|
67
|
+
if (identifiedLanguageInfo.language === GO) {
|
|
68
|
+
goAE(identifiedLanguageInfo, analysis.config, langCallback);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { supportedLanguages: { NODE, DOTNET, JAVA, RUBY, PYTHON, GO, PHP, JAVASCRIPT } } = require('./constants');
|
|
3
|
+
const i18n = require('i18n');
|
|
4
|
+
const DOT_NET_PROJECT_FILE_REGEX = /.+\.csproj$/;
|
|
5
|
+
const DOT_NET_LOCK_FILENAME = 'packages.lock.json';
|
|
6
|
+
const isDotNetProjectFilename = filename => filename.search(DOT_NET_PROJECT_FILE_REGEX) !== -1;
|
|
7
|
+
const isDotNetLockFilename = filename => filename === DOT_NET_LOCK_FILENAME;
|
|
8
|
+
function isJavaMavenProjectFilename(filename) {
|
|
9
|
+
return filename === 'pom.xml';
|
|
10
|
+
}
|
|
11
|
+
function isJavaGradleProjectFilename(filename) {
|
|
12
|
+
return filename === 'build.gradle' || filename === 'build.gradle.kts';
|
|
13
|
+
}
|
|
14
|
+
const isRubyProjectFilename = filename => filename === 'Gemfile';
|
|
15
|
+
const isNodeProjectFilename = filename => filename === 'package.json';
|
|
16
|
+
const isPythonProjectFilename = filename => filename === 'requirements.txt' || filename === 'Pipfile';
|
|
17
|
+
const isPhpProjectFilename = filename => filename === 'composer.json';
|
|
18
|
+
const isPhpLockFilename = filename => filename === 'composer.lock';
|
|
19
|
+
function isNodeLockFilename(filename) {
|
|
20
|
+
return filename === 'package-lock.json' || filename === 'yarn.lock';
|
|
21
|
+
}
|
|
22
|
+
const isRubyLockFilename = filename => filename === 'Gemfile.lock';
|
|
23
|
+
const isPipfileLockLockFilename = filename => filename === 'Pipfile.lock';
|
|
24
|
+
const isGoProjectFilename = filename => filename === 'go.mod';
|
|
25
|
+
const deduceLanguage = filename => {
|
|
26
|
+
const deducedLanguages = [];
|
|
27
|
+
if (isJavaMavenProjectFilename(filename)) {
|
|
28
|
+
deducedLanguages.push({ language: JAVA, projectFilename: filename });
|
|
29
|
+
}
|
|
30
|
+
if (isJavaGradleProjectFilename(filename)) {
|
|
31
|
+
deducedLanguages.push({ language: JAVA, projectFilename: filename });
|
|
32
|
+
}
|
|
33
|
+
if (isNodeProjectFilename(filename)) {
|
|
34
|
+
deducedLanguages.push({ language: NODE, projectFilename: filename });
|
|
35
|
+
}
|
|
36
|
+
if (isDotNetProjectFilename(filename)) {
|
|
37
|
+
deducedLanguages.push({ language: DOTNET, projectFilename: filename });
|
|
38
|
+
}
|
|
39
|
+
if (isRubyProjectFilename(filename)) {
|
|
40
|
+
deducedLanguages.push({ language: RUBY, projectFilename: filename });
|
|
41
|
+
}
|
|
42
|
+
if (isPythonProjectFilename(filename)) {
|
|
43
|
+
deducedLanguages.push({ language: PYTHON, projectFilename: filename });
|
|
44
|
+
}
|
|
45
|
+
if (isPhpProjectFilename(filename)) {
|
|
46
|
+
deducedLanguages.push({ language: PHP, projectFilename: filename });
|
|
47
|
+
}
|
|
48
|
+
if (isDotNetLockFilename(filename)) {
|
|
49
|
+
deducedLanguages.push({ language: DOTNET, lockFilename: filename });
|
|
50
|
+
}
|
|
51
|
+
if (isNodeLockFilename(filename)) {
|
|
52
|
+
deducedLanguages.push({ language: NODE, lockFilename: filename });
|
|
53
|
+
}
|
|
54
|
+
if (isRubyLockFilename(filename)) {
|
|
55
|
+
deducedLanguages.push({ language: RUBY, lockFilename: filename });
|
|
56
|
+
}
|
|
57
|
+
if (isPipfileLockLockFilename(filename)) {
|
|
58
|
+
deducedLanguages.push({ language: PYTHON, lockFilename: filename });
|
|
59
|
+
}
|
|
60
|
+
if (isPhpLockFilename(filename)) {
|
|
61
|
+
deducedLanguages.push({ language: PHP, lockFilename: filename });
|
|
62
|
+
}
|
|
63
|
+
if (isGoProjectFilename(filename)) {
|
|
64
|
+
deducedLanguages.push({ language: GO, projectFilename: filename });
|
|
65
|
+
}
|
|
66
|
+
return deducedLanguages;
|
|
67
|
+
};
|
|
68
|
+
const reduceIdentifiedLanguages = identifiedLanguages => identifiedLanguages.reduce((accumulator, identifiedLanguageInfo) => {
|
|
69
|
+
const { language, projectFilename, lockFilename } = identifiedLanguageInfo;
|
|
70
|
+
if (!(language in accumulator)) {
|
|
71
|
+
accumulator[language] = { projectFilenames: [], lockFilenames: [] };
|
|
72
|
+
}
|
|
73
|
+
if (projectFilename) {
|
|
74
|
+
accumulator[language].projectFilenames.push(projectFilename);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
accumulator[language].lockFilenames.push(lockFilename);
|
|
78
|
+
}
|
|
79
|
+
return accumulator;
|
|
80
|
+
}, {});
|
|
81
|
+
module.exports = exports = (analysis, next) => {
|
|
82
|
+
const { projectPath, languageAnalysis, config } = analysis;
|
|
83
|
+
let identifiedLanguages = languageAnalysis.projectRootFilenames.reduce((accumulator, filename) => {
|
|
84
|
+
const deducedLanguages = deduceLanguage(filename);
|
|
85
|
+
return [...accumulator, ...deducedLanguages];
|
|
86
|
+
}, []);
|
|
87
|
+
if (Object.keys(identifiedLanguages).length === 0) {
|
|
88
|
+
next(new Error(i18n.__('languageAnalysisNoLanguage', projectPath)));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let language = config.language;
|
|
92
|
+
if (language === undefined) {
|
|
93
|
+
languageAnalysis.identifiedLanguages = reduceIdentifiedLanguages(identifiedLanguages);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
let refinedIdentifiedLanguages = [];
|
|
97
|
+
for (let x in identifiedLanguages) {
|
|
98
|
+
if (identifiedLanguages[x].language === language.toUpperCase() ||
|
|
99
|
+
(identifiedLanguages[x].language === NODE &&
|
|
100
|
+
language.toUpperCase() === JAVASCRIPT)) {
|
|
101
|
+
refinedIdentifiedLanguages.push(identifiedLanguages[x]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (refinedIdentifiedLanguages.length === 0) {
|
|
105
|
+
console.log(`Could not detect language as specified: ${config.language}`);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
languageAnalysis.identifiedLanguages = reduceIdentifiedLanguages(refinedIdentifiedLanguages);
|
|
109
|
+
}
|
|
110
|
+
next();
|
|
111
|
+
};
|
|
112
|
+
exports.isJavaMavenProjectFilename = isJavaMavenProjectFilename;
|
|
113
|
+
exports.isJavaGradleProjectFilename = isJavaGradleProjectFilename;
|
|
114
|
+
exports.isNodeProjectFilename = isNodeProjectFilename;
|
|
115
|
+
exports.isDotNetProjectFilename = isDotNetProjectFilename;
|
|
116
|
+
exports.isDotNetLockFilename = isDotNetLockFilename;
|
|
117
|
+
exports.isGoProjectFilename = isGoProjectFilename;
|
|
118
|
+
exports.isPhpProjectFilename = isPhpProjectFilename;
|
|
119
|
+
exports.isPhpLockFilename = isPhpLockFilename;
|
|
120
|
+
exports.deduceLanguage = deduceLanguage;
|
|
121
|
+
exports.reduceIdentifiedLanguages = reduceIdentifiedLanguages;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { getGlobalProperties, getFeatures, isFeatureEnabled } = require('../util/generalAPI');
|
|
3
|
+
const { CLI_IGNORE_DEV_DEPS } = require('../util/capabilities');
|
|
4
|
+
const checkDevDeps = async (config) => {
|
|
5
|
+
const shouldIgnoreDev = config.ignoreDev;
|
|
6
|
+
const globalProperties = await getGlobalProperties();
|
|
7
|
+
const features = getFeatures(globalProperties.internal_version);
|
|
8
|
+
const isfeatureEnabled = isFeatureEnabled(features, CLI_IGNORE_DEV_DEPS);
|
|
9
|
+
let ignoreDevUrl = false;
|
|
10
|
+
if (shouldIgnoreDev) {
|
|
11
|
+
ignoreDevUrl = isfeatureEnabled;
|
|
12
|
+
}
|
|
13
|
+
return ignoreDevUrl;
|
|
14
|
+
};
|
|
15
|
+
module.exports = {
|
|
16
|
+
checkDevDeps
|
|
17
|
+
};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const i18n = require('i18n');
|
|
3
|
+
const { getHttpClient } = require('../../../utils/commonApi');
|
|
4
|
+
function displaySuccessMessageReport() {
|
|
5
|
+
console.log('\n' + i18n.__('reportSuccessMessage'));
|
|
6
|
+
}
|
|
7
|
+
function getAllDependenciesArray(packageJson) {
|
|
8
|
+
const { dependencies, optionalDependencies, devDependencies, peerDependencies } = packageJson;
|
|
9
|
+
const allDep = {
|
|
10
|
+
...dependencies,
|
|
11
|
+
...devDependencies,
|
|
12
|
+
...optionalDependencies,
|
|
13
|
+
...peerDependencies
|
|
14
|
+
};
|
|
15
|
+
return Object.entries(allDep);
|
|
16
|
+
}
|
|
17
|
+
function checkIfDepIsScoped(arrDep) {
|
|
18
|
+
let count = 0;
|
|
19
|
+
arrDep.forEach(([key, value]) => {
|
|
20
|
+
if (!key.startsWith('@')) {
|
|
21
|
+
console.log(` WARNING not scoped: ${key}:${value}`);
|
|
22
|
+
count++;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return count;
|
|
26
|
+
}
|
|
27
|
+
const dependencyRiskReport = async (packageJson, config) => {
|
|
28
|
+
const arrDep = getAllDependenciesArray(packageJson);
|
|
29
|
+
const unRegisteredDeps = await checkIfDepIsRegisteredOnNPM(arrDep, config);
|
|
30
|
+
let scopedCount = checkIfDepIsScoped(unRegisteredDeps);
|
|
31
|
+
return {
|
|
32
|
+
scopedCount: scopedCount,
|
|
33
|
+
unRegisteredCount: unRegisteredDeps.length
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const checkIfDepIsRegisteredOnNPM = async (arrDep, config) => {
|
|
37
|
+
let promises = [];
|
|
38
|
+
let unRegisteredDeps = [];
|
|
39
|
+
const client = getHttpClient(config);
|
|
40
|
+
for (const [index, element] of arrDep) {
|
|
41
|
+
const query = `query artifactByGAV($name: String!, $language: String!, $groupName: String, $version: String!, $nameCheck: Boolean) {
|
|
42
|
+
artifact: exactVersion(name: $name, language: $language, groupName: $groupName, version: $version, nameCheck: $nameCheck) {
|
|
43
|
+
version
|
|
44
|
+
cves {
|
|
45
|
+
baseScore
|
|
46
|
+
}}}`;
|
|
47
|
+
const data = {
|
|
48
|
+
query: query,
|
|
49
|
+
variables: {
|
|
50
|
+
name: index,
|
|
51
|
+
version: element,
|
|
52
|
+
language: 'node',
|
|
53
|
+
nameCheck: true
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
promises.push(client.checkLibrary(data));
|
|
57
|
+
}
|
|
58
|
+
await Promise.all(promises).then(response => {
|
|
59
|
+
response.forEach(res => {
|
|
60
|
+
const libName = JSON.parse(res.request.body);
|
|
61
|
+
if (res.statusCode === 200) {
|
|
62
|
+
if (res.body.data.artifact == null) {
|
|
63
|
+
unRegisteredDeps.push([
|
|
64
|
+
libName.variables.name,
|
|
65
|
+
libName.variables.version
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
if (unRegisteredDeps.length !== 0) {
|
|
72
|
+
console.log('\n Dependencies Risk Report', '\n\n Private libraries that are not scoped. We recommend these libraries are reviewed and the scope claimed to prevent dependency confusion breaches');
|
|
73
|
+
}
|
|
74
|
+
return unRegisteredDeps;
|
|
75
|
+
};
|
|
76
|
+
const createLibraryHeader = (id, numberOfVulnerableLibraries, numberOfCves, name) => {
|
|
77
|
+
name
|
|
78
|
+
? console.log(` Application Name: ${name} | Application ID: ${id}`)
|
|
79
|
+
: console.log(` Application ID: ${id}`);
|
|
80
|
+
console.log(` Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVE's`);
|
|
81
|
+
};
|
|
82
|
+
const breakPipeline = () => {
|
|
83
|
+
failOptionError();
|
|
84
|
+
process.exit(1);
|
|
85
|
+
};
|
|
86
|
+
const parameterOptions = hasSomeVulnerabilitiesReported => {
|
|
87
|
+
const inputtedCLIOptions = cliOptions.getCommandLineArgs();
|
|
88
|
+
let cveSeverityOption = inputtedCLIOptions['cve_severity'];
|
|
89
|
+
let fail = inputtedCLIOptions['fail'];
|
|
90
|
+
let cve_threshold = inputtedCLIOptions['cve_threshold'];
|
|
91
|
+
let expr;
|
|
92
|
+
if (cveSeverityOption && fail && cve_threshold) {
|
|
93
|
+
expr = 'SeverityAndThreshold';
|
|
94
|
+
}
|
|
95
|
+
else if (!cveSeverityOption && fail && cve_threshold) {
|
|
96
|
+
expr = 'ThresholdOnly';
|
|
97
|
+
}
|
|
98
|
+
else if (!cve_threshold && fail && hasSomeVulnerabilitiesReported[0]) {
|
|
99
|
+
expr = 'FailOnly';
|
|
100
|
+
}
|
|
101
|
+
return expr;
|
|
102
|
+
};
|
|
103
|
+
const analyseReportOptions = hasSomeVulnerabilitiesReported => {
|
|
104
|
+
const inputtedCLIOptions = cliOptions.getCommandLineArgs();
|
|
105
|
+
let cve_threshold = inputtedCLIOptions['cve_threshold'];
|
|
106
|
+
let cveSeverity;
|
|
107
|
+
let criticalSeverity;
|
|
108
|
+
let highSeverity;
|
|
109
|
+
let mediumSeverity;
|
|
110
|
+
let lowSeverity;
|
|
111
|
+
switch (parameterOptions(hasSomeVulnerabilitiesReported)) {
|
|
112
|
+
case 'SeverityAndThreshold':
|
|
113
|
+
cveSeverity = inputtedCLIOptions['cve_severity'].severity;
|
|
114
|
+
criticalSeverity = hasSomeVulnerabilitiesReported[2].critical;
|
|
115
|
+
highSeverity = hasSomeVulnerabilitiesReported[2].high;
|
|
116
|
+
mediumSeverity = hasSomeVulnerabilitiesReported[2].medium;
|
|
117
|
+
lowSeverity = hasSomeVulnerabilitiesReported[2].low;
|
|
118
|
+
if (cveSeverity === 'HIGH') {
|
|
119
|
+
if (cve_threshold < highSeverity + criticalSeverity) {
|
|
120
|
+
breakPipeline();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (cveSeverity === 'MEDIUM') {
|
|
124
|
+
if (cve_threshold < mediumSeverity + highSeverity) {
|
|
125
|
+
breakPipeline();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (cveSeverity === 'LOW') {
|
|
129
|
+
if (cve_threshold < lowSeverity + mediumSeverity + highSeverity) {
|
|
130
|
+
breakPipeline();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
case 'ThresholdOnly':
|
|
135
|
+
if (cve_threshold < hasSomeVulnerabilitiesReported[1]) {
|
|
136
|
+
breakPipeline();
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
case 'FailOnly':
|
|
140
|
+
breakPipeline();
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const getReport = async (applicationId) => {
|
|
145
|
+
const userParams = await util.getParams(applicationId);
|
|
146
|
+
const addParams = agent.getAdditionalParams();
|
|
147
|
+
const protocol = getValidHost(userParams.host);
|
|
148
|
+
const client = commonApi.getHttpClient(userParams, protocol, addParams);
|
|
149
|
+
return client
|
|
150
|
+
.getReport(userParams)
|
|
151
|
+
.then(res => {
|
|
152
|
+
if (res.statusCode === 200) {
|
|
153
|
+
displaySuccessMessageReport();
|
|
154
|
+
return res.body;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
handleResponseErrors(res, 'report');
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
.catch(err => {
|
|
161
|
+
console.log(err);
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
const printVulnerabilityResponse = (severity, filteredVulns, vulnerabilities) => {
|
|
165
|
+
let hasSomeVulnerabilitiesReported = false;
|
|
166
|
+
if (severity) {
|
|
167
|
+
returnCveData(filteredVulns);
|
|
168
|
+
if (Object.keys(filteredVulns).length > 0)
|
|
169
|
+
hasSomeVulnerabilitiesReported = true;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
returnCveData(vulnerabilities);
|
|
173
|
+
if (Object.keys(vulnerabilities).length > 0)
|
|
174
|
+
hasSomeVulnerabilitiesReported = true;
|
|
175
|
+
}
|
|
176
|
+
return hasSomeVulnerabilitiesReported;
|
|
177
|
+
};
|
|
178
|
+
const returnCveData = libraries => {
|
|
179
|
+
console.log('\n ************************************************************');
|
|
180
|
+
for (const [key, value] of Object.entries(libraries)) {
|
|
181
|
+
const parts = key.split('/');
|
|
182
|
+
const nameVersion = parts[1].split('@');
|
|
183
|
+
const group = parts[0];
|
|
184
|
+
const name = nameVersion[0];
|
|
185
|
+
const version = nameVersion[1];
|
|
186
|
+
const libName = group !== 'null'
|
|
187
|
+
? `${group}/${name}/${version} is vulnerable`
|
|
188
|
+
: `${name}/${version} is vulnerable`;
|
|
189
|
+
console.log('\n\n ' + libName);
|
|
190
|
+
value.forEach(vuln => {
|
|
191
|
+
let sevCode = vuln.severityCode || vuln.severity_code;
|
|
192
|
+
console.log('\n ' + vuln.name + ' ' + sevCode + '\n ' + vuln.description);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
function searchHighCVEs(vuln) {
|
|
197
|
+
let sevCode = vuln.severityCode || vuln.severity_code;
|
|
198
|
+
if (sevCode === 'HIGH') {
|
|
199
|
+
return vuln;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function searchMediumCVEs(vuln) {
|
|
203
|
+
let sevCode = vuln.severityCode || vuln.severity_code;
|
|
204
|
+
if (sevCode === 'HIGH' || sevCode === 'MEDIUM') {
|
|
205
|
+
return vuln;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function searchLowCVEs(vuln) {
|
|
209
|
+
let sevCode = vuln.severityCode || vuln.severity_code;
|
|
210
|
+
if (sevCode === 'HIGH' || sevCode === 'MEDIUM' || sevCode === 'LOW') {
|
|
211
|
+
return vuln;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const filterVulnerabilitiesBySeverity = (severity, vulnerabilities) => {
|
|
215
|
+
let filteredVulns = [];
|
|
216
|
+
if (severity) {
|
|
217
|
+
for (let x in vulnerabilities) {
|
|
218
|
+
if (severity.severity === 'HIGH') {
|
|
219
|
+
let highVulnerability = vulnerabilities[x].filter(searchHighCVEs);
|
|
220
|
+
if (highVulnerability.length > 0) {
|
|
221
|
+
filteredVulns[x] = highVulnerability;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else if (severity.severity === 'MEDIUM') {
|
|
225
|
+
let mediumVulnerability = vulnerabilities[x].filter(searchMediumCVEs);
|
|
226
|
+
if (mediumVulnerability.length > 0) {
|
|
227
|
+
filteredVulns[x] = mediumVulnerability;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else if (severity.severity === 'LOW') {
|
|
231
|
+
let lowVulnerability = vulnerabilities[x].filter(searchLowCVEs);
|
|
232
|
+
if (lowVulnerability.length > 0) {
|
|
233
|
+
filteredVulns[x] = lowVulnerability;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return filteredVulns;
|
|
239
|
+
};
|
|
240
|
+
module.exports = {
|
|
241
|
+
displaySuccessMessageReport: displaySuccessMessageReport,
|
|
242
|
+
getAllDependenciesArray: getAllDependenciesArray,
|
|
243
|
+
dependencyRiskReport: dependencyRiskReport,
|
|
244
|
+
createLibraryHeader: createLibraryHeader,
|
|
245
|
+
breakPipeline: breakPipeline,
|
|
246
|
+
parameterOptions: parameterOptions,
|
|
247
|
+
analyseReportOptions: analyseReportOptions,
|
|
248
|
+
getReport: getReport,
|
|
249
|
+
checkIfDepIsScoped: checkIfDepIsScoped,
|
|
250
|
+
checkIfDepIsRegisteredOnNPM: checkIfDepIsRegisteredOnNPM,
|
|
251
|
+
filterVulnerabilitiesBySeverity: filterVulnerabilitiesBySeverity,
|
|
252
|
+
searchLowCVEs: searchLowCVEs,
|
|
253
|
+
searchMediumCVEs: searchMediumCVEs,
|
|
254
|
+
searchHighCVEs: searchHighCVEs,
|
|
255
|
+
returnCveData: returnCveData,
|
|
256
|
+
printVulnerabilityResponse: printVulnerabilityResponse
|
|
257
|
+
};
|