@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.
Files changed (201) hide show
  1. package/.prettierignore +2 -0
  2. package/README.md +120 -47
  3. package/dist/audit/AnalysisEngine.js +37 -0
  4. package/dist/audit/catalogueApplication/catalogueApplication.js +36 -0
  5. package/dist/audit/dotnetAnalysisEngine/index.js +25 -0
  6. package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +35 -0
  7. package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +15 -0
  8. package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +18 -0
  9. package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +14 -0
  10. package/dist/audit/dotnetAnalysisEngine/sanitizer.js +9 -0
  11. package/dist/audit/goAnalysisEngine/index.js +17 -0
  12. package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +164 -0
  13. package/dist/audit/goAnalysisEngine/readProjectFileContents.js +21 -0
  14. package/dist/audit/goAnalysisEngine/sanitizer.js +5 -0
  15. package/dist/audit/javaAnalysisEngine/index.js +34 -0
  16. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +153 -0
  17. package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +353 -0
  18. package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +98 -0
  19. package/dist/audit/javaAnalysisEngine/sanitizer.js +5 -0
  20. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +24 -0
  21. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +24 -0
  22. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +35 -0
  23. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +23 -0
  24. package/dist/audit/languageAnalysisEngine/commonApi.js +18 -0
  25. package/dist/audit/languageAnalysisEngine/constants.js +20 -0
  26. package/dist/audit/languageAnalysisEngine/filterProjectPath.js +20 -0
  27. package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +25 -0
  28. package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +39 -0
  29. package/dist/audit/languageAnalysisEngine/index.js +39 -0
  30. package/dist/audit/languageAnalysisEngine/langugageAnalysisFactory.js +70 -0
  31. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +121 -0
  32. package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +17 -0
  33. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +257 -0
  34. package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +81 -0
  35. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +133 -0
  36. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +41 -0
  37. package/dist/audit/languageAnalysisEngine/util/capabilities.js +11 -0
  38. package/dist/audit/languageAnalysisEngine/util/generalAPI.js +39 -0
  39. package/dist/audit/languageAnalysisEngine/util/requestUtils.js +14 -0
  40. package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +40 -0
  41. package/dist/audit/nodeAnalysisEngine/index.js +31 -0
  42. package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +18 -0
  43. package/dist/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +51 -0
  44. package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +18 -0
  45. package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +17 -0
  46. package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +14 -0
  47. package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +24 -0
  48. package/dist/audit/nodeAnalysisEngine/sanitizer.js +9 -0
  49. package/dist/audit/phpAnalysisEngine/index.js +23 -0
  50. package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +52 -0
  51. package/dist/audit/phpAnalysisEngine/readLockFileContents.js +13 -0
  52. package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +16 -0
  53. package/dist/audit/phpAnalysisEngine/sanitizer.js +5 -0
  54. package/dist/audit/pythonAnalysisEngine/index.js +25 -0
  55. package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +17 -0
  56. package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +21 -0
  57. package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +13 -0
  58. package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +14 -0
  59. package/dist/audit/pythonAnalysisEngine/sanitizer.js +7 -0
  60. package/dist/audit/rubyAnalysisEngine/index.js +25 -0
  61. package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +176 -0
  62. package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +22 -0
  63. package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +14 -0
  64. package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +14 -0
  65. package/dist/audit/rubyAnalysisEngine/sanitizer.js +6 -0
  66. package/dist/commands/audit/auditConfig.js +25 -0
  67. package/dist/commands/audit/auditController.js +31 -0
  68. package/dist/commands/audit/help.js +52 -0
  69. package/dist/commands/audit/processAudit.js +18 -0
  70. package/dist/commands/auth/auth.js +1 -1
  71. package/dist/commands/scan/processScan.js +19 -5
  72. package/dist/common/HTTPClient.js +101 -13
  73. package/dist/common/errorHandling.js +49 -1
  74. package/dist/common/findLatestCLIVersion.js +23 -0
  75. package/dist/constants/constants.js +1 -1
  76. package/dist/constants/lambda.js +32 -4
  77. package/dist/constants/locales.js +39 -16
  78. package/dist/constants.js +148 -20
  79. package/dist/index.js +7 -1
  80. package/dist/lambda/aws.js +14 -11
  81. package/dist/lambda/help.js +4 -0
  82. package/dist/lambda/lambda.js +50 -27
  83. package/dist/lambda/lambdaUtils.js +72 -0
  84. package/dist/lambda/logUtils.js +11 -1
  85. package/dist/lambda/scanDetailCompletion.js +4 -4
  86. package/dist/lambda/scanRequest.js +11 -5
  87. package/dist/lambda/utils.js +110 -53
  88. package/dist/scan/autoDetection.js +0 -32
  89. package/dist/scan/fileUtils.js +1 -1
  90. package/dist/scan/help.js +12 -40
  91. package/dist/scan/populateProjectIdAndProjectName.js +4 -0
  92. package/dist/scan/saveResults.js +15 -0
  93. package/dist/scan/scan.js +77 -42
  94. package/dist/scan/scanConfig.js +20 -0
  95. package/dist/scan/scanController.js +13 -15
  96. package/dist/scan/scanResults.js +18 -16
  97. package/dist/utils/commonApi.js +3 -3
  98. package/dist/utils/fileUtils.js +31 -0
  99. package/dist/utils/paramsUtil/commandlineParams.js +1 -20
  100. package/dist/utils/paramsUtil/genericCommandLineParams.js +12 -0
  101. package/dist/utils/paramsUtil/paramHandler.js +3 -6
  102. package/dist/utils/parsedCLIOptions.js +14 -8
  103. package/package.json +26 -21
  104. package/src/audit/AnalysisEngine.js +103 -0
  105. package/src/audit/catalogueApplication/catalogueApplication.js +42 -0
  106. package/src/audit/dotnetAnalysisEngine/index.js +26 -0
  107. package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +47 -0
  108. package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +29 -0
  109. package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +30 -0
  110. package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +26 -0
  111. package/src/audit/dotnetAnalysisEngine/sanitizer.js +11 -0
  112. package/src/audit/goAnalysisEngine/index.js +18 -0
  113. package/src/audit/goAnalysisEngine/parseProjectFileContents.js +209 -0
  114. package/src/audit/goAnalysisEngine/readProjectFileContents.js +31 -0
  115. package/src/audit/goAnalysisEngine/sanitizer.js +7 -0
  116. package/src/audit/javaAnalysisEngine/index.js +41 -0
  117. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +222 -0
  118. package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +420 -0
  119. package/src/audit/javaAnalysisEngine/readProjectFileContents.js +141 -0
  120. package/src/audit/javaAnalysisEngine/sanitizer.js +6 -0
  121. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +35 -0
  122. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +41 -0
  123. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +54 -0
  124. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +32 -0
  125. package/src/audit/languageAnalysisEngine/commonApi.js +20 -0
  126. package/src/audit/languageAnalysisEngine/constants.js +23 -0
  127. package/src/audit/languageAnalysisEngine/filterProjectPath.js +21 -0
  128. package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +41 -0
  129. package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +72 -0
  130. package/src/audit/languageAnalysisEngine/index.js +45 -0
  131. package/src/audit/languageAnalysisEngine/langugageAnalysisFactory.js +94 -0
  132. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +177 -0
  133. package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +27 -0
  134. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +303 -0
  135. package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +124 -0
  136. package/src/audit/languageAnalysisEngine/report/reportingFeature.js +190 -0
  137. package/src/audit/languageAnalysisEngine/sendSnapshot.js +51 -0
  138. package/src/audit/languageAnalysisEngine/util/capabilities.js +12 -0
  139. package/src/audit/languageAnalysisEngine/util/generalAPI.js +43 -0
  140. package/src/audit/languageAnalysisEngine/util/requestUtils.js +17 -0
  141. package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +49 -0
  142. package/src/audit/nodeAnalysisEngine/index.js +35 -0
  143. package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +20 -0
  144. package/src/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +63 -0
  145. package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +26 -0
  146. package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +23 -0
  147. package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +27 -0
  148. package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +36 -0
  149. package/src/audit/nodeAnalysisEngine/sanitizer.js +11 -0
  150. package/src/audit/phpAnalysisEngine/index.js +27 -0
  151. package/src/audit/phpAnalysisEngine/parseLockFileContents.js +60 -0
  152. package/src/audit/phpAnalysisEngine/readLockFileContents.js +14 -0
  153. package/src/audit/phpAnalysisEngine/readProjectFileContents.js +25 -0
  154. package/src/audit/phpAnalysisEngine/sanitizer.js +4 -0
  155. package/src/audit/pythonAnalysisEngine/index.js +55 -0
  156. package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +23 -0
  157. package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +33 -0
  158. package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +16 -0
  159. package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +22 -0
  160. package/src/audit/pythonAnalysisEngine/sanitizer.js +9 -0
  161. package/src/audit/rubyAnalysisEngine/index.js +30 -0
  162. package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +215 -0
  163. package/src/audit/rubyAnalysisEngine/parsedGemfile.js +39 -0
  164. package/src/audit/rubyAnalysisEngine/readGemfileContents.js +18 -0
  165. package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +17 -0
  166. package/src/audit/rubyAnalysisEngine/sanitizer.js +8 -0
  167. package/src/commands/audit/auditConfig.ts +30 -0
  168. package/src/commands/audit/auditController.ts +31 -0
  169. package/src/commands/audit/help.ts +48 -0
  170. package/src/commands/audit/processAudit.ts +19 -0
  171. package/src/commands/auth/auth.js +1 -1
  172. package/src/commands/scan/processScan.js +20 -5
  173. package/src/common/HTTPClient.js +136 -14
  174. package/src/common/errorHandling.ts +56 -1
  175. package/src/common/findLatestCLIVersion.ts +27 -0
  176. package/src/constants/constants.js +1 -1
  177. package/src/constants/lambda.js +45 -4
  178. package/src/constants/locales.js +48 -20
  179. package/src/constants.js +168 -22
  180. package/src/index.ts +9 -2
  181. package/src/lambda/aws.ts +13 -12
  182. package/src/lambda/help.ts +4 -0
  183. package/src/lambda/lambda.ts +53 -34
  184. package/src/lambda/lambdaUtils.ts +111 -0
  185. package/src/lambda/logUtils.ts +19 -1
  186. package/src/lambda/scanDetailCompletion.ts +4 -4
  187. package/src/lambda/scanRequest.ts +13 -11
  188. package/src/lambda/utils.ts +149 -81
  189. package/src/scan/autoDetection.js +0 -29
  190. package/src/scan/fileUtils.js +1 -1
  191. package/src/scan/help.js +12 -45
  192. package/src/scan/populateProjectIdAndProjectName.js +4 -0
  193. package/src/scan/saveResults.js +15 -0
  194. package/src/scan/scan.js +95 -59
  195. package/src/scan/scanConfig.js +29 -0
  196. package/src/scan/scanController.js +13 -13
  197. package/src/scan/scanResults.js +21 -19
  198. package/src/utils/commonApi.js +2 -3
  199. package/src/utils/paramsUtil/commandlineParams.js +1 -26
  200. package/src/utils/paramsUtil/paramHandler.js +3 -7
  201. package/src/utils/parsedCLIOptions.js +11 -9
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ const commonReport = require('./commonReportingFunctions');
3
+ const { handleResponseErrors } = require('../commonApi');
4
+ const { getHttpClient } = require('../../../utils/commonApi');
5
+ const vulnReportWithoutDevDep = async (analysis, applicationId, snapshotId, config) => {
6
+ if (config.report) {
7
+ const reportResponse = await getSpecReport(snapshotId, config);
8
+ if (reportResponse !== undefined) {
9
+ const severity = config.cveSeverity;
10
+ const id = applicationId;
11
+ const name = config.applicationName;
12
+ const hasSomeVulnerabilitiesReported = formatVulnerabilityOutput(reportResponse.vulnerabilities, severity, id, name, config);
13
+ commonReport.analyseReportOptions(hasSomeVulnerabilitiesReported);
14
+ }
15
+ }
16
+ };
17
+ const getSpecReport = async (reportId, config) => {
18
+ const client = getHttpClient(config);
19
+ return client
20
+ .getSpecificReport(config, reportId)
21
+ .then(res => {
22
+ if (res.statusCode === 200) {
23
+ commonReport.displaySuccessMessageReport();
24
+ return res.body;
25
+ }
26
+ else {
27
+ handleResponseErrors(res, 'report');
28
+ }
29
+ })
30
+ .catch(err => {
31
+ console.log(err);
32
+ });
33
+ };
34
+ const countSeverity = vulnerabilities => {
35
+ const severityCount = {
36
+ critical: 0,
37
+ high: 0,
38
+ medium: 0,
39
+ low: 0
40
+ };
41
+ for (const key of Object.keys(vulnerabilities)) {
42
+ vulnerabilities[key].forEach(vuln => {
43
+ if (vuln.severityCode === 'HIGH') {
44
+ severityCount['high'] += 1;
45
+ }
46
+ else if (vuln.severityCode === 'MEDIUM') {
47
+ severityCount['medium'] += 1;
48
+ }
49
+ else if (vuln.severityCode === 'LOW') {
50
+ severityCount['low'] += 1;
51
+ }
52
+ else if (vuln.severityCode === 'CRITICAL') {
53
+ severityCount['critical'] += 1;
54
+ }
55
+ });
56
+ }
57
+ return severityCount;
58
+ };
59
+ const formatVulnerabilityOutput = (vulnerabilities, severity, id, name, config) => {
60
+ const numberOfVulnerableLibraries = Object.keys(vulnerabilities).length;
61
+ let numberOfCves = 0;
62
+ for (const key of Object.keys(vulnerabilities)) {
63
+ numberOfCves += vulnerabilities[key].length;
64
+ }
65
+ commonReport.createLibraryHeader(id, numberOfVulnerableLibraries, numberOfCves, name);
66
+ const severityCount = countSeverity(vulnerabilities);
67
+ const filteredVulns = commonReport.filterVulnerabilitiesBySeverity(severity, vulnerabilities);
68
+ let hasSomeVulnerabilitiesReported;
69
+ hasSomeVulnerabilitiesReported = commonReport.printVulnerabilityResponse(severity, filteredVulns, vulnerabilities);
70
+ console.log('\n **************************' +
71
+ ` Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVE's ` +
72
+ '************************** ');
73
+ console.log(' \n Please go to the Contrast UI to view your dependency tree: \n' +
74
+ ` \n ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`);
75
+ return [hasSomeVulnerabilitiesReported, numberOfCves, severityCount];
76
+ };
77
+ module.exports = {
78
+ vulnReportWithoutDevDep: vulnReportWithoutDevDep,
79
+ formatVulnerabilityOutput: formatVulnerabilityOutput,
80
+ getSpecReport: getSpecReport
81
+ };
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ const i18n = require('i18n');
3
+ const commonApi = require('../commonApi');
4
+ const commonReport = require('./commonReportingFunctions');
5
+ function displaySuccessMessageVulnerabilities() {
6
+ console.log(i18n.__('vulnerabilitiesSuccessMessage'));
7
+ }
8
+ const vulnerabilityReport = async (analysis, applicationId, config) => {
9
+ let depRiskReportCount = {};
10
+ if (analysis.language === 'NODE') {
11
+ depRiskReportCount = await commonReport.dependencyRiskReport(analysis.node.packageJSON, config);
12
+ }
13
+ if (config['report']) {
14
+ const reportResponse = await commonReport.getReport(applicationId);
15
+ if (reportResponse !== undefined) {
16
+ const libraryVulnerabilityInput = createLibraryVulnerabilityInput(reportResponse.reports);
17
+ const libraryVulnerabilityResponse = await getLibraryVulnerabilities(libraryVulnerabilityInput, applicationId);
18
+ const severity = config['cve_severity'];
19
+ const id = applicationId;
20
+ const name = config.applicationName;
21
+ const hasSomeVulnerabilitiesReported = formatVulnerabilityOutput(libraryVulnerabilityResponse, severity, id, name, depRiskReportCount, config);
22
+ commonReport.analyseReportOptions(hasSomeVulnerabilitiesReported);
23
+ }
24
+ }
25
+ };
26
+ const createLibraryVulnerabilityInput = report => {
27
+ const language = Object.keys(report[0].report)[0];
28
+ const reportTree = report[0].report[language].dependencyTree;
29
+ const libraries = reportTree[Object.keys(reportTree)[0]];
30
+ let gav = [];
31
+ for (const key of Object.keys(libraries)) {
32
+ gav.push({
33
+ name: libraries[key].name,
34
+ group: libraries[key].group,
35
+ version: libraries[key].resolved
36
+ });
37
+ }
38
+ return {
39
+ name_group_versions: gav,
40
+ language: language.toUpperCase()
41
+ };
42
+ };
43
+ const oldCountSeverity = vulnerableLibraries => {
44
+ const severityCount = {
45
+ critical: 0,
46
+ high: 0,
47
+ medium: 0,
48
+ low: 0
49
+ };
50
+ vulnerableLibraries.forEach(lib => {
51
+ lib.vulns.forEach(vuln => {
52
+ if (vuln.severity_code === 'HIGH') {
53
+ severityCount['high'] += 1;
54
+ }
55
+ else if (vuln.severity_code === 'MEDIUM') {
56
+ severityCount['medium'] += 1;
57
+ }
58
+ else if (vuln.severity_code === 'LOW') {
59
+ severityCount['low'] += 1;
60
+ }
61
+ else if (vuln.severity_code === 'CRITICAL') {
62
+ severityCount['critical'] += 1;
63
+ }
64
+ });
65
+ });
66
+ return severityCount;
67
+ };
68
+ const parseVulnerabilites = libraryVulnerabilityResponse => {
69
+ let parsedVulnerabilites = {};
70
+ let vulnName = libraryVulnerabilityResponse.libraries;
71
+ for (let x in vulnName) {
72
+ let vuln = vulnName[x].vulns;
73
+ if (vuln.length > 0) {
74
+ let libname = vulnName[x].group +
75
+ '/' +
76
+ vulnName[x].file_name +
77
+ '@' +
78
+ vulnName[x].file_version;
79
+ parsedVulnerabilites[libname] = vulnName[x].vulns;
80
+ }
81
+ }
82
+ return parsedVulnerabilites;
83
+ };
84
+ const formatVulnerabilityOutput = (libraryVulnerabilityResponse, severity, id, name, depRiskReportCount, config) => {
85
+ let vulnerableLibraries = libraryVulnerabilityResponse.libraries.filter(data => {
86
+ return data.vulns.length > 0;
87
+ });
88
+ const numberOfVulnerableLibraries = vulnerableLibraries.length;
89
+ let numberOfCves = 0;
90
+ vulnerableLibraries.forEach(lib => (numberOfCves += lib.vulns.length));
91
+ commonReport.createLibraryHeader(id, numberOfVulnerableLibraries, numberOfCves, name);
92
+ const severityCount = oldCountSeverity(vulnerableLibraries);
93
+ let vulnerabilities = parseVulnerabilites(libraryVulnerabilityResponse);
94
+ let filteredVulns = commonReport.filterVulnerabilitiesBySeverity(severity, vulnerabilities);
95
+ let hasSomeVulnerabilitiesReported;
96
+ hasSomeVulnerabilitiesReported = commonReport.printVulnerabilityResponse(severity, filteredVulns, vulnerabilities);
97
+ console.log('\n **************************' +
98
+ ` Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVE's ` +
99
+ '************************** ');
100
+ if (depRiskReportCount && depRiskReportCount.scopedCount === 0) {
101
+ console.log(' No private libraries that are not scoped detected');
102
+ }
103
+ console.log(' \n Please go to the Contrast UI to view your dependency tree: \n' +
104
+ ` \n ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`);
105
+ return [hasSomeVulnerabilitiesReported, numberOfCves, severityCount];
106
+ };
107
+ const getLibraryVulnerabilities = async (input, applicationId) => {
108
+ const requestBody = input;
109
+ const addParams = agent.getAdditionalParams();
110
+ const userParams = await util.getParams(applicationId);
111
+ const protocol = getValidHost(userParams.host);
112
+ const client = commonApi.getHttpClient(userParams, protocol, addParams);
113
+ return client
114
+ .getLibraryVulnerabilities(requestBody, userParams)
115
+ .then(res => {
116
+ if (res.statusCode === 200) {
117
+ displaySuccessMessageVulnerabilities();
118
+ return res.body;
119
+ }
120
+ else {
121
+ handleResponseErrors(res, 'vulnerabilities');
122
+ }
123
+ })
124
+ .catch(err => {
125
+ console.log(err);
126
+ });
127
+ };
128
+ module.exports = {
129
+ vulnerabilityReport: vulnerabilityReport,
130
+ getLibraryVulnerabilities: getLibraryVulnerabilities,
131
+ formatVulnerabilityOutput: formatVulnerabilityOutput,
132
+ createLibraryVulnerabilityInput: createLibraryVulnerabilityInput
133
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ const prettyjson = require('prettyjson');
3
+ const i18n = require('i18n');
4
+ const { getHttpClient } = require('../../utils/commonApi');
5
+ const { handleResponseErrors } = require('../../common/errorHandling');
6
+ const { APP_VERSION } = require('../../constants/constants');
7
+ function displaySnapshotSuccessMessage(config) {
8
+ console.log('\n **************************' +
9
+ i18n.__('successHeader') +
10
+ '************************** ');
11
+ console.log('\n' + i18n.__('snapshotSuccessMessage') + '\n');
12
+ console.log(` ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`);
13
+ console.log('\n ***********************************************************');
14
+ }
15
+ const newSendSnapShot = async (analysis, applicationId) => {
16
+ const analysisLanguage = analysis.config.language.toLowerCase();
17
+ const requestBody = {
18
+ appID: analysis.config.applicationId,
19
+ cliVersion: APP_VERSION,
20
+ snapshot: { [analysisLanguage]: analysis[analysisLanguage] }
21
+ };
22
+ const client = getHttpClient(analysis.config);
23
+ return client
24
+ .sendSnapshot(requestBody, analysis.config)
25
+ .then(res => {
26
+ if (res.statusCode === 201) {
27
+ displaySnapshotSuccessMessage(analysis.config);
28
+ return res.body;
29
+ }
30
+ else {
31
+ handleResponseErrors(res, 'snapshot');
32
+ }
33
+ })
34
+ .catch(err => {
35
+ console.log(err);
36
+ });
37
+ };
38
+ module.exports = {
39
+ newSendSnapShot: newSendSnapShot,
40
+ displaySnapshotSuccessMessage: displaySnapshotSuccessMessage
41
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ const CLI_IGNORE_DEV_DEPS = 'CLI_IGNORE_DEV_DEPS';
3
+ const featuresTeamServer = [
4
+ {
5
+ CLI_IGNORE_DEV_DEPS: '3.9.0'
6
+ }
7
+ ];
8
+ module.exports = {
9
+ featuresTeamServer,
10
+ CLI_IGNORE_DEV_DEPS
11
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ const { featuresTeamServer } = require('./capabilities');
3
+ const semver = require('semver');
4
+ const { handleResponseErrors } = require('../../../common/errorHandling');
5
+ const { getHttpClient } = require('../../../utils/commonApi');
6
+ const getGlobalProperties = async (config) => {
7
+ const client = getHttpClient(config);
8
+ return client
9
+ .getGlobalProperties(config)
10
+ .then(res => {
11
+ if (res.statusCode === 200) {
12
+ return res.body;
13
+ }
14
+ else {
15
+ handleResponseErrors(res, 'globalProperties');
16
+ }
17
+ })
18
+ .catch(err => {
19
+ console.log(err);
20
+ });
21
+ };
22
+ const getFeatures = version => {
23
+ const featuresEnabled = [];
24
+ featuresTeamServer.forEach(feature => {
25
+ const versionFrom = Object.values(feature)[0];
26
+ return semver.gte(version, versionFrom)
27
+ ? featuresEnabled.push(Object.keys(feature)[0])
28
+ : null;
29
+ });
30
+ return featuresEnabled;
31
+ };
32
+ const isFeatureEnabled = (features, featureName) => {
33
+ return features.includes(featureName);
34
+ };
35
+ module.exports = {
36
+ getGlobalProperties,
37
+ getFeatures,
38
+ isFeatureEnabled
39
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const request = require('request');
3
+ const Promise = require('bluebird');
4
+ Promise.promisifyAll(request);
5
+ function sendRequest({ options, method = 'put' }) {
6
+ return request[`${method}Async`](options.url, options);
7
+ }
8
+ const sleep = ms => {
9
+ return new Promise(resolve => setTimeout(resolve, ms));
10
+ };
11
+ module.exports = {
12
+ sendRequest: sendRequest,
13
+ sleep: sleep
14
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ const i18n = require('i18n');
3
+ module.exports = exports = (analysis, next) => {
4
+ const { language: { lockFilePath }, node } = analysis;
5
+ try {
6
+ if (node.npmLockFile && node.npmLockFile.lockfileVersion > 1) {
7
+ const listOfTopDep = Object.keys(node.npmLockFile.dependencies);
8
+ Object.entries(node.npmLockFile.dependencies).forEach(([key, value]) => {
9
+ if (value.requires) {
10
+ const listOfRequiresDep = Object.keys(value.requires);
11
+ listOfRequiresDep.forEach(dep => {
12
+ if (!listOfTopDep.includes(dep)) {
13
+ addDepToLockFile(value['requires'], dep);
14
+ }
15
+ });
16
+ }
17
+ if (value.dependencies) {
18
+ Object.entries(value.dependencies).forEach(([childKey, childValue]) => {
19
+ if (childValue.requires) {
20
+ const listOfRequiresDep = Object.keys(childValue.requires);
21
+ listOfRequiresDep.forEach(dep => {
22
+ if (!listOfTopDep.includes(dep)) {
23
+ addDepToLockFile(childValue['requires'], dep);
24
+ }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ }
32
+ catch (err) {
33
+ next(next(new Error(i18n.__('NodeParseNPM', lockFilePath) + `${err.message}`)));
34
+ return;
35
+ }
36
+ function addDepToLockFile(depObj, key) {
37
+ node.npmLockFile.dependencies[key] = { version: depObj[key] };
38
+ }
39
+ next();
40
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ const AnalysisEngine = require('../AnalysisEngine');
3
+ const readProjectFileContents = require('./readProjectFileContents');
4
+ const readNPMLockFileContents = require('./readNPMLockFileContents');
5
+ const parseNPMLockFileContents = require('./parseNPMLockFileContents');
6
+ const readYarnLockFileContents = require('./readYarnLockFileContents');
7
+ const parseYarnLockFileContents = require('./parseYarnLockFileContents');
8
+ const parseYarn2LockFileContents = require('./parseYarn2LockFileContents');
9
+ const handleNPMLockFileV2 = require('./handleNPMLockFileV2');
10
+ const sanitizer = require('./sanitizer');
11
+ const i18n = require('i18n');
12
+ module.exports = exports = (language, config, callback) => {
13
+ const ae = new AnalysisEngine({ language, config, node: {} });
14
+ ae.use([
15
+ readProjectFileContents,
16
+ readNPMLockFileContents,
17
+ parseNPMLockFileContents,
18
+ readYarnLockFileContents,
19
+ parseYarnLockFileContents,
20
+ parseYarn2LockFileContents,
21
+ handleNPMLockFileV2,
22
+ sanitizer
23
+ ]);
24
+ ae.analyze((err, analysis) => {
25
+ if (err) {
26
+ callback(new Error(i18n.__('NodeAnalysisFailure') + `${err.message}`));
27
+ return;
28
+ }
29
+ callback(null, analysis);
30
+ });
31
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ const i18n = require('i18n');
3
+ module.exports = exports = ({ language: { lockFilePath }, node }, next) => {
4
+ if (node.rawLockFileContents === undefined) {
5
+ next();
6
+ }
7
+ else {
8
+ try {
9
+ node.npmLockFile = JSON.parse(node.rawLockFileContents);
10
+ }
11
+ catch (err) {
12
+ next(new Error(i18n.__('NodeParseNPM', lockFilePath ? lockFilePath : 'undefined') +
13
+ `${err.message}`));
14
+ return;
15
+ }
16
+ next();
17
+ }
18
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ const i18n = require('i18n');
3
+ module.exports = exports = ({ language: { lockFilename }, node }, next) => {
4
+ if (node.rawYarnLockFileContents == undefined || node.yarnVersion == 1) {
5
+ next();
6
+ }
7
+ else {
8
+ try {
9
+ node.yarnLockFile = {};
10
+ node.yarnLockFile['object'] = node.rawYarnLockFileContents;
11
+ delete node.yarnLockFile['object'].__metadata;
12
+ node.yarnLockFile['type'] = 'success';
13
+ Object.entries(node.rawYarnLockFileContents).forEach(([key, value]) => {
14
+ const rawKeyNames = key.split(',');
15
+ const keyNames = formatKey(rawKeyNames);
16
+ keyNames.forEach(name => {
17
+ node.yarnLockFile.object[name] = value;
18
+ });
19
+ });
20
+ }
21
+ catch (err) {
22
+ next(new Error(i18n.__('NodeParseYarn2', lockFilename.lockFilePath) +
23
+ `${err.message}`));
24
+ return;
25
+ }
26
+ next();
27
+ }
28
+ };
29
+ function formatKey(keyNames) {
30
+ let name = '';
31
+ let formattedNames = [];
32
+ keyNames.forEach(dummyString => {
33
+ let nameArr = dummyString.split('@');
34
+ if (nameArr.length > 1) {
35
+ if (nameArr.length == 2) {
36
+ name = nameArr[0];
37
+ }
38
+ if (nameArr.length == 3) {
39
+ name = '@' + nameArr[1];
40
+ }
41
+ let version = dummyString.split(':').pop('');
42
+ if (version.length == 1 && version != '*') {
43
+ version = version + '.0';
44
+ }
45
+ let reformattedKey = name.trim() + '@' + version;
46
+ formattedNames.push(reformattedKey);
47
+ }
48
+ });
49
+ return formattedNames;
50
+ }
51
+ exports.formatKey = formatKey;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ const yarnParser = require('@yarnpkg/lockfile');
3
+ const i18n = require('i18n');
4
+ module.exports = exports = ({ language: { lockFilename }, node }, next) => {
5
+ if (node.rawYarnLockFileContents === undefined || node.yarnVersion === 2) {
6
+ next();
7
+ }
8
+ else {
9
+ try {
10
+ node.yarnLockFile = yarnParser.parse(node.rawYarnLockFileContents);
11
+ }
12
+ catch (err) {
13
+ next(new Error(i18n.__('NodeParseYarn', lockFilename.lockFilePath ? lockFilename.lockFilePath : 'undefined') + `${err.message}`));
14
+ return;
15
+ }
16
+ next();
17
+ }
18
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ const fs = require('fs');
3
+ const i18n = require('i18n');
4
+ module.exports = exports = ({ language: { lockFilePath }, node }, next) => {
5
+ if (!lockFilePath || !lockFilePath.includes('package-lock.json')) {
6
+ next();
7
+ return;
8
+ }
9
+ try {
10
+ node.rawLockFileContents = fs.readFileSync(lockFilePath);
11
+ }
12
+ catch (err) {
13
+ next(new Error(i18n.__('NodeReadNpmError', lockFilePath) + `${err.message}`));
14
+ return;
15
+ }
16
+ next();
17
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const fs = require('fs');
3
+ const i18n = require('i18n');
4
+ module.exports = exports = (analysis, next) => {
5
+ const { language: { projectFilePath }, node } = analysis;
6
+ try {
7
+ node.packageJSON = JSON.parse(fs.readFileSync(projectFilePath, 'utf8'));
8
+ }
9
+ catch (err) {
10
+ next(new Error(i18n.__('nodeReadProjectFileError', projectFilePath) + `${err.message}`));
11
+ return;
12
+ }
13
+ next();
14
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ const fs = require('fs');
3
+ const yaml = require('js-yaml');
4
+ const i18n = require('i18n');
5
+ module.exports = exports = ({ language: { lockFilePath }, node }, next) => {
6
+ if (!lockFilePath || !lockFilePath.includes('yarn.lock')) {
7
+ next();
8
+ return;
9
+ }
10
+ try {
11
+ node.rawYarnLockFileContents = fs.readFileSync(lockFilePath, 'utf8');
12
+ node.yarnVersion = 1;
13
+ if (!node.rawYarnLockFileContents.includes('lockfile v1') ||
14
+ node.rawYarnLockFileContents.includes('__metadata')) {
15
+ node.rawYarnLockFileContents = yaml.load(fs.readFileSync(lockFilePath, 'utf8'));
16
+ node.yarnVersion = 2;
17
+ }
18
+ }
19
+ catch (err) {
20
+ next(new Error(i18n.__('nodeReadYarnLockFileError', lockFilePath) + `${err.message}`));
21
+ return;
22
+ }
23
+ next();
24
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ module.exports = exports = ({ node }, next) => {
3
+ delete node.rawProjectFileContents;
4
+ delete node.projectFileJSON;
5
+ delete node.projectLockFileJSON;
6
+ delete node.rawLockFileContents;
7
+ delete node.rawYarnLockFileContents;
8
+ next();
9
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ const AnalysisEngine = require('../AnalysisEngine');
3
+ const readProjectFileContents = require('./readProjectFileContents');
4
+ const readLockFileContents = require('./readLockFileContents');
5
+ const parseLockFileContents = require('./parseLockFileContents');
6
+ const sanitizer = require('./sanitizer');
7
+ const i18n = require('i18n');
8
+ module.exports = exports = (language, config, callback) => {
9
+ const ae = new AnalysisEngine({ language, config, php: {} });
10
+ ae.use([
11
+ readProjectFileContents,
12
+ readLockFileContents,
13
+ parseLockFileContents,
14
+ sanitizer
15
+ ]);
16
+ ae.analyze((err, analysis) => {
17
+ if (err) {
18
+ callback(new Error(i18n.__('phpAnalysisFailure') + `${err.message}`));
19
+ return;
20
+ }
21
+ callback(null, analysis);
22
+ });
23
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ const i18n = require('i18n');
3
+ const _ = require('lodash');
4
+ module.exports = exports = ({ language: { lockFilePath }, php }, next) => {
5
+ try {
6
+ php.lockFile = php.rawLockFileContents;
7
+ let packages = _.keyBy(php.lockFile.packages, 'name');
8
+ let packagesDev = _.keyBy(php.lockFile['packages-dev'], 'name');
9
+ php.lockFile.dependencies = _.merge(packages, packagesDev);
10
+ const listOfTopDep = Object.keys(php.lockFile.dependencies);
11
+ Object.entries(php.lockFile.dependencies).forEach(([key, value]) => {
12
+ if (value.require) {
13
+ const listOfRequiresDep = Object.keys(value.require);
14
+ listOfRequiresDep.forEach(dep => {
15
+ if (!listOfTopDep.includes(dep)) {
16
+ addChildDepToLockFileAsOwnObj(value['require'], dep);
17
+ }
18
+ });
19
+ }
20
+ if (value['require-dev']) {
21
+ const listOfRequiresDep = Object.keys(value['require-dev']);
22
+ listOfRequiresDep.forEach(dep => {
23
+ if (!listOfTopDep.includes(dep)) {
24
+ addChildDepToLockFileAsOwnObj(value['require-dev'], dep);
25
+ }
26
+ });
27
+ }
28
+ });
29
+ formatParentDepToLockFile();
30
+ }
31
+ catch (err) {
32
+ next(new Error(i18n.__('phpParseComposerLock', lockFilePath) + `${err.message}`));
33
+ return;
34
+ }
35
+ next();
36
+ function addChildDepToLockFileAsOwnObj(depObj, key) {
37
+ php.lockFile.dependencies[key] = { version: depObj[key] };
38
+ }
39
+ function formatParentDepToLockFile() {
40
+ for (const [key, value] of Object.entries(php.lockFile.dependencies)) {
41
+ let requires = {};
42
+ for (const [childKey, childValue] of Object.entries(value)) {
43
+ if (childKey === 'require' || childKey === 'require-dev') {
44
+ requires = _.merge(requires, childValue);
45
+ php.lockFile.dependencies[key].requires = requires;
46
+ delete php.lockFile.dependencies[key].require;
47
+ delete php.lockFile.dependencies[key]['require-dev'];
48
+ }
49
+ }
50
+ }
51
+ }
52
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ const fs = require('fs');
3
+ const i18n = require('i18n');
4
+ module.exports = exports = ({ language: { lockFilePath }, php }, next) => {
5
+ try {
6
+ php.rawLockFileContents = JSON.parse(fs.readFileSync(lockFilePath));
7
+ }
8
+ catch (err) {
9
+ next(new Error(i18n.__('phpReadError', lockFilePath) + `${err.message}`));
10
+ return;
11
+ }
12
+ next();
13
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ const fs = require('fs');
3
+ const i18n = require('i18n');
4
+ module.exports = exports = (analysis, next) => {
5
+ const { language: { projectFilePath }, php } = analysis;
6
+ try {
7
+ php.composerJSON = JSON.parse(fs.readFileSync(projectFilePath, 'utf8'));
8
+ php.composerJSON.dependencies = php.composerJSON.require;
9
+ php.composerJSON.devDependencies = php.composerJSON['require-dev'];
10
+ }
11
+ catch (err) {
12
+ next(new Error(i18n.__('phpReadProjectFileError', projectFilePath) + `${err.message}`));
13
+ return;
14
+ }
15
+ next();
16
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ module.exports = exports = ({ php }, next) => {
3
+ delete php.rawLockFileContents;
4
+ next();
5
+ };