@contrast/contrast 1.0.19 → 1.0.21

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 (66) hide show
  1. package/dist/audit/report/commonReportingFunctions.js +3 -4
  2. package/dist/audit/report/models/reportListModel.js +2 -1
  3. package/dist/audit/report/reportingFeature.js +1 -1
  4. package/dist/audit/report/utils/reportUtils.js +30 -11
  5. package/dist/cliConstants.js +13 -6
  6. package/dist/commands/audit/auditConfig.js +1 -2
  7. package/dist/commands/audit/help.js +2 -1
  8. package/dist/commands/audit/processAudit.js +1 -1
  9. package/dist/commands/fingerprint/fingerprintConfig.js +12 -0
  10. package/dist/commands/fingerprint/processFingerprint.js +14 -0
  11. package/dist/commands/learn/learn.js +9 -0
  12. package/dist/commands/learn/processLearn.js +10 -0
  13. package/dist/common/commonHelp.js +8 -1
  14. package/dist/constants/constants.js +1 -1
  15. package/dist/constants/locales.js +14 -3
  16. package/dist/index.js +8 -0
  17. package/dist/lambda/help.js +2 -1
  18. package/dist/scaAnalysis/common/auditReport.js +16 -60
  19. package/dist/scaAnalysis/common/commonReportingFunctionsSca.js +154 -0
  20. package/dist/scaAnalysis/common/models/ScaReportModel.js +45 -0
  21. package/dist/scaAnalysis/common/scaServicesUpload.js +4 -3
  22. package/dist/scaAnalysis/common/utils/reportUtilsSca.js +76 -0
  23. package/dist/scaAnalysis/java/analysis.js +1 -28
  24. package/dist/scaAnalysis/java/index.js +1 -13
  25. package/dist/scaAnalysis/scaAnalysis.js +155 -0
  26. package/dist/scan/autoDetection.js +2 -2
  27. package/dist/scan/fileUtils.js +2 -2
  28. package/dist/scan/formatScanOutput.js +19 -13
  29. package/dist/scan/help.js +2 -1
  30. package/dist/utils/paramsUtil/configStoreParams.js +1 -12
  31. package/dist/utils/paramsUtil/paramHandler.js +1 -7
  32. package/package.json +5 -1
  33. package/src/audit/report/commonReportingFunctions.js +7 -5
  34. package/src/audit/report/models/reportListModel.ts +12 -2
  35. package/src/audit/report/reportingFeature.ts +1 -1
  36. package/src/audit/report/utils/reportUtils.ts +4 -4
  37. package/src/cliConstants.js +15 -6
  38. package/src/commands/audit/auditConfig.js +1 -2
  39. package/src/commands/audit/help.js +2 -1
  40. package/src/commands/audit/processAudit.js +1 -1
  41. package/src/commands/fingerprint/fingerprintConfig.js +19 -0
  42. package/src/commands/fingerprint/processFingerprint.js +21 -0
  43. package/src/commands/learn/learn.js +10 -0
  44. package/src/commands/learn/processLearn.js +13 -0
  45. package/src/common/commonHelp.js +11 -1
  46. package/src/constants/constants.js +1 -1
  47. package/src/constants/locales.js +22 -3
  48. package/src/index.ts +11 -0
  49. package/src/lambda/help.ts +2 -1
  50. package/src/scaAnalysis/common/auditReport.js +25 -80
  51. package/src/scaAnalysis/common/commonReportingFunctionsSca.js +276 -0
  52. package/src/scaAnalysis/common/models/ScaReportModel.ts +81 -0
  53. package/src/scaAnalysis/common/scaServicesUpload.js +5 -3
  54. package/src/scaAnalysis/common/utils/reportUtilsSca.ts +123 -0
  55. package/src/scaAnalysis/java/analysis.js +1 -28
  56. package/src/scaAnalysis/java/index.js +1 -18
  57. package/src/scaAnalysis/scaAnalysis.js +206 -0
  58. package/src/scan/autoDetection.js +2 -2
  59. package/src/scan/fileUtils.js +2 -2
  60. package/src/scan/formatScanOutput.ts +28 -17
  61. package/src/scan/help.js +2 -1
  62. package/src/utils/getConfig.ts +0 -1
  63. package/src/utils/paramsUtil/configStoreParams.js +1 -14
  64. package/src/utils/paramsUtil/paramHandler.js +1 -9
  65. package/dist/commands/scan/sca/scaAnalysis.js +0 -155
  66. package/src/commands/scan/sca/scaAnalysis.js +0 -206
@@ -3,8 +3,7 @@ import {
3
3
  ReportLibraryModel
4
4
  } from '../models/reportLibraryModel'
5
5
  import { ReportSeverityModel } from '../models/reportSeverityModel'
6
- import languageAnalysisEngine from '../../../constants/constants'
7
- import {
6
+ import languageAnalysisEngine, {
8
7
  CRITICAL_COLOUR,
9
8
  CRITICAL_PRIORITY,
10
9
  HIGH_COLOUR,
@@ -19,6 +18,7 @@ import {
19
18
  import { orderBy } from 'lodash'
20
19
  import { SeverityCountModel } from '../models/severityCountModel'
21
20
  import { ReportModelStructure } from '../models/reportListModel'
21
+
22
22
  const {
23
23
  supportedLanguages: { GO }
24
24
  } = languageAnalysisEngine
@@ -30,8 +30,8 @@ export function findHighestSeverityCVE(cveArray: ReportCVEModel[]) {
30
30
  return orderBy(mappedToReportSeverityModels, cve => cve?.priority)[0]
31
31
  }
32
32
 
33
- export function orderByHighestPriority(cves: ReportCVEModel[]) {
34
- return orderBy(cves, ['priority'], ['asc'])
33
+ export function orderByHighestPriority(severityModels: ReportSeverityModel[]) {
34
+ return orderBy(severityModels, ['priority'], ['asc'])
35
35
  }
36
36
 
37
37
  export function findCVESeverity(cve: ReportCVEModel) {
@@ -337,10 +337,6 @@ const auditOptionDefinitions = [
337
337
  '}: ' +
338
338
  i18n.__('constantsIgnoreDev')
339
339
  },
340
- {
341
- name: 'fingerprint',
342
- type: Boolean
343
- },
344
340
  {
345
341
  name: 'save',
346
342
  alias: 's',
@@ -405,6 +401,16 @@ const auditOptionDefinitions = [
405
401
  }
406
402
  ]
407
403
 
404
+ const fingerprintOptionDefinitions = [
405
+ ...auditOptionDefinitions,
406
+ {
407
+ name: 'depth',
408
+ type: Number,
409
+ description:
410
+ '{bold ' + i18n.__('constantsOptional') + '}: ' + i18n.__('depthOption')
411
+ }
412
+ ]
413
+
408
414
  const mainUsageGuide = commandLineUsage([
409
415
  {
410
416
  header: i18n.__('constantsHeader'),
@@ -426,7 +432,8 @@ const mainUsageGuide = commandLineUsage([
426
432
  { name: i18n.__('auditName'), summary: i18n.__('helpAuditSummary') },
427
433
  { name: i18n.__('versionName'), summary: i18n.__('helpVersionSummary') },
428
434
  { name: i18n.__('configName'), summary: i18n.__('helpConfigSummary') },
429
- { name: i18n.__('helpName'), summary: i18n.__('helpSummary') }
435
+ { name: i18n.__('helpName'), summary: i18n.__('helpSummary') },
436
+ { name: i18n.__('learnName'), summary: i18n.__('helpLearnSummary') }
430
437
  ]
431
438
  },
432
439
  {
@@ -440,7 +447,8 @@ const mainUsageGuide = commandLineUsage([
440
447
  ]
441
448
  },
442
449
  commonHelpLinks()[0],
443
- commonHelpLinks()[1]
450
+ commonHelpLinks()[1],
451
+ commonHelpLinks()[2]
444
452
  ])
445
453
 
446
454
  const mainDefinition = [{ name: 'command', defaultOption: true }]
@@ -450,6 +458,7 @@ module.exports = {
450
458
  mainUsageGuide,
451
459
  mainDefinition,
452
460
  scanOptionDefinitions,
461
+ fingerprintOptionDefinitions,
453
462
  auditOptionDefinitions,
454
463
  authOptionDefinitions,
455
464
  configOptionDefinitions,
@@ -10,8 +10,7 @@ const getAuditConfig = async (contrastConf, command, argv) => {
10
10
  constants.commandLineDefinitions.auditOptionDefinitions
11
11
  )
12
12
  const paramsAuth = paramHandler.getAuth(auditParameters)
13
- const javaAgreement = paramHandler.getAgreement()
14
- return { ...paramsAuth, ...auditParameters, ...javaAgreement }
13
+ return { ...paramsAuth, ...auditParameters }
15
14
  }
16
15
 
17
16
  module.exports = {
@@ -62,7 +62,8 @@ const auditUsageGuide = commandLineUsage([
62
62
  constants.commandLineDefinitions.auditAdvancedOptionDefinitionsForHelp
63
63
  },
64
64
  commonHelpLinks()[0],
65
- commonHelpLinks()[1]
65
+ commonHelpLinks()[1],
66
+ commonHelpLinks()[2]
66
67
  ])
67
68
 
68
69
  module.exports = {
@@ -1,6 +1,6 @@
1
1
  const auditConfig = require('./auditConfig')
2
2
  const { auditUsageGuide } = require('./help')
3
- const scaController = require('../scan/sca/scaAnalysis')
3
+ const scaController = require('../../scaAnalysis/scaAnalysis')
4
4
  const { sendTelemetryConfigAsObject } = require('../../telemetry/telemetry')
5
5
  const { postRunMessage } = require('../../common/commonHelp')
6
6
 
@@ -0,0 +1,19 @@
1
+ const parsedCLIOptions = require('../../utils/parsedCLIOptions')
2
+ const constants = require('../../cliConstants')
3
+ const paramHandler = require('../../utils/paramsUtil/paramHandler')
4
+
5
+ const getFingerprintConfig = async (contrastConf, command, argv) => {
6
+ const fingerprintParameters = await parsedCLIOptions.getCommandLineArgsCustom(
7
+ contrastConf,
8
+ command,
9
+ argv,
10
+ constants.commandLineDefinitions.fingerprintOptionDefinitions
11
+ )
12
+ const paramsAuth = paramHandler.getAuth(fingerprintParameters)
13
+
14
+ return { ...paramsAuth, ...fingerprintParameters }
15
+ }
16
+
17
+ module.exports = {
18
+ getFingerprintConfig
19
+ }
@@ -0,0 +1,21 @@
1
+ const fingerprintConfig = require('./fingerprintConfig')
2
+ const autoDetection = require('../../scan/autoDetection')
3
+ const saveResults = require('../../scan/saveResults')
4
+ const processFingerprint = async (contrastConf, argvMain) => {
5
+ const config = await fingerprintConfig.getFingerprintConfig(
6
+ contrastConf,
7
+ 'fingerprint',
8
+ argvMain
9
+ )
10
+ let fingerprint = await autoDetection.autoDetectFingerprintInfo(
11
+ config.file,
12
+ config.depth
13
+ )
14
+ let idArray = fingerprint.map(x => x.id)
15
+ await saveResults.writeResultsToFile(fingerprint, 'fingerPrintInfo.json')
16
+ return console.log(idArray)
17
+ }
18
+
19
+ module.exports = {
20
+ processFingerprint
21
+ }
@@ -0,0 +1,10 @@
1
+ const open = require('open')
2
+
3
+ async function openLearnPage() {
4
+ const url = 'https://www.contrastsecurity.com/developer/learn'
5
+ return open(url)
6
+ }
7
+
8
+ module.exports = {
9
+ openLearnPage
10
+ }
@@ -0,0 +1,13 @@
1
+ const { openLearnPage } = require('./learn')
2
+
3
+ async function processLearn() {
4
+ console.log('Opening develop central...')
5
+ console.log(
6
+ 'If the page does not open you can open it directly via https://www.contrastsecurity.com/developer/learn'
7
+ )
8
+ return openLearnPage()
9
+ }
10
+
11
+ module.exports = {
12
+ processLearn
13
+ }
@@ -19,6 +19,11 @@ const commonHelpLinks = () => {
19
19
  i18n.__('commonHelpLearnMoreEnterpriseHeader') +
20
20
  i18n.__('commonHelpLearnMoreEnterpriseText')
21
21
  ]
22
+ },
23
+ {
24
+ content: [
25
+ i18n.__('commonHelpLearnHeader') + i18n.__('commonHelpLearnText')
26
+ ]
22
27
  }
23
28
  ]
24
29
  }
@@ -27,7 +32,7 @@ const postRunMessage = commandName => {
27
32
  console.log('\n' + chalk.underline.bold('Other Features:'))
28
33
  if (commandName !== 'scan')
29
34
  console.log(
30
- "'contrast scan' to run Contrasts’ industry leading SAST scanner"
35
+ "'contrast scan' to run Contrast's industry leading SAST scanner"
31
36
  )
32
37
  if (commandName !== 'audit')
33
38
  console.log(
@@ -35,6 +40,11 @@ const postRunMessage = commandName => {
35
40
  )
36
41
  if (commandName !== 'lambda')
37
42
  console.log("'contrast lambda' to secure your AWS serverless functions")
43
+
44
+ if (commandName !== 'learn')
45
+ console.log(
46
+ "'contrast learn' launches Contrast's Secure Code Learning Hub."
47
+ )
38
48
  }
39
49
 
40
50
  module.exports = {
@@ -14,7 +14,7 @@ const HIGH = 'HIGH'
14
14
  const CRITICAL = 'CRITICAL'
15
15
  // App
16
16
  const APP_NAME = 'contrast'
17
- const APP_VERSION = '1.0.19'
17
+ const APP_VERSION = '1.0.21'
18
18
  const TIMEOUT = 120000
19
19
  const HIGH_COLOUR = '#ff9900'
20
20
  const CRITICAL_COLOUR = '#e35858'
@@ -177,6 +177,12 @@ const en_locales = () => {
177
177
  versionName: 'version',
178
178
  configName: 'config',
179
179
  helpName: 'help',
180
+ learnName: 'learn',
181
+ helpLearnSummary: 'launches Contrast’s Secure Code Learning Hub.',
182
+ fingerprintName:
183
+ 'assess repo to see how many languages it can detect. For use in pipeline only.',
184
+ depthOption:
185
+ 'can set how deep in the file system the cli looks for language files',
180
186
  scanOptionsLanguageSummary: 'Valid values are JAVA, JAVASCRIPT and DOTNET',
181
187
  scanOptionsTimeoutSummary:
182
188
  'Time in seconds to wait for scan to complete. Default value is 300 seconds.',
@@ -194,7 +200,10 @@ const en_locales = () => {
194
200
  chalk.bold('\ncontrast scan') +
195
201
  " to run Contrast's industry leading SAST scanner. \nSupports Java, JavaScript and .Net \n" +
196
202
  chalk.bold('\ncontrast audit') +
197
- ' to find vulnerabilities in your open source dependencies.\nSupports Java, .NET, Node, Ruby, Python, Go and PHP \n' +
203
+ ' to find vulnerabilities in your open source dependencies.' +
204
+ '\nSupports Java, .NET, Node, Ruby, Python, Go and PHP.' +
205
+ '\nOur CLI runs native build tools to generate a complete dependency tree.' +
206
+ '\nIf you are running on untrusted code, consider running in a sandbox.\n' +
198
207
  chalk.bold('\ncontrast lambda') +
199
208
  ' to secure your AWS serverless functions. \nSupports Java and Python \n' +
200
209
  chalk.bold('\ncontrast help') +
@@ -259,7 +268,8 @@ const en_locales = () => {
259
268
  )} Maven build platform including the dependency plugin.
260
269
  ${chalk.bold('Or')} build.gradle ${chalk.bold(
261
270
  'and'
262
- )} gradle dependencies or ./gradlew dependencies must be supported`,
271
+ )} gradle dependencies or ./gradlew dependencies must be supported
272
+ If you are running on untrusted code, consider running in a sandbox.`,
263
273
  constantsAuditPrerequisitesContentDotNetMessage: `
264
274
  ${chalk.bold(
265
275
  '.NET framework and .NET core:'
@@ -316,7 +326,16 @@ const en_locales = () => {
316
326
  commonHelpJoinDiscussionHeader: chalk.hex('#9DC184')(
317
327
  'Join the discussion:'
318
328
  ),
319
- commonHelpJoinDiscussionText: ' https://dev.to/codesec',
329
+ commonHelpJoinDiscussionText:
330
+ ' https://www.contrastsecurity.com/developer/community',
331
+ commonHelpLearnHeader:
332
+ chalk.hex('#ffe599')('\rWant to UP your game?') +
333
+ " type 'contrast learn'",
334
+ commonHelpLearnText: `\n🎓 Advance your security knowledge and become an ${chalk.hex(
335
+ '#ffd966'
336
+ )('All-star coder')} ⭐ with ${chalk.bold(
337
+ 'Contrast Secure Code Learning Hub.'
338
+ )} 😺`,
320
339
  authCommand: {
321
340
  credentialsAccepted: {
322
341
  title: 'Credentials accepted',
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { processAudit } from './commands/audit/processAudit'
5
5
  import { processAuth } from './commands/auth/auth'
6
6
  import { processConfig } from './commands/config/config'
7
7
  import { processScan } from './commands/scan/processScan'
8
+ import { processFingerprint } from './commands/fingerprint/processFingerprint'
8
9
  import constants from './cliConstants'
9
10
  import { APP_NAME, APP_VERSION } from './constants/constants'
10
11
  import { processLambda } from './lambda/lambda'
@@ -15,6 +16,8 @@ import {
15
16
  } from './common/versionChecker'
16
17
  import { findCommandOnError } from './common/errorHandling'
17
18
  import { sendTelemetryConfigAsConfObj } from './telemetry/telemetry'
19
+ import { openLearnPage } from './commands/learn/learn'
20
+ import { processLearn } from './commands/learn/processLearn'
18
21
  const {
19
22
  commandLineDefinitions: { mainUsageGuide, mainDefinition }
20
23
  } = constants
@@ -82,6 +85,14 @@ const start = async () => {
82
85
  return await processAudit(config, argvMain)
83
86
  }
84
87
 
88
+ if (command === 'learn') {
89
+ return processLearn()
90
+ }
91
+
92
+ if (command === 'fingerprint') {
93
+ return await processFingerprint(config, argvMain)
94
+ }
95
+
85
96
  if (
86
97
  command === 'help' ||
87
98
  argvMain.includes('--help') ||
@@ -82,7 +82,8 @@ const lambdaUsageGuide = commandLineUsage([
82
82
  ]
83
83
  },
84
84
  commonHelpLinks()[0],
85
- commonHelpLinks()[1]
85
+ commonHelpLinks()[1],
86
+ commonHelpLinks()[2]
86
87
  ])
87
88
 
88
89
  export { lambdaUsageGuide }
@@ -1,105 +1,50 @@
1
1
  const {
2
2
  getSeverityCounts,
3
- createSummaryMessageTop,
4
- printVulnInfo,
5
- getReportTable,
6
- getIssueRow,
7
3
  printNoVulnFoundMsg
8
4
  } = require('../../audit/report/commonReportingFunctions')
9
- const { orderBy } = require('lodash')
10
- const { assignBySeverity } = require('../../scan/formatScanOutput')
11
- const chalk = require('chalk')
12
- const { CE_URL } = require('../../constants/constants')
13
5
  const common = require('../../common/fail')
14
- const i18n = require('i18n')
6
+ const { printFormattedOutputSca } = require('./commonReportingFunctionsSca')
15
7
 
16
- const processAuditReport = (config, results) => {
8
+ const processAuditReport = (config, reportModelList) => {
17
9
  let severityCounts = {}
18
- if (results !== undefined) {
19
- severityCounts = formatScaServicesReport(config, results)
10
+ if (reportModelList !== undefined) {
11
+ severityCounts = formatScaServicesReport(config, reportModelList)
20
12
  }
21
13
 
22
14
  if (config.fail) {
23
15
  common.processFail(config, severityCounts)
24
16
  }
25
17
  }
26
- const formatScaServicesReport = (config, results) => {
27
- const projectOverviewCount = getSeverityCounts(results)
18
+ const formatScaServicesReport = (config, reportModelList) => {
19
+ const projectOverviewCount = getSeverityCounts(reportModelList)
28
20
 
29
21
  if (projectOverviewCount.total === 0) {
30
22
  printNoVulnFoundMsg()
31
- return projectOverviewCount
32
23
  } else {
33
- let total = 0
34
- const numberOfCves = results.length
35
- const table = getReportTable()
36
- let contrastHeaderNumCounter = 0
37
- let assignPriorityToResults = results.map(result =>
38
- assignBySeverity(result, result)
39
- )
40
- const numberOfVulns = results
41
- .map(result => result.vulnerabilities)
42
- .reduce((a, b) => {
43
- return (total += b.length)
44
- }, 0)
45
- const outputOrderedByLowestSeverityAndLowestNumOfCvesFirst = orderBy(
46
- assignPriorityToResults,
47
- [
48
- reportListItem => {
49
- return reportListItem.priority
50
- },
51
- reportListItem => {
52
- return reportListItem.vulnerabilities.length
53
- }
54
- ],
55
- ['asc', 'desc']
56
- )
57
-
58
- for (const result of outputOrderedByLowestSeverityAndLowestNumOfCvesFirst) {
59
- contrastHeaderNumCounter++
60
- const cvesNum = result.vulnerabilities.length
61
- const grammaticallyCorrectVul =
62
- result.vulnerabilities.length > 1 ? 'vulnerabilities' : 'vulnerability'
63
-
64
- const headerColour = chalk.hex(result.colour)
65
- const headerRow = [
66
- headerColour(
67
- `CONTRAST-${contrastHeaderNumCounter.toString().padStart(3, '0')}`
68
- ),
69
- headerColour(`-`),
70
- headerColour(`[${result.severity}] `) +
71
- headerColour.bold(`${result.artifactName}`) +
72
- ` introduces ${cvesNum} ${grammaticallyCorrectVul}`
73
- ]
24
+ const numberOfVulnerableLibraries = reportModelList.map(library => {
25
+ let count = 0
74
26
 
75
- const adviceRow = [
76
- chalk.bold(`Advice`),
77
- chalk.bold(`:`),
78
- `Change to version ${result.remediationAdvice.latestStableVersion}`
79
- ]
27
+ if (library.vulnerabilities.length > 0) {
28
+ count++
29
+ }
80
30
 
81
- let assignPriorityToVulns = result.vulnerabilities.map(result =>
82
- assignBySeverity(result, result)
83
- )
84
- const issueRow = getIssueRow(assignPriorityToVulns)
31
+ return count
32
+ }).length
85
33
 
86
- table.push(headerRow, issueRow, adviceRow)
87
- console.log()
88
- }
89
-
90
- console.log()
91
- createSummaryMessageTop(numberOfCves, numberOfVulns)
92
- console.log(table.toString() + '\n')
93
- printVulnInfo(projectOverviewCount)
34
+ let numberOfCves = reportModelList.reduce(
35
+ (count, current) => count + current.vulnerabilities.length,
36
+ 0
37
+ )
94
38
 
95
- if (config.host !== CE_URL) {
96
- console.log('\n' + chalk.bold(i18n.__('auditServicesMessageForTS')))
97
- console.log(
98
- `${config.host}/Contrast/static/ng/index.html#/${config.organizationId}/applications/${config.applicationId}/libs`
99
- )
100
- }
101
- return projectOverviewCount
39
+ printFormattedOutputSca(
40
+ config,
41
+ reportModelList,
42
+ numberOfVulnerableLibraries,
43
+ numberOfCves
44
+ )
102
45
  }
46
+
47
+ return projectOverviewCount
103
48
  }
104
49
  module.exports = {
105
50
  formatScaServicesReport,