@contrast/contrast 1.0.3 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.prettierignore +4 -0
  2. package/README.md +20 -14
  3. package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
  4. package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
  5. package/dist/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +6 -14
  6. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +29 -0
  7. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +101 -234
  8. package/dist/audit/languageAnalysisEngine/report/models/reportLibraryModel.js +19 -0
  9. package/dist/audit/languageAnalysisEngine/report/models/reportListModel.js +24 -0
  10. package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +24 -0
  11. package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +12 -0
  12. package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +13 -0
  13. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +24 -129
  14. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +99 -0
  15. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +2 -14
  16. package/dist/commands/audit/auditConfig.js +8 -2
  17. package/dist/commands/audit/auditController.js +14 -5
  18. package/dist/commands/scan/processScan.js +10 -6
  19. package/dist/commands/scan/sca/scaAnalysis.js +49 -0
  20. package/dist/common/HTTPClient.js +18 -26
  21. package/dist/common/errorHandling.js +7 -17
  22. package/dist/common/versionChecker.js +14 -12
  23. package/dist/constants/constants.js +24 -2
  24. package/dist/constants/lambda.js +3 -1
  25. package/dist/constants/locales.js +42 -42
  26. package/dist/constants.js +25 -1
  27. package/dist/index.js +2 -2
  28. package/dist/lambda/help.js +22 -14
  29. package/dist/lambda/lambda.js +6 -0
  30. package/dist/scaAnalysis/common/formatMessage.js +19 -0
  31. package/dist/scaAnalysis/common/treeUpload.js +29 -0
  32. package/dist/scaAnalysis/go/goAnalysis.js +17 -0
  33. package/dist/scaAnalysis/go/goParseDeps.js +158 -0
  34. package/dist/scaAnalysis/go/goReadDepFile.js +23 -0
  35. package/dist/scaAnalysis/java/analysis.js +108 -0
  36. package/dist/scaAnalysis/java/index.js +18 -0
  37. package/dist/scaAnalysis/java/javaBuildDepsParser.js +339 -0
  38. package/dist/scan/autoDetection.js +46 -1
  39. package/dist/scan/fileUtils.js +73 -1
  40. package/dist/scan/formatScanOutput.js +215 -0
  41. package/dist/scan/help.js +3 -1
  42. package/dist/scan/models/groupedResultsModel.js +11 -0
  43. package/dist/scan/models/resultContentModel.js +2 -0
  44. package/dist/scan/models/scanResultsModel.js +11 -0
  45. package/dist/scan/scan.js +27 -126
  46. package/dist/scan/scanConfig.js +1 -1
  47. package/dist/scan/scanController.js +11 -5
  48. package/dist/scan/scanResults.js +15 -19
  49. package/dist/utils/getConfig.js +3 -0
  50. package/dist/utils/oraWrapper.js +5 -1
  51. package/package.json +3 -2
  52. package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
  53. package/src/audit/catalogueApplication/catalogueApplication.js +4 -16
  54. package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +11 -21
  55. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +72 -0
  56. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +204 -0
  57. package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +30 -0
  58. package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +32 -0
  59. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +29 -0
  60. package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +13 -0
  61. package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +16 -0
  62. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +56 -0
  63. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +116 -0
  64. package/src/audit/languageAnalysisEngine/sendSnapshot.js +2 -22
  65. package/src/commands/audit/auditConfig.ts +12 -3
  66. package/src/commands/audit/auditController.ts +20 -5
  67. package/src/commands/audit/processAudit.ts +3 -0
  68. package/src/commands/scan/processScan.js +13 -9
  69. package/src/commands/scan/sca/scaAnalysis.js +75 -0
  70. package/src/common/HTTPClient.js +31 -38
  71. package/src/common/errorHandling.ts +7 -25
  72. package/src/common/versionChecker.ts +24 -22
  73. package/src/constants/constants.js +24 -2
  74. package/src/constants/lambda.js +3 -1
  75. package/src/constants/locales.js +47 -56
  76. package/src/constants.js +29 -1
  77. package/src/index.ts +2 -3
  78. package/src/lambda/help.ts +22 -14
  79. package/src/lambda/lambda.ts +8 -0
  80. package/src/scaAnalysis/common/formatMessage.js +20 -0
  81. package/src/scaAnalysis/common/treeUpload.js +30 -0
  82. package/src/scaAnalysis/go/goAnalysis.js +20 -0
  83. package/src/scaAnalysis/go/goParseDeps.js +203 -0
  84. package/src/scaAnalysis/go/goReadDepFile.js +32 -0
  85. package/src/scaAnalysis/java/analysis.js +143 -0
  86. package/src/scaAnalysis/java/index.js +21 -0
  87. package/src/scaAnalysis/java/javaBuildDepsParser.js +404 -0
  88. package/src/scan/autoDetection.js +54 -1
  89. package/src/scan/fileUtils.js +91 -1
  90. package/src/scan/formatScanOutput.ts +250 -0
  91. package/src/scan/help.js +3 -1
  92. package/src/scan/models/groupedResultsModel.ts +20 -0
  93. package/src/scan/models/resultContentModel.ts +86 -0
  94. package/src/scan/models/scanResultsModel.ts +52 -0
  95. package/src/scan/scan.ts +63 -0
  96. package/src/scan/scanConfig.js +1 -1
  97. package/src/scan/scanController.js +15 -7
  98. package/src/scan/scanResults.js +21 -18
  99. package/src/utils/getConfig.ts +10 -0
  100. package/src/utils/oraWrapper.js +6 -1
  101. package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -17
  102. package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -81
  103. package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -27
  104. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +0 -303
  105. package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -124
  106. package/src/audit/languageAnalysisEngine/report/reportingFeature.js +0 -190
  107. package/src/scan/scan.js +0 -195
@@ -1,81 +0,0 @@
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
- };
@@ -1,27 +0,0 @@
1
- const {
2
- getGlobalProperties,
3
- getFeatures,
4
- isFeatureEnabled
5
- } = require('../util/generalAPI')
6
- const { CLI_IGNORE_DEV_DEPS } = require('../util/capabilities')
7
-
8
- const checkDevDeps = async config => {
9
- const shouldIgnoreDev = config.ignoreDev
10
- const globalProperties = await getGlobalProperties()
11
-
12
- // returns [ 'CLI_IGNORE_DEV_DEPS' ] if teamserver version is above 3.8.1
13
- const features = getFeatures(globalProperties.internal_version)
14
-
15
- // providing user is on version >= 3.8.1, isfeatureEnabled will always return true,
16
- // therefore shouldIgnoreDev flag (from params) is needed to disable ignore dev deps
17
- const isfeatureEnabled = isFeatureEnabled(features, CLI_IGNORE_DEV_DEPS)
18
- let ignoreDevUrl = false
19
- if (shouldIgnoreDev) {
20
- ignoreDevUrl = isfeatureEnabled
21
- }
22
- return ignoreDevUrl
23
- }
24
-
25
- module.exports = {
26
- checkDevDeps
27
- }
@@ -1,303 +0,0 @@
1
- const i18n = require('i18n')
2
- const { getHttpClient } = require('../../../utils/commonApi')
3
-
4
- function displaySuccessMessageReport() {
5
- console.log('\n' + i18n.__('reportSuccessMessage'))
6
- }
7
-
8
- function getAllDependenciesArray(packageJson) {
9
- const {
10
- dependencies,
11
- optionalDependencies,
12
- devDependencies,
13
- peerDependencies
14
- } = packageJson
15
-
16
- const allDep = {
17
- ...dependencies,
18
- ...devDependencies,
19
- ...optionalDependencies,
20
- ...peerDependencies
21
- }
22
-
23
- return Object.entries(allDep)
24
- }
25
-
26
- function checkIfDepIsScoped(arrDep) {
27
- let count = 0
28
- arrDep.forEach(([key, value]) => {
29
- if (!key.startsWith('@')) {
30
- console.log(` WARNING not scoped: ${key}:${value}`)
31
- count++
32
- }
33
- })
34
- return count
35
- }
36
-
37
- const dependencyRiskReport = async (packageJson, config) => {
38
- const arrDep = getAllDependenciesArray(packageJson)
39
- const unRegisteredDeps = await checkIfDepIsRegisteredOnNPM(arrDep, config)
40
- let scopedCount = checkIfDepIsScoped(unRegisteredDeps)
41
-
42
- return {
43
- scopedCount: scopedCount,
44
- unRegisteredCount: unRegisteredDeps.length
45
- }
46
- }
47
-
48
- const checkIfDepIsRegisteredOnNPM = async (arrDep, config) => {
49
- let promises = []
50
- let unRegisteredDeps = []
51
- const client = getHttpClient(config)
52
-
53
- for (const [index, element] of arrDep) {
54
- const query = `query artifactByGAV($name: String!, $language: String!, $groupName: String, $version: String!, $nameCheck: Boolean) {
55
- artifact: exactVersion(name: $name, language: $language, groupName: $groupName, version: $version, nameCheck: $nameCheck) {
56
- version
57
- cves {
58
- baseScore
59
- }}}`
60
-
61
- const data = {
62
- query: query,
63
- variables: {
64
- name: index,
65
- version: element,
66
- language: 'node',
67
- nameCheck: true
68
- }
69
- }
70
-
71
- promises.push(client.checkLibrary(data))
72
- }
73
-
74
- await Promise.all(promises).then(response => {
75
- response.forEach(res => {
76
- const libName = JSON.parse(res.request.body)
77
- if (res.statusCode === 200) {
78
- if (res.body.data.artifact == null) {
79
- unRegisteredDeps.push([
80
- libName.variables.name,
81
- libName.variables.version
82
- ])
83
- }
84
- }
85
- })
86
- })
87
-
88
- if (unRegisteredDeps.length !== 0) {
89
- console.log(
90
- '\n Dependencies Risk Report',
91
- '\n\n Private libraries that are not scoped. We recommend these libraries are reviewed and the scope claimed to prevent dependency confusion breaches'
92
- )
93
- }
94
-
95
- return unRegisteredDeps
96
- }
97
-
98
- const createLibraryHeader = (
99
- id,
100
- numberOfVulnerableLibraries,
101
- numberOfCves,
102
- name
103
- ) => {
104
- name
105
- ? console.log(` Application Name: ${name} | Application ID: ${id}`)
106
- : console.log(` Application ID: ${id}`)
107
- console.log(
108
- ` Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVE's`
109
- )
110
- }
111
-
112
- const breakPipeline = () => {
113
- failOptionError()
114
- process.exit(1)
115
- }
116
-
117
- const parameterOptions = hasSomeVulnerabilitiesReported => {
118
- const inputtedCLIOptions = cliOptions.getCommandLineArgs()
119
- let cveSeverityOption = inputtedCLIOptions['cve_severity']
120
- let fail = inputtedCLIOptions['fail']
121
- let cve_threshold = inputtedCLIOptions['cve_threshold']
122
- let expr
123
- if (cveSeverityOption && fail && cve_threshold) {
124
- expr = 'SeverityAndThreshold'
125
- } else if (!cveSeverityOption && fail && cve_threshold) {
126
- expr = 'ThresholdOnly'
127
- } else if (!cve_threshold && fail && hasSomeVulnerabilitiesReported[0]) {
128
- expr = 'FailOnly'
129
- }
130
- return expr
131
- }
132
-
133
- const analyseReportOptions = hasSomeVulnerabilitiesReported => {
134
- const inputtedCLIOptions = cliOptions.getCommandLineArgs()
135
- let cve_threshold = inputtedCLIOptions['cve_threshold']
136
- let cveSeverity
137
- let criticalSeverity
138
- let highSeverity
139
- let mediumSeverity
140
- let lowSeverity
141
-
142
- switch (parameterOptions(hasSomeVulnerabilitiesReported)) {
143
- case 'SeverityAndThreshold':
144
- cveSeverity = inputtedCLIOptions['cve_severity'].severity
145
- criticalSeverity = hasSomeVulnerabilitiesReported[2].critical
146
- highSeverity = hasSomeVulnerabilitiesReported[2].high
147
- mediumSeverity = hasSomeVulnerabilitiesReported[2].medium
148
- lowSeverity = hasSomeVulnerabilitiesReported[2].low
149
-
150
- if (cveSeverity === 'HIGH') {
151
- if (cve_threshold < highSeverity + criticalSeverity) {
152
- breakPipeline()
153
- }
154
- }
155
-
156
- if (cveSeverity === 'MEDIUM') {
157
- if (cve_threshold < mediumSeverity + highSeverity) {
158
- breakPipeline()
159
- }
160
- }
161
-
162
- if (cveSeverity === 'LOW') {
163
- if (cve_threshold < lowSeverity + mediumSeverity + highSeverity) {
164
- breakPipeline()
165
- }
166
- }
167
- break
168
- case 'ThresholdOnly':
169
- if (cve_threshold < hasSomeVulnerabilitiesReported[1]) {
170
- breakPipeline()
171
- }
172
- break
173
- case 'FailOnly':
174
- breakPipeline()
175
- break
176
- }
177
- }
178
-
179
- const getReport = async applicationId => {
180
- const userParams = await util.getParams(applicationId)
181
- const addParams = agent.getAdditionalParams()
182
- const protocol = getValidHost(userParams.host)
183
- const client = commonApi.getHttpClient(userParams, protocol, addParams)
184
- return client
185
- .getReport(userParams)
186
- .then(res => {
187
- if (res.statusCode === 200) {
188
- displaySuccessMessageReport()
189
- return res.body
190
- } else {
191
- handleResponseErrors(res, 'report')
192
- }
193
- })
194
- .catch(err => {
195
- console.log(err)
196
- })
197
- }
198
-
199
- const printVulnerabilityResponse = (
200
- severity,
201
- filteredVulns,
202
- vulnerabilities
203
- ) => {
204
- let hasSomeVulnerabilitiesReported = false
205
- if (severity) {
206
- returnCveData(filteredVulns)
207
- if (Object.keys(filteredVulns).length > 0)
208
- hasSomeVulnerabilitiesReported = true
209
- } else {
210
- returnCveData(vulnerabilities)
211
- if (Object.keys(vulnerabilities).length > 0)
212
- hasSomeVulnerabilitiesReported = true
213
- }
214
- return hasSomeVulnerabilitiesReported
215
- }
216
-
217
- const returnCveData = libraries => {
218
- console.log('\n ************************************************************')
219
-
220
- for (const [key, value] of Object.entries(libraries)) {
221
- const parts = key.split('/')
222
- const nameVersion = parts[1].split('@')
223
- const group = parts[0]
224
- const name = nameVersion[0]
225
- const version = nameVersion[1]
226
-
227
- const libName =
228
- group !== 'null'
229
- ? `${group}/${name}/${version} is vulnerable`
230
- : `${name}/${version} is vulnerable`
231
-
232
- console.log('\n\n ' + libName)
233
- value.forEach(vuln => {
234
- let sevCode = vuln.severityCode || vuln.severity_code
235
- console.log('\n ' + vuln.name + ' ' + sevCode + '\n ' + vuln.description)
236
- })
237
- }
238
- }
239
-
240
- function searchHighCVEs(vuln) {
241
- let sevCode = vuln.severityCode || vuln.severity_code
242
- if (sevCode === 'HIGH') {
243
- return vuln
244
- }
245
- }
246
-
247
- function searchMediumCVEs(vuln) {
248
- let sevCode = vuln.severityCode || vuln.severity_code
249
- if (sevCode === 'HIGH' || sevCode === 'MEDIUM') {
250
- return vuln
251
- }
252
- }
253
-
254
- function searchLowCVEs(vuln) {
255
- let sevCode = vuln.severityCode || vuln.severity_code
256
- if (sevCode === 'HIGH' || sevCode === 'MEDIUM' || sevCode === 'LOW') {
257
- return vuln
258
- }
259
- }
260
-
261
- const filterVulnerabilitiesBySeverity = (severity, vulnerabilities) => {
262
- let filteredVulns = []
263
- if (severity) {
264
- for (let x in vulnerabilities) {
265
- if (severity.severity === 'HIGH') {
266
- let highVulnerability = vulnerabilities[x].filter(searchHighCVEs)
267
- if (highVulnerability.length > 0) {
268
- filteredVulns[x] = highVulnerability
269
- }
270
- } else if (severity.severity === 'MEDIUM') {
271
- let mediumVulnerability = vulnerabilities[x].filter(searchMediumCVEs)
272
- if (mediumVulnerability.length > 0) {
273
- filteredVulns[x] = mediumVulnerability
274
- }
275
- } else if (severity.severity === 'LOW') {
276
- let lowVulnerability = vulnerabilities[x].filter(searchLowCVEs)
277
- if (lowVulnerability.length > 0) {
278
- filteredVulns[x] = lowVulnerability
279
- }
280
- }
281
- }
282
- }
283
- return filteredVulns
284
- }
285
-
286
- module.exports = {
287
- displaySuccessMessageReport: displaySuccessMessageReport,
288
- getAllDependenciesArray: getAllDependenciesArray,
289
- dependencyRiskReport: dependencyRiskReport,
290
- createLibraryHeader: createLibraryHeader,
291
- breakPipeline: breakPipeline,
292
- parameterOptions: parameterOptions,
293
- analyseReportOptions: analyseReportOptions,
294
- getReport: getReport,
295
- checkIfDepIsScoped: checkIfDepIsScoped,
296
- checkIfDepIsRegisteredOnNPM: checkIfDepIsRegisteredOnNPM,
297
- filterVulnerabilitiesBySeverity: filterVulnerabilitiesBySeverity,
298
- searchLowCVEs: searchLowCVEs,
299
- searchMediumCVEs: searchMediumCVEs,
300
- searchHighCVEs: searchHighCVEs,
301
- returnCveData: returnCveData,
302
- printVulnerabilityResponse: printVulnerabilityResponse
303
- }
@@ -1,124 +0,0 @@
1
- const commonReport = require('./commonReportingFunctions')
2
- const { handleResponseErrors } = require('../commonApi')
3
- const { getHttpClient } = require('../../../utils/commonApi')
4
-
5
- const vulnReportWithoutDevDep = async (
6
- analysis,
7
- applicationId,
8
- snapshotId,
9
- config
10
- ) => {
11
- if (config.report) {
12
- const reportResponse = await getSpecReport(snapshotId, config)
13
- if (reportResponse !== undefined) {
14
- const severity = config.cveSeverity
15
- const id = applicationId
16
- const name = config.applicationName
17
- const hasSomeVulnerabilitiesReported = formatVulnerabilityOutput(
18
- reportResponse.vulnerabilities,
19
- severity,
20
- id,
21
- name,
22
- config
23
- )
24
- commonReport.analyseReportOptions(hasSomeVulnerabilitiesReported)
25
- }
26
- }
27
- }
28
-
29
- const getSpecReport = async (reportId, config) => {
30
- const client = getHttpClient(config)
31
-
32
- return client
33
- .getSpecificReport(config, reportId)
34
- .then(res => {
35
- if (res.statusCode === 200) {
36
- commonReport.displaySuccessMessageReport()
37
- return res.body
38
- } else {
39
- handleResponseErrors(res, 'report')
40
- }
41
- })
42
- .catch(err => {
43
- console.log(err)
44
- })
45
- }
46
-
47
- const countSeverity = vulnerabilities => {
48
- const severityCount = {
49
- critical: 0,
50
- high: 0,
51
- medium: 0,
52
- low: 0
53
- }
54
-
55
- // eslint-disable-next-line
56
- for (const key of Object.keys(vulnerabilities)) {
57
- vulnerabilities[key].forEach(vuln => {
58
- if (vuln.severityCode === 'HIGH') {
59
- severityCount['high'] += 1
60
- } else if (vuln.severityCode === 'MEDIUM') {
61
- severityCount['medium'] += 1
62
- } else if (vuln.severityCode === 'LOW') {
63
- severityCount['low'] += 1
64
- } else if (vuln.severityCode === 'CRITICAL') {
65
- severityCount['critical'] += 1
66
- }
67
- })
68
- }
69
- return severityCount
70
- }
71
-
72
- const formatVulnerabilityOutput = (
73
- vulnerabilities,
74
- severity,
75
- id,
76
- name,
77
- config
78
- ) => {
79
- const numberOfVulnerableLibraries = Object.keys(vulnerabilities).length
80
- let numberOfCves = 0
81
-
82
- // eslint-disable-next-line
83
- for (const key of Object.keys(vulnerabilities)) {
84
- numberOfCves += vulnerabilities[key].length
85
- }
86
-
87
- commonReport.createLibraryHeader(
88
- id,
89
- numberOfVulnerableLibraries,
90
- numberOfCves,
91
- name
92
- )
93
-
94
- const severityCount = countSeverity(vulnerabilities)
95
- const filteredVulns = commonReport.filterVulnerabilitiesBySeverity(
96
- severity,
97
- vulnerabilities
98
- )
99
-
100
- let hasSomeVulnerabilitiesReported
101
- hasSomeVulnerabilitiesReported = commonReport.printVulnerabilityResponse(
102
- severity,
103
- filteredVulns,
104
- vulnerabilities
105
- )
106
-
107
- console.log(
108
- '\n **************************' +
109
- ` Found ${numberOfVulnerableLibraries} vulnerable libraries containing ${numberOfCves} CVE's ` +
110
- '************************** '
111
- )
112
-
113
- console.log(
114
- ' \n Please go to the Contrast UI to view your dependency tree: \n' +
115
- ` \n ${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs/dependency-tree`
116
- )
117
- return [hasSomeVulnerabilitiesReported, numberOfCves, severityCount]
118
- }
119
-
120
- module.exports = {
121
- vulnReportWithoutDevDep: vulnReportWithoutDevDep,
122
- formatVulnerabilityOutput: formatVulnerabilityOutput,
123
- getSpecReport: getSpecReport
124
- }