@contrast/contrast 1.0.2 → 1.0.5

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 (113) hide show
  1. package/.prettierignore +4 -0
  2. package/README.md +24 -16
  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} +30 -13
  6. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +25 -0
  7. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +51 -237
  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/reportSeverityModel.js +10 -0
  11. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +24 -129
  12. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +85 -0
  13. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +2 -14
  14. package/dist/commands/audit/auditConfig.js +8 -2
  15. package/dist/commands/audit/auditController.js +14 -5
  16. package/dist/commands/audit/saveFile.js +11 -0
  17. package/dist/commands/auth/auth.js +19 -1
  18. package/dist/commands/config/config.js +19 -8
  19. package/dist/commands/scan/processScan.js +13 -27
  20. package/dist/commands/scan/sca/scaAnalysis.js +44 -0
  21. package/dist/common/HTTPClient.js +29 -26
  22. package/dist/common/errorHandling.js +15 -39
  23. package/dist/common/versionChecker.js +32 -0
  24. package/dist/constants/constants.js +16 -2
  25. package/dist/constants/lambda.js +3 -1
  26. package/dist/constants/locales.js +58 -48
  27. package/dist/constants.js +59 -3
  28. package/dist/index.js +48 -30
  29. package/dist/lambda/help.js +22 -14
  30. package/dist/lambda/lambda.js +6 -0
  31. package/dist/sbom/generateSbom.js +20 -0
  32. package/dist/scaAnalysis/common/formatMessage.js +11 -0
  33. package/dist/scaAnalysis/common/treeUpload.js +30 -0
  34. package/dist/scaAnalysis/java/analysis.js +116 -0
  35. package/dist/scaAnalysis/java/index.js +18 -0
  36. package/dist/scaAnalysis/java/javaBuildDepsParser.js +326 -0
  37. package/dist/scan/autoDetection.js +46 -1
  38. package/dist/scan/fileUtils.js +73 -1
  39. package/dist/scan/formatScanOutput.js +212 -0
  40. package/dist/scan/help.js +6 -2
  41. package/dist/scan/models/groupedResultsModel.js +11 -0
  42. package/dist/scan/models/resultContentModel.js +2 -0
  43. package/dist/scan/models/scanResultsModel.js +11 -0
  44. package/dist/scan/populateProjectIdAndProjectName.js +1 -0
  45. package/dist/scan/saveResults.js +9 -10
  46. package/dist/scan/scan.js +26 -101
  47. package/dist/scan/scanConfig.js +20 -1
  48. package/dist/scan/scanController.js +8 -4
  49. package/dist/scan/scanResults.js +8 -17
  50. package/dist/utils/getConfig.js +3 -0
  51. package/dist/utils/requestUtils.js +1 -1
  52. package/dist/utils/saveFile.js +19 -0
  53. package/package.json +3 -2
  54. package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
  55. package/src/audit/catalogueApplication/catalogueApplication.js +4 -16
  56. package/src/audit/languageAnalysisEngine/{langugageAnalysisFactory.js → languageAnalysisFactory.js} +41 -19
  57. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +71 -0
  58. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +105 -0
  59. package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +30 -0
  60. package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +32 -0
  61. package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +9 -0
  62. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +56 -0
  63. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +110 -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 +21 -5
  67. package/src/commands/audit/processAudit.ts +3 -1
  68. package/src/commands/audit/saveFile.ts +6 -0
  69. package/src/commands/auth/auth.js +25 -1
  70. package/src/commands/config/config.js +22 -8
  71. package/src/commands/scan/processScan.js +15 -31
  72. package/src/commands/scan/sca/scaAnalysis.js +73 -0
  73. package/src/common/HTTPClient.js +42 -36
  74. package/src/common/errorHandling.ts +17 -48
  75. package/src/common/versionChecker.ts +41 -0
  76. package/src/constants/constants.js +17 -4
  77. package/src/constants/lambda.js +3 -1
  78. package/src/constants/locales.js +69 -63
  79. package/src/constants.js +66 -3
  80. package/src/index.ts +62 -36
  81. package/src/lambda/help.ts +22 -14
  82. package/src/lambda/lambda.ts +8 -0
  83. package/src/sbom/generateSbom.ts +17 -0
  84. package/src/scaAnalysis/common/formatMessage.js +10 -0
  85. package/src/scaAnalysis/common/treeUpload.js +34 -0
  86. package/src/scaAnalysis/java/analysis.js +159 -0
  87. package/src/scaAnalysis/java/index.js +21 -0
  88. package/src/scaAnalysis/java/javaBuildDepsParser.js +391 -0
  89. package/src/scan/autoDetection.js +54 -1
  90. package/src/scan/fileUtils.js +91 -1
  91. package/src/scan/formatScanOutput.ts +241 -0
  92. package/src/scan/help.js +6 -2
  93. package/src/scan/models/groupedResultsModel.ts +20 -0
  94. package/src/scan/models/resultContentModel.ts +86 -0
  95. package/src/scan/models/scanResultsModel.ts +52 -0
  96. package/src/scan/populateProjectIdAndProjectName.js +1 -0
  97. package/src/scan/saveResults.js +8 -9
  98. package/src/scan/scan.ts +62 -0
  99. package/src/scan/scanConfig.js +26 -1
  100. package/src/scan/scanController.js +12 -4
  101. package/src/scan/scanResults.js +19 -17
  102. package/src/utils/getConfig.ts +12 -0
  103. package/src/utils/requestUtils.js +1 -1
  104. package/src/utils/saveFile.js +19 -0
  105. package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -17
  106. package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -81
  107. package/dist/common/findLatestCLIVersion.js +0 -23
  108. package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +0 -27
  109. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +0 -303
  110. package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +0 -124
  111. package/src/audit/languageAnalysisEngine/report/reportingFeature.js +0 -190
  112. package/src/common/findLatestCLIVersion.ts +0 -27
  113. package/src/scan/scan.js +0 -167
@@ -3,9 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.approximateCommandOnError = exports.libraryAnalysisError = exports.handleResponseErrors = exports.getErrorMessage = exports.generalError = exports.hostWarningError = exports.failOptionError = exports.proxyError = exports.forbiddenError = exports.badRequestError = exports.unauthenticatedError = exports.genericError = void 0;
6
+ exports.reportFailureError = exports.vulnerabilitiesFailureError = exports.snapshotFailureError = exports.findCommandOnError = exports.libraryAnalysisError = exports.handleResponseErrors = exports.getErrorMessage = exports.generalError = exports.failOptionError = exports.proxyError = exports.forbiddenError = exports.badRequestError = exports.unauthenticatedError = exports.genericError = void 0;
7
7
  const i18n_1 = __importDefault(require("i18n"));
8
- const lodash_1 = require("lodash");
9
8
  const handleResponseErrors = (res, api) => {
10
9
  if (res.statusCode === 400) {
11
10
  api === 'catalogue' ? badRequestError(true) : badRequestError(false);
@@ -37,23 +36,17 @@ const libraryAnalysisError = () => {
37
36
  };
38
37
  exports.libraryAnalysisError = libraryAnalysisError;
39
38
  const snapshotFailureError = () => {
40
- console.log('\n ******************************** ' +
41
- i18n_1.default.__('snapshotFailureHeader') +
42
- ' *********************************\n' +
43
- i18n_1.default.__('snapshotFailureMessage'));
39
+ console.log(i18n_1.default.__('snapshotFailureMessage'));
44
40
  };
41
+ exports.snapshotFailureError = snapshotFailureError;
45
42
  const vulnerabilitiesFailureError = () => {
46
- console.log('\n ******************************** ' +
47
- i18n_1.default.__('snapshotFailureHeader') +
48
- ' *********************************\n' +
49
- i18n_1.default.__('vulnerabilitiesFailureMessage'));
43
+ console.log(i18n_1.default.__('vulnerabilitiesFailureMessage'));
50
44
  };
45
+ exports.vulnerabilitiesFailureError = vulnerabilitiesFailureError;
51
46
  const reportFailureError = () => {
52
- console.log('\n ******************************** ' +
53
- i18n_1.default.__('snapshotFailureHeader') +
54
- ' *********************************\n' +
55
- i18n_1.default.__('reportFailureMessage'));
47
+ console.log(i18n_1.default.__('auditReportFailureMessage'));
56
48
  };
49
+ exports.reportFailureError = reportFailureError;
57
50
  const genericError = (missingCliOption) => {
58
51
  console.log(`*************************** ${i18n_1.default.__('yamlMissingParametersHeader')} ***************************\n${missingCliOption}`);
59
52
  console.error(i18n_1.default.__('yamlMissingParametersMessage'));
@@ -72,16 +65,13 @@ const badRequestError = (catalogue) => {
72
65
  exports.badRequestError = badRequestError;
73
66
  const forbiddenError = () => {
74
67
  generalError('forbiddenRequestErrorHeader', 'forbiddenRequestErrorMessage');
68
+ process.exit(1);
75
69
  };
76
70
  exports.forbiddenError = forbiddenError;
77
71
  const proxyError = () => {
78
72
  generalError('proxyErrorHeader', 'proxyErrorMessage');
79
73
  };
80
74
  exports.proxyError = proxyError;
81
- const hostWarningError = () => {
82
- console.log(i18n_1.default.__('snapshotHostMessage'));
83
- };
84
- exports.hostWarningError = hostWarningError;
85
75
  const failOptionError = () => {
86
76
  console.log('\n ******************************** ' +
87
77
  i18n_1.default.__('snapshotFailureHeader') +
@@ -107,7 +97,7 @@ const generalError = (header, message) => {
107
97
  console.log(finalMessage);
108
98
  };
109
99
  exports.generalError = generalError;
110
- const approximateCommandOnError = (unknownOptions) => {
100
+ const findCommandOnError = (unknownOptions) => {
111
101
  const commandKeywords = {
112
102
  auth: 'auth',
113
103
  audit: 'audit',
@@ -115,24 +105,10 @@ const approximateCommandOnError = (unknownOptions) => {
115
105
  lambda: 'lambda',
116
106
  config: 'config'
117
107
  };
118
- const sortedUnknownOptions = (0, lodash_1.sortBy)(unknownOptions, param => param === 'auth' ||
119
- param === 'audit' ||
120
- param === 'scan' ||
121
- param === 'lambda' ||
122
- param === 'config'
123
- ? 0
124
- : 1);
125
- const foundCommands = sortedUnknownOptions.filter(command => commandKeywords[command]);
126
- const parsedUnknownOptions = sortedUnknownOptions
127
- .toString()
128
- .replace(/,/g, ' ');
129
- const approximateParams = parsedUnknownOptions
130
- .replace(new RegExp(foundCommands.join('|'), 'g'), '')
131
- .trim();
132
- const approximateCommand = `${foundCommands[0]} ${approximateParams}`;
133
- return {
134
- approximateCommand,
135
- approximateCommandKeyword: foundCommands[0]
136
- };
108
+ const containsCommandKeyword = unknownOptions.some(command => commandKeywords[command]);
109
+ if (containsCommandKeyword) {
110
+ const foundCommands = unknownOptions.filter(command => commandKeywords[command]);
111
+ return foundCommands[0];
112
+ }
137
113
  };
138
- exports.approximateCommandOnError = approximateCommandOnError;
114
+ exports.findCommandOnError = findCommandOnError;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isCorrectNodeVersion = exports.findLatestCLIVersion = void 0;
7
+ const latest_version_1 = __importDefault(require("latest-version"));
8
+ const constants_1 = require("../constants/constants");
9
+ const boxen_1 = __importDefault(require("boxen"));
10
+ const chalk_1 = __importDefault(require("chalk"));
11
+ const semver_1 = __importDefault(require("semver"));
12
+ async function findLatestCLIVersion(updateMessageHidden) {
13
+ if (!updateMessageHidden) {
14
+ const latestCLIVersion = await (0, latest_version_1.default)('@contrast/contrast');
15
+ if (semver_1.default.lt(constants_1.APP_VERSION, latestCLIVersion)) {
16
+ const updateAvailableMessage = `Update available ${chalk_1.default.yellow(constants_1.APP_VERSION)} → ${chalk_1.default.green(latestCLIVersion)}`;
17
+ const npmUpdateAvailableCommand = `Run ${chalk_1.default.cyan('npm i @contrast/contrast -g')} to update via npm`;
18
+ const homebrewUpdateAvailableCommand = `Run ${chalk_1.default.cyan('brew install contrastsecurity/tap/contrast')} to update via brew`;
19
+ console.log((0, boxen_1.default)(`${updateAvailableMessage}\n${npmUpdateAvailableCommand}\n\n${homebrewUpdateAvailableCommand}`, {
20
+ titleAlignment: 'center',
21
+ margin: 1,
22
+ padding: 1,
23
+ align: 'center'
24
+ }));
25
+ }
26
+ }
27
+ }
28
+ exports.findLatestCLIVersion = findLatestCLIVersion;
29
+ async function isCorrectNodeVersion(currentVersion) {
30
+ return semver_1.default.satisfies(currentVersion, '>=16.13.2 <17');
31
+ }
32
+ exports.isCorrectNodeVersion = isCorrectNodeVersion;
@@ -12,10 +12,17 @@ const MEDIUM = 'MEDIUM';
12
12
  const HIGH = 'HIGH';
13
13
  const CRITICAL = 'CRITICAL';
14
14
  const APP_NAME = 'contrast';
15
- const APP_VERSION = '1.0.2';
15
+ const APP_VERSION = '1.0.5';
16
16
  const TIMEOUT = 120000;
17
+ const HIGH_COLOUR = '#ff9900';
18
+ const CRITICAL_COLOUR = '#e35858';
19
+ const MEDIUM_COLOUR = '#f1c232';
20
+ const LOW_COLOUR = '#ff9900';
21
+ const NOTE_COLOUR = '#999999';
17
22
  const AUTH_UI_URL = 'https://cli-auth.contrastsecurity.com';
18
23
  const AUTH_CALLBACK_URL = 'https://cli-auth-api.contrastsecurity.com';
24
+ const SARIF_FILE = 'SARIF';
25
+ const CE_URL = 'https://ce.contrastsecurity.com/';
19
26
  module.exports = {
20
27
  supportedLanguages: { NODE, DOTNET, JAVA, RUBY, PYTHON, GO, PHP, JAVASCRIPT },
21
28
  LOW,
@@ -26,5 +33,12 @@ module.exports = {
26
33
  APP_NAME,
27
34
  TIMEOUT,
28
35
  AUTH_UI_URL,
29
- AUTH_CALLBACK_URL
36
+ AUTH_CALLBACK_URL,
37
+ SARIF_FILE,
38
+ HIGH_COLOUR,
39
+ CRITICAL_COLOUR,
40
+ MEDIUM_COLOUR,
41
+ LOW_COLOUR,
42
+ NOTE_COLOUR,
43
+ CE_URL
30
44
  };
@@ -25,9 +25,11 @@ const lambda = {
25
25
  loadingFunctionList: 'Loading lambda function list',
26
26
  functionsFound: '{{count}} functions found',
27
27
  noFunctionsFound: 'No functions found',
28
- failedToLoadFunctions: 'Faled to load lambda functions',
28
+ failedToLoadFunctions: 'Failed to load lambda functions',
29
29
  availableForScan: '{{icon}} {{count}} available for scan',
30
30
  runtimeCount: '----- {{runtime}} ({{count}}) -----',
31
+ gatherResults: 'Gathering results...',
32
+ doneGatherResults: 'Done gathering results',
31
33
  whatHappenedTitle: 'What happened:',
32
34
  whatHappenedItem: '{{policy}} have:\n{{comments}}\n',
33
35
  recommendation: 'Recommendation:',
@@ -4,43 +4,29 @@ const chalk = require('chalk');
4
4
  const en_locales = () => {
5
5
  return {
6
6
  successHeader: 'SUCCESS',
7
- snapshotSuccessMessage: ' Please go to the Contrast UI to view your dependency tree.',
7
+ snapshotSuccessMessage: 'Please go to the Contrast UI to view your dependency tree.',
8
8
  snapshotFailureHeader: 'FAIL',
9
- snapshotFailureMessage: ' Unable to send library analysis to your Contrast UI.',
10
- snapshotHostMessage: " No host supplied. Using default host 'app.contrastsecurity.com'. Please ensure this is correct.",
11
- vulnerabilitiesSuccessMessage: ' Vulnerability data successfully retrieved',
12
- vulnerabilitiesFailureMessage: ' Unable to retrieve library vulnerabilities from Team Server.',
13
- reportSuccessMessage: ' Report successfully retrieved',
14
- reportFailureMessage: ' Unable to generate library report.',
9
+ snapshotFailureMessage: 'Library analysis failed',
10
+ snapshotHostMessage: "No host supplied. Using default host 'app.contrastsecurity.com'. Please ensure this is correct.",
11
+ vulnerabilitiesSuccessMessage: 'Vulnerability data successfully retrieved',
12
+ vulnerabilitiesFailureMessage: 'Unable to retrieve library vulnerabilities',
15
13
  catchErrorMessage: 'Contrast UI error: ',
16
14
  dependenciesNote: 'Please Note: We currently only support projects with one .csproj AND *.package.lock.json',
17
- languageAnalysisFailureMessage: 'LANGUAGE ANALYSIS FAILED',
15
+ languageAnalysisFailureMessage: 'SCA Analysis Failure',
18
16
  languageAnalysisFactoryFailureHeader: 'FAIL',
19
- projectPathParameter: 'Please set the %s to locate the source code for the project',
20
- apiKeyParameter: 'Please set the %s to connect to the Contrast UI',
21
- applicationNameParameter: 'Please provide a value for %s, to appear in the Contrast UI',
22
- languageParameter: 'Please set the %s to the language of the source project. Allowable values are JAVA, DOTNET, NODE, PYTHON and RUBY.',
23
- hostParameter: 'Please set the %s to the hostname and (optionally) the port expressed as <host>:<port> of the Contrast UI',
24
- organizationIdParameter: 'Please set the %s to correctly identify your organization within the Contrast UI',
25
- authorizationParameter: 'Please set the %s to your authorization header, found in the Contrast UI',
26
- applicationIdParameter: 'Please set the %s to the value provided within the Contrast UI for the target application',
27
- libraryAnalysisError: 'Please ensure the language parameter is set in accordance to the language specified on the project path.\nThe Contrast-CLI must be run in the same directory as the project manifest file OR the project_path parameter must be used to identify the directory containing the project manifest file.\n\nFor further information please read our usage guide, which can be accessed with the following command:\n\ncontrast-cli --help',
17
+ libraryAnalysisError: 'Please ensure the language parameter is set in accordance to the language specified on the project path.\nContrast CLI must be run in the same directory as the project manifest file OR the project_path parameter must be used to identify the directory containing the project manifest file.\n\nFor further information please read our usage guide, which can be accessed with the following command:\n\ncontrast-cli --help',
28
18
  yamlMissingParametersHeader: 'Missing Parameters',
29
- yamlMissingParametersMessage: 'The following parameters are required: \n \norganization_id \napi_key \nauthorization \nhost \napplication_name or application_id \nlanguage \n \nThey must be specified as a command line argument or within the yaml file. \nFor further information please read our usage guide, which can be accessed with the following command:\ncontrast-cli --help',
19
+ yamlMissingParametersMessage: 'The following parameters are required: \n \norganization-id \napi-key \nauthorization \nhost \nlanguage \n \nThey must be specified as a command line argument. \nFor further information please read our usage guide, which can be accessed with the following command:\ncontrast audit --help',
30
20
  unauthenticatedErrorHeader: '401 error - Unauthenticated',
31
- unauthenticatedErrorMessage: 'Please check the following keys are correct:\n--organization_id, --api_key or --authorization',
21
+ unauthenticatedErrorMessage: 'Please check the following keys are correct:\n--organization-id, --api-key or --authorization',
32
22
  badRequestErrorHeader: '400 error - Bad Request',
33
- badRequestErrorMessage: 'Please check the following key is correct: \n--application_id',
23
+ badRequestErrorMessage: 'Please check the following key is correct: \n--application-id',
34
24
  badRequestCatalogueErrorMessage: 'The application name already exists, please use a unique name',
35
25
  forbiddenRequestErrorHeader: '403 error - Forbidden',
36
26
  forbiddenRequestErrorMessage: 'You do not have permission to access this server.',
37
27
  proxyErrorHeader: '407 error - Proxy Authentication Required',
38
28
  proxyErrorMessage: 'Please provide valid authentication credentials for the proxy server.',
39
- downgradeHttpsHttp: 'Connection to ContrastUI using https failed. Attempting to connect using http...',
40
- setSpecifiedParameter: 'Please set the %s ',
41
- catalogueFailureCommand: 'Failed to catalogue a new application for reason: ',
42
- catalogueFailureHostCommand: 'Failed to catalogue a new application, please ensure you have the correct host and authentication. Error: ',
43
- catalogueSuccessCommand: 'This application ID can now be used to send dependency data to Contrast: ',
29
+ catalogueSuccessCommand: 'Application Created',
44
30
  dotnetAnalysisFailure: '.NET analysis failed because: ',
45
31
  dotnetReadLockfile: 'Failed to read the lock file @ %s because: ',
46
32
  dotnetParseLockfile: "Failed to parse .NET lock file @ '%s' because: ",
@@ -84,10 +70,9 @@ const en_locales = () => {
84
70
  constantsOptionalForCatalogue: '(optional for catalogue)',
85
71
  constantsRequired: '(required)',
86
72
  constantsRequiredCatalogue: '(required for catalogue)',
87
- constantsYamlPath: 'If you want to read params from the yaml file then enter the path to the file',
88
73
  constantsApiKey: 'An agent API key as provided by Contrast UI',
89
- constantsAuthorization: 'An agent Authorization credentials as provided by Contrast UI',
90
- constantsOrganizationId: 'The ID of your organization in Contrast UI',
74
+ constantsAuthorization: 'Authorization credentials as provided by Contrast UI',
75
+ constantsOrganizationId: 'The ID of your organization',
91
76
  constantsApplicationId: 'The ID of the application cataloged by Contrast UI',
92
77
  constantsHostId: 'Provide the name of the host and optionally the port expressed as "<host>:<port>".',
93
78
  constantsApplicationName: 'The name of the application cataloged by Contrast UI',
@@ -109,17 +94,22 @@ const en_locales = () => {
109
94
  failOptionErrorMessage: " FAIL - CVE's have been detected that match at least the cve_severity or cve_threshold option specified.",
110
95
  constantsSeverity: 'Combined with the --report command, allows the user to report libraries with vulnerabilities above a chosen severity level. For example, cve_severity medium only reports libraries with vulnerabilities at medium or higher severity. Values for level are high, medium or low.',
111
96
  constantsCount: "The number of CVE's that must be exceeded to fail a build",
112
- constantsHeader: 'Contrast CLI',
97
+ constantsHeader: 'CodeSec by Contrast Security',
113
98
  constantsPrerequisitesContentScanLanguages: 'Java & JavaScript supported',
114
- constantsContrastContent: 'Use the Contrast CLI, the fastest and most accurate code scan, to help find and eliminate security bugs in your code.',
99
+ constantsContrastContent: 'Use the Contrast CLI to run a scan (Java, JavaScript and .NET ) or lambda command (Java and Python) to find your vulnerabilities and start securing your code.',
115
100
  constantsUsageGuideContentRecommendation: 'Our recommendation is that this is invoked as part of a CI pipeline so that running the cli is automated as part of your build process.',
116
101
  constantsPrerequisitesHeader: 'Pre-requisites',
102
+ constantsAuthUsageHeader: 'Usage',
103
+ constantsAuthUsageContents: 'contrast auth',
104
+ constantsAuthHeaderContents: 'Authorize with external identity provider to perform scans on code',
105
+ configHeader: 'Config',
106
+ constantsConfigUsageContents: 'view / clear the configuration',
117
107
  constantsPrerequisitesContent: 'To scan a Java project you will need a .jar or .war file for analysis\n' +
118
108
  'To scan a Javascript project you will need a .js or.zip file for analysis\n' +
119
109
  'To scan a .NET c# webforms project you will need a .exe or a .zip file for analysis\n',
120
110
  constantsUsage: 'Usage',
121
111
  constantsUsageCommandExample: 'contrast [command] [options]',
122
- constantsUsageCommandInfo: 'The file argument is optional. If no file is given, Contrast will search for a .jar, .war, .js, .exe or .zip file in the working directory.\n',
112
+ constantsUsageCommandInfo: 'The file argument is optional. If no file is given, Contrast will search for a .jar, .war, .exe or .zip file in the working directory.\n',
123
113
  constantsUsageCommandInfo24Hours: 'Submitted files are encrypted during upload and deleted in 24 hours.',
124
114
  constantsAnd: 'AND',
125
115
  constantsJava: 'AND Maven build platform, including the dependency plugin. For a Gradle project, use build.gradle. A gradle-wrapper.properties file is also required. Kotlin is also supported requiring a build.gradle.kts file.',
@@ -160,17 +150,18 @@ const en_locales = () => {
160
150
  goReadProjectFile: 'Failed to read the project file @ "%s" because: "%s"',
161
151
  goAnalysisError: 'GO analysis failed because: ',
162
152
  goParseProjectFile: 'Failed to parse go mod graph output because: ',
163
- mavenNotInstalledError: " 'mvn' is not available. Please ensure you have Maven installed and available on your path.",
153
+ mavenNotInstalledError: "'mvn' is not available. Please ensure you have Maven installed and available on your path.",
164
154
  mavenDependencyTreeNonZero: 'Building maven dependancy tree failed with a non 0 exit code',
165
- gradleWrapperUnavailable: ' Gradle wrapper not found in root of project. Please ensure gradlew or gradlew.bat is in root of the project.',
155
+ gradleWrapperUnavailable: 'Gradle wrapper not found in root of project. Please ensure gradlew or gradlew.bat is in root of the project.',
166
156
  gradleDependencyTreeNonZero: "Building gradle dependancy tree failed with a non 0 exit code. \n Please check you have the correct version of Java installed to compile your project? \n If running against a muti module project ensure you are using the '--sub-project' flag",
167
- yamlPathCamelCaseError: ' Warning: The "yamlPath" parameter will be deprecated in a future release. Please look at our documentation for further guidance.',
168
- constantsSbom: ' Generate the Software Bill of Materials (SBOM) for the given application',
157
+ yamlPathCamelCaseError: 'Warning: The "yamlPath" parameter will be deprecated in a future release. Please look at our documentation for further guidance.',
158
+ constantsSbom: 'Generate the Software Bill of Materials (SBOM) for the given application',
169
159
  constantsMetadata: 'Define a set of key=value pairs (which conforms to RFC 2253) for specifying user-defined metadata associated with the application.',
170
160
  constantsTags: 'Apply labels to an application. Labels must be formatted as a comma-delimited list. Example - label1,label2,label3',
171
161
  constantsCode: 'Add the application code this application should use in the Contrast UI',
172
- constantsIgnoreCertErrors: ' For EOP users with a local Teamserver install, this will bypass the SSL certificate and recognise a self signed certificate.',
173
- constantsSave: ' Saves the Scan Results JSON to file.',
162
+ constantsIgnoreCertErrors: 'For EOP users with a local Teamserver install, this will bypass the SSL certificate and recognise a self signed certificate.',
163
+ constantsSave: 'Saves the Scan Results SARIF to file.',
164
+ scanLabel: "adds a label to the scan - defaults to 'Started by CLI tool at current date'",
174
165
  constantsIgnoreDev: 'Combined with the --report command excludes developer dependencies from the vulnerabilities report. By default all dependencies are included in a report.',
175
166
  constantsCommands: 'Commands',
176
167
  constantsScanOptions: 'Scan Options',
@@ -179,20 +170,22 @@ const en_locales = () => {
179
170
  ignoreDevDep: 'No private libraries that are not scoped detected',
180
171
  foundExistingProjectScan: 'Found existing project...',
181
172
  projectCreatedScan: 'Project created',
182
- uploadingScan: 'Uploading...',
173
+ uploadingScan: 'Uploading file to scan.',
183
174
  uploadingScanSuccessful: 'Uploaded file successfully.',
184
175
  uploadingScanFail: 'Unable to upload the file.',
185
176
  waitingTimedOut: 'Timed out.',
186
177
  responseMessage: 'Response: %s',
187
178
  searchingDirectoryScan: 'Searched 3 directory levels & found: ',
188
- noFileFoundScan: "We could't find a suitable file in your directories (we go 3 deep)",
179
+ noFileFoundScan: "We couldn't find a suitable file in your directories (we go 3 deep)",
189
180
  specifyFileScanError: 'Java Scan requires a .war or .jar file. Javascript Scan requires a .js or .zip file.\nTo start a Scan enter "contrast scan -f <path-to-file>"',
181
+ specifyFileAuditNotFound: 'No files found for library analysis',
190
182
  populateProjectIdMessage: 'project ID is %s',
191
183
  genericServiceError: 'returned with status code %s',
184
+ projectIdError: 'Your project ID is %s please check this is correct',
192
185
  permissionsError: 'You do not have the correct permissions here. \n Contact support@contrastsecurity.com to get this fixed.',
193
186
  scanErrorFileMessage: 'We only accept the following file types: \nJava - .jar, .war \nJavaScript - .js or .zip files',
194
187
  helpAuthSummary: 'Authenticate Contrast using your Github or Google account',
195
- helpScanSummary: 'Searches for a .jar, .war, .js or .zip file in the working directory, uploads for analysis and returns the results',
188
+ helpScanSummary: 'Perform static analysis on binaries / code artifacts',
196
189
  helpLambdaSummary: 'Perform scan on AWS Lambda functions',
197
190
  helpVersionSummary: 'Displays version of Contrast CLI',
198
191
  helpConfigSummary: 'Displays stored credentials',
@@ -203,10 +196,11 @@ const en_locales = () => {
203
196
  versionName: 'version',
204
197
  configName: 'config',
205
198
  helpName: 'help',
199
+ scanOptionsLanguageSummary: 'Valid values are JAVA, JAVASCRIPT and DOTNET',
206
200
  scanOptionsLanguageSummaryOptional: 'Language of file to send for analysis. ',
207
201
  scanOptionsLanguageSummaryRequired: 'If you scan a .zip file or you use the --file option.',
208
202
  scanOptionsTimeoutSummary: 'Time in seconds to wait for scan to complete. Default value is 300 seconds.',
209
- scanOptionsFileNameSummary: 'Path of the file you want to scan. If no file is specified, Contrast searches for a .jar, .war, .js, .exe or .zip file in the working directory.',
203
+ scanOptionsFileNameSummary: 'Path of the file you want to scan. If no file is specified, Contrast searches for a .jar, .war, .exe or .zip file in the working directory.',
210
204
  scanOptionsVerboseSummary: ' Returns extended information to the terminal.',
211
205
  authSuccessMessage: 'Authentication successful',
212
206
  runAuthSuccessMessage: "Now you can use Contrast CLI \nRun 'contrast scan' on your file \n" +
@@ -215,7 +209,7 @@ const en_locales = () => {
215
209
  authTimedOutMessage: 'Auth Timed out, try again',
216
210
  zipErrorScan: 'We only support zip files for JAVASCRIPT language, please set the flag --language JAVASCRIPT',
217
211
  unknownFileErrorScan: 'Unsupported file selected for Scan.',
218
- foundScanFile: 'found: %s',
212
+ foundScanFile: 'Found: %s',
219
213
  foundDetailedVulnerabilities: chalk.bold('%s Critical') +
220
214
  ' | ' +
221
215
  chalk.bold('%s High') +
@@ -223,14 +217,19 @@ const en_locales = () => {
223
217
  requiredParams: 'All required parameters are not present.',
224
218
  timeoutScan: 'Timeout set to 5 minutes.',
225
219
  searchingScanFileDirectory: 'Searching for file to scan from %s...',
220
+ searchingAuditFileDirectory: 'Searching for package manager files from %s...',
226
221
  scanHeader: 'Contrast Scan CLI',
227
- lambdaHeader: 'Contrast lambda help',
222
+ authHeader: 'Auth',
223
+ lambdaHeader: 'Contrast Lambda CLI',
228
224
  lambdaSummary: 'Performs static security scan on an AWS Lambda Function.\nProduces CVE (Vulnerable Dependencies) and Least Privilege violations/remediation results.',
229
225
  lambdaUsage: 'contrast lambda --function-name <function> [options]',
230
- lambdaPrerequisitesContent: 'contrast cli',
231
- scanFileNameOption: ' -f, --file',
232
- lambdaFunctionNameOption: ' -f, --function-name',
233
- lambdaListFunctionsOption: ' -l, --list-functions',
226
+ lambdaPrerequisitesContent: '',
227
+ lambdaPrerequisitesContentLambdaLanguages: 'Supported runtimes: Java & Python',
228
+ lambdaPrerequisitesContentLambdaDescriptionTitle: 'AWS Requirements\n',
229
+ lambdaPrerequisitesContentLambdaDescription: 'Make sure you have the AWS credentials configured on your local environment. \nYou need the following AWS permissions configured on your IAM user:\n - Lambda: GetFunction, GetLayerVersionֿ\n - IAM: GetRolePolicy, GetPolicy, GetPolicyVersion, ListRolePolicies, ListAttachedRolePolicies',
230
+ scanFileNameOption: '-f, --file',
231
+ lambdaFunctionNameOption: '-f, --function-name',
232
+ lambdaListFunctionsOption: '-l, --list-functions',
234
233
  lambdaEndpointOption: '-e, --endpoint-url',
235
234
  lambdaRegionOption: '-r, --region',
236
235
  lambdaProfileOption: '-p, --profile',
@@ -278,8 +277,19 @@ const en_locales = () => {
278
277
  auditOptionsIgnoreDevDependenciesDescription: 'ignores DevDependencies',
279
278
  auditOptionsSave: '-s, --save',
280
279
  auditOptionsSaveDescription: 'saves the output in specified format Txt text, sbom',
280
+ scanNotCompleted: 'Scan not completed. Check for framework and language support here: %s',
281
281
  scanNoVulnerabilitiesFound: '👏 No vulnerabilities found',
282
- scanNoFiletypeSpecifiedForSave: 'Please specify file type to save results to',
282
+ scanNoVulnerabilitiesFoundSecureCode: '👍 Your code looks secure.',
283
+ scanNoVulnerabilitiesFoundGoodWork: '👏 Keep up the good work.',
284
+ scanNoFiletypeSpecifiedForSave: 'Please specify file type to save results to, accepted value is SARIF',
285
+ auditSBOMSaveSuccess: '\n Software Bill of Materials (SBOM) saved successfully',
286
+ auditNoFiletypeSpecifiedForSave: `\n ${chalk.yellow.bold('No file type specified for --save option to save audit results to. Use audit --help to see valid --save options.')}`,
287
+ auditBadFiletypeSpecifiedForSave: `\n ${chalk.yellow.bold('Bad file type specified for --save option. Use audit --help to see valid --save options.')}`,
288
+ auditReportWaiting: 'Waiting for report...',
289
+ auditReportFail: 'Report Retrieval Failed, please try again',
290
+ auditReportSuccessMessage: 'Report successfully retrieved',
291
+ auditReportFailureMessage: 'Unable to generate library report',
292
+ auditSCAAnalysisBegins: 'Contrast SCA analysis begins',
283
293
  ...lambda
284
294
  };
285
295
  };
package/dist/constants.js CHANGED
@@ -17,6 +17,14 @@ const scanOptionDefinitions = [
17
17
  '}: ' +
18
18
  i18n.__('constantsProjectName')
19
19
  },
20
+ {
21
+ name: 'language',
22
+ alias: 'l',
23
+ description: '{bold ' +
24
+ i18n.__('constantsOptional') +
25
+ '}: ' +
26
+ i18n.__('scanOptionsLanguageSummary')
27
+ },
20
28
  {
21
29
  name: 'file',
22
30
  alias: 'f',
@@ -33,6 +41,14 @@ const scanOptionDefinitions = [
33
41
  '}: ' +
34
42
  i18n.__('constantsProjectId')
35
43
  },
44
+ {
45
+ name: 'project-path',
46
+ alias: 'i',
47
+ description: '{bold ' +
48
+ i18n.__('constantsOptional') +
49
+ '}: ' +
50
+ i18n.__('constantsProjectPath')
51
+ },
36
52
  {
37
53
  name: 'timeout',
38
54
  alias: 't',
@@ -66,7 +82,6 @@ const scanOptionDefinitions = [
66
82
  },
67
83
  {
68
84
  name: 'host',
69
- alias: 'h',
70
85
  description: '{bold ' +
71
86
  i18n.__('constantsRequired') +
72
87
  '}: ' +
@@ -109,14 +124,52 @@ const scanOptionDefinitions = [
109
124
  alias: 's',
110
125
  description: '{bold ' + i18n.__('constantsOptional') + '}:' + i18n.__('constantsSave')
111
126
  },
127
+ {
128
+ name: 'label',
129
+ description: '{bold ' + i18n.__('constantsOptional') + '}:' + i18n.__('scanLabel')
130
+ },
112
131
  {
113
132
  name: 'help',
133
+ alias: 'h',
114
134
  type: Boolean
115
135
  },
116
136
  {
117
137
  name: 'debug',
118
138
  alias: 'd',
119
139
  type: Boolean
140
+ },
141
+ {
142
+ name: 'experimental',
143
+ alias: 'e',
144
+ type: Boolean
145
+ },
146
+ {
147
+ name: 'application-name',
148
+ description: '{bold ' +
149
+ i18n.__('constantsOptional') +
150
+ '}: ' +
151
+ i18n.__('constantsApplicationName')
152
+ }
153
+ ];
154
+ const authOptionDefinitions = [
155
+ {
156
+ name: 'help',
157
+ alias: 'h',
158
+ type: Boolean
159
+ }
160
+ ];
161
+ const configOptionDefinitions = [
162
+ {
163
+ name: 'help',
164
+ alias: 'h',
165
+ type: Boolean,
166
+ description: 'Help text'
167
+ },
168
+ {
169
+ name: 'clear',
170
+ alias: 'c',
171
+ type: Boolean,
172
+ description: 'Clear the currently stored config'
120
173
  }
121
174
  ];
122
175
  const auditOptionDefinitions = [
@@ -257,6 +310,7 @@ const mainUsageGuide = commandLineUsage([
257
310
  header: i18n.__('constantsCommands'),
258
311
  content: [
259
312
  { name: i18n.__('authName'), summary: i18n.__('helpAuthSummary') },
313
+ { name: i18n.__('scanName'), summary: i18n.__('helpScanSummary') },
260
314
  { name: i18n.__('lambdaName'), summary: i18n.__('helpLambdaSummary') },
261
315
  { name: i18n.__('versionName'), summary: i18n.__('helpVersionSummary') },
262
316
  { name: i18n.__('configName'), summary: i18n.__('helpConfigSummary') },
@@ -264,7 +318,7 @@ const mainUsageGuide = commandLineUsage([
264
318
  ]
265
319
  },
266
320
  {
267
- content: '{underline https://www.contrastsecurity.com}'
321
+ content: '{underline https://developer.contrastsecurity.com/} \n For technical support head to {underline https://support.contrastsecurity.com}'
268
322
  }
269
323
  ]);
270
324
  const mainDefinition = [{ name: 'command', defaultOption: true }];
@@ -273,6 +327,8 @@ module.exports = {
273
327
  mainUsageGuide,
274
328
  mainDefinition,
275
329
  scanOptionDefinitions,
276
- auditOptionDefinitions
330
+ auditOptionDefinitions,
331
+ authOptionDefinitions,
332
+ configOptionDefinitions
277
333
  }
278
334
  };
package/dist/index.js CHANGED
@@ -12,7 +12,8 @@ const constants_1 = __importDefault(require("./constants"));
12
12
  const constants_2 = require("./constants/constants");
13
13
  const lambda_1 = require("./lambda/lambda");
14
14
  const getConfig_1 = require("./utils/getConfig");
15
- const findLatestCLIVersion_1 = __importDefault(require("./common/findLatestCLIVersion"));
15
+ const versionChecker_1 = require("./common/versionChecker");
16
+ const errorHandling_1 = require("./common/errorHandling");
16
17
  const { commandLineDefinitions: { mainUsageGuide, mainDefinition } } = constants_1.default;
17
18
  const config = (0, getConfig_1.localConfig)(constants_2.APP_NAME, constants_2.APP_VERSION);
18
19
  const getMainOption = () => {
@@ -28,37 +29,54 @@ const getMainOption = () => {
28
29
  };
29
30
  };
30
31
  const start = async () => {
31
- const { mainOptions, argv: argvMain } = getMainOption();
32
- const command = mainOptions.command != undefined ? mainOptions.command.toLowerCase() : '';
33
- if (command === 'version' ||
34
- argvMain.includes('--v') ||
35
- argvMain.includes('--version')) {
36
- console.log(constants_2.APP_VERSION);
37
- return;
38
- }
39
- await (0, findLatestCLIVersion_1.default)();
40
- if (command === 'config') {
41
- return (0, config_1.processConfig)(argvMain, config);
42
- }
43
- if (command === 'auth') {
44
- return await (0, auth_1.processAuth)(config);
45
- }
46
- if (command === 'lambda') {
47
- return await (0, lambda_1.processLambda)(argvMain);
48
- }
49
- if (command === 'scan') {
50
- return await (0, processScan_1.processScan)(argvMain);
51
- }
52
- if (command === 'audit') {
53
- return await (0, processAudit_1.processAudit)(argvMain);
54
- }
55
- if (command === 'help' ||
56
- argvMain.includes('--help') ||
57
- Object.keys(mainOptions).length === 0) {
58
- console.log(mainUsageGuide);
32
+ if (await (0, versionChecker_1.isCorrectNodeVersion)(process.version)) {
33
+ const { mainOptions, argv: argvMain } = getMainOption();
34
+ const command = mainOptions.command != undefined ? mainOptions.command.toLowerCase() : '';
35
+ if (command === 'version' ||
36
+ argvMain.includes('--v') ||
37
+ argvMain.includes('--version')) {
38
+ console.log(constants_2.APP_VERSION);
39
+ await (0, versionChecker_1.findLatestCLIVersion)(config.get('updateMessageHidden'));
40
+ return;
41
+ }
42
+ config.set('numOfRuns', config.get('numOfRuns') + 1);
43
+ if (config.get('numOfRuns') >= 5) {
44
+ await (0, versionChecker_1.findLatestCLIVersion)(config.get('updateMessageHidden'));
45
+ config.set('numOfRuns', 0);
46
+ }
47
+ if (command === 'config') {
48
+ return (0, config_1.processConfig)(argvMain, config);
49
+ }
50
+ if (command === 'auth') {
51
+ return await (0, auth_1.processAuth)(argvMain, config);
52
+ }
53
+ if (command === 'lambda') {
54
+ return await (0, lambda_1.processLambda)(argvMain);
55
+ }
56
+ if (command === 'scan') {
57
+ return await (0, processScan_1.processScan)(argvMain);
58
+ }
59
+ if (command === 'audit') {
60
+ return await (0, processAudit_1.processAudit)(argvMain);
61
+ }
62
+ if (command === 'help' ||
63
+ argvMain.includes('--help') ||
64
+ Object.keys(mainOptions).length === 0) {
65
+ console.log(mainUsageGuide);
66
+ }
67
+ else if (mainOptions._unknown !== undefined) {
68
+ const foundCommand = (0, errorHandling_1.findCommandOnError)(mainOptions._unknown);
69
+ foundCommand
70
+ ? console.log(`Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`)
71
+ : console.log(`Unknown Command: ${command} \nUse --help for the full list`);
72
+ }
73
+ else {
74
+ console.log(`Unknown Command: ${command} \nUse --help for the full list`);
75
+ }
76
+ process.exit(9);
59
77
  }
60
78
  else {
61
- console.log('Unknown Command: ' + command + ' \nUse --help for the full list');
79
+ console.log('Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.');
62
80
  process.exit(9);
63
81
  }
64
82
  };