@contrast/contrast 1.0.4 → 1.0.7

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 (115) hide show
  1. package/.prettierignore +0 -3
  2. package/dist/audit/autodetection/autoDetectLanguage.js +32 -0
  3. package/dist/audit/catalogueApplication/catalogueApplication.js +2 -11
  4. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +4 -2
  5. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +2 -1
  6. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +2 -1
  7. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +2 -1
  8. package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +6 -2
  9. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +39 -1
  10. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +69 -30
  11. package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +24 -0
  12. package/dist/audit/languageAnalysisEngine/report/models/reportSeverityModel.js +3 -1
  13. package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +13 -0
  14. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +2 -2
  15. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +56 -45
  16. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +65 -17
  17. package/dist/commands/audit/auditConfig.js +8 -2
  18. package/dist/commands/audit/auditController.js +9 -3
  19. package/dist/commands/audit/processAudit.js +1 -1
  20. package/dist/commands/scan/processScan.js +7 -4
  21. package/dist/commands/scan/sca/scaAnalysis.js +60 -0
  22. package/dist/common/HTTPClient.js +50 -16
  23. package/dist/common/errorHandling.js +11 -16
  24. package/dist/common/versionChecker.js +1 -1
  25. package/dist/constants/constants.js +24 -2
  26. package/dist/constants/locales.js +31 -36
  27. package/dist/constants.js +20 -0
  28. package/dist/lambda/analytics.js +11 -0
  29. package/dist/lambda/lambda.js +35 -4
  30. package/dist/lambda/types.js +13 -0
  31. package/dist/scaAnalysis/common/formatMessage.js +35 -0
  32. package/dist/scaAnalysis/common/treeUpload.js +29 -0
  33. package/dist/scaAnalysis/go/goAnalysis.js +17 -0
  34. package/dist/scaAnalysis/go/goParseDeps.js +158 -0
  35. package/dist/scaAnalysis/go/goReadDepFile.js +23 -0
  36. package/dist/scaAnalysis/java/analysis.js +105 -0
  37. package/dist/scaAnalysis/java/index.js +18 -0
  38. package/dist/scaAnalysis/java/javaBuildDepsParser.js +339 -0
  39. package/dist/scaAnalysis/python/analysis.js +41 -0
  40. package/dist/scaAnalysis/python/index.js +10 -0
  41. package/dist/scaAnalysis/ruby/analysis.js +226 -0
  42. package/dist/scaAnalysis/ruby/index.js +10 -0
  43. package/dist/scan/autoDetection.js +50 -1
  44. package/dist/scan/fileUtils.js +80 -1
  45. package/dist/scan/formatScanOutput.js +213 -0
  46. package/dist/scan/help.js +3 -1
  47. package/dist/scan/models/groupedResultsModel.js +2 -1
  48. package/dist/scan/models/scanResultsModel.js +3 -1
  49. package/dist/scan/populateProjectIdAndProjectName.js +2 -1
  50. package/dist/scan/scan.js +6 -99
  51. package/dist/scan/scanConfig.js +6 -1
  52. package/dist/scan/scanController.js +26 -7
  53. package/dist/scan/scanResults.js +20 -20
  54. package/dist/utils/commonApi.js +4 -1
  55. package/dist/utils/oraWrapper.js +5 -1
  56. package/package.json +12 -7
  57. package/src/audit/autodetection/autoDetectLanguage.ts +40 -0
  58. package/src/audit/catalogueApplication/catalogueApplication.js +3 -16
  59. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +11 -8
  60. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +2 -1
  61. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +2 -1
  62. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +2 -1
  63. package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +17 -5
  64. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +76 -3
  65. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +122 -40
  66. package/src/audit/languageAnalysisEngine/report/models/reportLibraryModel.ts +3 -3
  67. package/src/audit/languageAnalysisEngine/report/models/reportListModel.ts +15 -11
  68. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +29 -0
  69. package/src/audit/languageAnalysisEngine/report/models/reportSeverityModel.ts +12 -3
  70. package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +16 -0
  71. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +3 -3
  72. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +87 -65
  73. package/src/audit/languageAnalysisEngine/sendSnapshot.js +78 -25
  74. package/src/commands/audit/auditConfig.ts +12 -3
  75. package/src/commands/audit/auditController.ts +9 -3
  76. package/src/commands/audit/processAudit.ts +4 -1
  77. package/src/commands/scan/processScan.js +10 -4
  78. package/src/commands/scan/sca/scaAnalysis.js +83 -0
  79. package/src/common/HTTPClient.js +65 -25
  80. package/src/common/errorHandling.ts +14 -22
  81. package/src/common/versionChecker.ts +1 -1
  82. package/src/constants/constants.js +24 -2
  83. package/src/constants/locales.js +33 -50
  84. package/src/constants.js +22 -0
  85. package/src/lambda/analytics.ts +9 -0
  86. package/src/lambda/arn.ts +2 -1
  87. package/src/lambda/lambda.ts +37 -17
  88. package/src/lambda/types.ts +35 -0
  89. package/src/lambda/utils.ts +2 -7
  90. package/src/scaAnalysis/common/formatMessage.js +38 -0
  91. package/src/scaAnalysis/common/treeUpload.js +30 -0
  92. package/src/scaAnalysis/go/goAnalysis.js +19 -0
  93. package/src/scaAnalysis/go/goParseDeps.js +203 -0
  94. package/src/scaAnalysis/go/goReadDepFile.js +32 -0
  95. package/src/scaAnalysis/java/analysis.js +142 -0
  96. package/src/scaAnalysis/java/index.js +21 -0
  97. package/src/scaAnalysis/java/javaBuildDepsParser.js +404 -0
  98. package/src/scaAnalysis/python/analysis.js +48 -0
  99. package/src/scaAnalysis/python/index.js +11 -0
  100. package/src/scaAnalysis/ruby/analysis.js +282 -0
  101. package/src/scaAnalysis/ruby/index.js +11 -0
  102. package/src/scan/autoDetection.js +58 -1
  103. package/src/scan/fileUtils.js +99 -1
  104. package/src/scan/formatScanOutput.ts +249 -0
  105. package/src/scan/help.js +3 -1
  106. package/src/scan/models/groupedResultsModel.ts +7 -5
  107. package/src/scan/models/resultContentModel.ts +2 -2
  108. package/src/scan/models/scanResultsModel.ts +5 -2
  109. package/src/scan/populateProjectIdAndProjectName.js +3 -1
  110. package/src/scan/scan.ts +8 -136
  111. package/src/scan/scanConfig.js +5 -1
  112. package/src/scan/scanController.js +30 -10
  113. package/src/scan/scanResults.js +31 -18
  114. package/src/utils/commonApi.js +4 -1
  115. package/src/utils/oraWrapper.js +6 -1
@@ -8,14 +8,20 @@ const paramHandler_1 = __importDefault(require("../../utils/paramsUtil/paramHand
8
8
  const constants_1 = __importDefault(require("../../constants"));
9
9
  const parsedCLIOptions_1 = __importDefault(require("../../utils/parsedCLIOptions"));
10
10
  const constants_2 = __importDefault(require("../../audit/languageAnalysisEngine/constants"));
11
+ const autoDetectLanguage_1 = require("../../audit/autodetection/autoDetectLanguage");
11
12
  const { supportedLanguages: { NODE, JAVASCRIPT } } = constants_2.default;
12
13
  const getAuditConfig = (argv) => {
13
14
  const auditParameters = parsedCLIOptions_1.default.getCommandLineArgsCustom(argv, constants_1.default.commandLineDefinitions.auditOptionDefinitions);
14
15
  const paramsAuth = paramHandler_1.default.getAuth(auditParameters);
15
16
  if (auditParameters.language === undefined ||
16
17
  auditParameters.language === null) {
17
- console.log('error, --language parameter is required');
18
- process.exit(1);
18
+ try {
19
+ auditParameters.language = (0, autoDetectLanguage_1.determineProjectLanguage)((0, autoDetectLanguage_1.identifyLanguages)(auditParameters));
20
+ }
21
+ catch (err) {
22
+ console.log(err.message);
23
+ process.exit(1);
24
+ }
19
25
  }
20
26
  else if (auditParameters.language.toUpperCase() === JAVASCRIPT) {
21
27
  auditParameters.language = NODE.toLowerCase();
@@ -3,11 +3,12 @@ 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.startAudit = void 0;
6
+ exports.startAudit = exports.dealWithNoAppId = void 0;
7
7
  const catalogueApplication_1 = require("../../audit/catalogueApplication/catalogueApplication");
8
8
  const commonApi_1 = __importDefault(require("../../audit/languageAnalysisEngine/commonApi"));
9
9
  const identifyLanguageAE = require('./../../audit/languageAnalysisEngine');
10
10
  const languageFactory = require('../../audit/languageAnalysisEngine/languageAnalysisFactory');
11
+ const { v4: uuidv4 } = require('uuid');
11
12
  const dealWithNoAppId = async (config) => {
12
13
  let appID;
13
14
  try {
@@ -15,19 +16,24 @@ const dealWithNoAppId = async (config) => {
15
16
  if (!appID && config.applicationName) {
16
17
  return await (0, catalogueApplication_1.catalogueApplication)(config);
17
18
  }
19
+ if (!appID && !config.applicationName) {
20
+ config.applicationName = uuidv4();
21
+ return await (0, catalogueApplication_1.catalogueApplication)(config);
22
+ }
18
23
  }
19
24
  catch (e) {
20
25
  if (e.toString().includes('tunneling socket could not be established')) {
21
- console.log(e.message);
26
+ console.log(e.message.toString());
22
27
  console.log('There seems to be an issue with your proxy, please check and try again');
23
28
  }
24
29
  process.exit(1);
25
30
  }
26
31
  return appID;
27
32
  };
33
+ exports.dealWithNoAppId = dealWithNoAppId;
28
34
  const startAudit = async (config) => {
29
35
  if (!config.applicationId) {
30
- config.applicationId = await dealWithNoAppId(config);
36
+ config.applicationId = await (0, exports.dealWithNoAppId)(config);
31
37
  }
32
38
  identifyLanguageAE(config.projectPath, languageFactory, config.applicationId, config);
33
39
  };
@@ -7,7 +7,7 @@ const help_1 = require("./help");
7
7
  const processAudit = async (argv) => {
8
8
  if (argv.indexOf('--help') != -1) {
9
9
  printHelpMessage();
10
- process.exit(1);
10
+ process.exit(0);
11
11
  }
12
12
  const config = (0, auditConfig_1.getAuditConfig)(argv);
13
13
  const auditResults = await (0, auditController_1.startAudit)(config);
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
- const { startScan } = require('../../scan/scanController');
3
- const { scanUsageGuide } = require('../../scan/help');
4
2
  const scanConfig = require('../../scan/scanConfig');
3
+ const { startScan } = require('../../scan/scanController');
5
4
  const { saveScanFile } = require('../../utils/saveFile');
6
5
  const { ScanResultsModel } = require('../../scan/models/scanResultsModel');
7
- const { formatScanOutput } = require('../../scan/scan');
6
+ const { formatScanOutput } = require('../../scan/formatScanOutput');
7
+ const { processSca } = require('./sca/scaAnalysis');
8
8
  const processScan = async (argvMain) => {
9
9
  let config = scanConfig.getScanConfig(argvMain);
10
+ if (config.experimental) {
11
+ await processSca(config);
12
+ }
10
13
  let scanResults = new ScanResultsModel(await startScan(config));
11
- if (scanResults) {
14
+ if (scanResults.scanResultsInstances !== undefined) {
12
15
  formatScanOutput(scanResults);
13
16
  }
14
17
  if (config.save !== undefined) {
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ const autoDetection = require('../../../scan/autoDetection');
3
+ const javaAnalysis = require('../../../scaAnalysis/java');
4
+ const treeUpload = require('../../../scaAnalysis/common/treeUpload');
5
+ const { manualDetectAuditFilesAndLanguages } = require('../../../scan/autoDetection');
6
+ const auditController = require('../../audit/auditController');
7
+ const { supportedLanguages: { JAVA, GO, RUBY, PYTHON } } = require('../../../audit/languageAnalysisEngine/constants');
8
+ const goAnalysis = require('../../../scaAnalysis/go/goAnalysis');
9
+ const { rubyAnalysis } = require('../../../scaAnalysis/ruby');
10
+ const { pythonAnalysis } = require('../../../scaAnalysis/python');
11
+ const processSca = async (config) => {
12
+ let filesFound;
13
+ if (config.projectPath) {
14
+ filesFound = manualDetectAuditFilesAndLanguages(config.projectPath);
15
+ }
16
+ else {
17
+ filesFound = await autoDetection.autoDetectAuditFilesAndLanguages(config);
18
+ config.projectPath = process.cwd();
19
+ }
20
+ let messageToSend = undefined;
21
+ if (filesFound.length === 1) {
22
+ switch (Object.keys(filesFound[0])[0]) {
23
+ case JAVA:
24
+ messageToSend = javaAnalysis.javaAnalysis(config, filesFound[0]);
25
+ config.language = JAVA;
26
+ break;
27
+ case RUBY:
28
+ messageToSend = rubyAnalysis(config, filesFound[0]);
29
+ config.language = RUBY;
30
+ break;
31
+ case PYTHON:
32
+ messageToSend = pythonAnalysis(config, filesFound[0]);
33
+ config.language = PYTHON;
34
+ break;
35
+ case GO:
36
+ messageToSend = goAnalysis.goAnalysis(config, filesFound[0]);
37
+ config.language = GO;
38
+ break;
39
+ default:
40
+ console.log('language detected not supported');
41
+ return;
42
+ }
43
+ if (!config.applicationId) {
44
+ config.applicationId = await auditController.dealWithNoAppId(config);
45
+ }
46
+ console.log('processing dependencies');
47
+ const response = await treeUpload.commonSendSnapShot(messageToSend, config);
48
+ }
49
+ else {
50
+ if (filesFound.length === 0) {
51
+ console.log('no compatible dependency files detected. Continuing...');
52
+ }
53
+ else {
54
+ console.log('multiple language files detected, please use --project-path to specify a directory or the file where dependencies are declared');
55
+ }
56
+ }
57
+ };
58
+ module.exports = {
59
+ processSca
60
+ };
@@ -20,7 +20,8 @@ function HTTPClient(config) {
20
20
  Authorization: authToken,
21
21
  'API-Key': apiKey,
22
22
  SuperAuthorization: superAuthToken,
23
- 'Super-API-Key': superApiKey
23
+ 'Super-API-Key': superApiKey,
24
+ 'User-Agent': 'contrast-cli-v2'
24
25
  }
25
26
  };
26
27
  if (config.proxy) {
@@ -66,10 +67,24 @@ HTTPClient.prototype.getSpecificScanResult = function getSpecificScanResult(conf
66
67
  options.url = url;
67
68
  return requestUtils.sendRequest({ method: 'get', options });
68
69
  };
69
- HTTPClient.prototype.getSpecificScanResultSarif = function getSpecificScanResultSarif(config, scanId) {
70
+ HTTPClient.prototype.getSpecificScanResultSarif =
71
+ function getSpecificScanResultSarif(config, scanId) {
72
+ const options = _.cloneDeep(this.requestOptions);
73
+ options.url = createRawOutputURL(config, scanId);
74
+ return requestUtils.sendRequest({ method: 'get', options });
75
+ };
76
+ HTTPClient.prototype.createNewEvent = function createNewEvent(config, scanId, newProject) {
70
77
  const options = _.cloneDeep(this.requestOptions);
71
- options.url = createRawOutputURL(config, scanId);
72
- return requestUtils.sendRequest({ method: 'get', options });
78
+ options.url = createEventCollectorURL(config, scanId);
79
+ options.body = {
80
+ eventSource: process.env.CODESEC_INVOCATION_ENVIRONMENT,
81
+ trackingProperties: {
82
+ projectNameSource: config.projectNameSource,
83
+ waitedForResults: !config.ff,
84
+ newProject
85
+ }
86
+ };
87
+ return requestUtils.sendRequest({ method: 'post', options });
73
88
  };
74
89
  HTTPClient.prototype.getScanId = function getScanId(config, codeArtifactId) {
75
90
  const options = _.cloneDeep(this.requestOptions);
@@ -145,9 +160,6 @@ HTTPClient.prototype.catalogueCommand = function catalogueCommand(config) {
145
160
  return requestUtils.sendRequest({ method: 'post', options });
146
161
  };
147
162
  HTTPClient.prototype.sendSnapshot = function sendSnapshot(requestBody, config) {
148
- if (config.language.toUpperCase() === 'RUBY') {
149
- console.log('sendSnapshot requestBody', requestBody.snapshot.ruby);
150
- }
151
163
  const options = _.cloneDeep(this.requestOptions);
152
164
  let url = createSnapshotURL(config);
153
165
  options.url = url;
@@ -164,12 +176,18 @@ HTTPClient.prototype.getReportById = function getReportById(config, reportId) {
164
176
  }
165
177
  return requestUtils.sendRequest({ method: 'get', options });
166
178
  };
167
- HTTPClient.prototype.getLibraryVulnerabilities = function getLibraryVulnerabilities(config, requestBody) {
179
+ HTTPClient.prototype.getReportStatusById = function getReportStatusById(config, snapshotId) {
168
180
  const options = _.cloneDeep(this.requestOptions);
169
- options.url = createLibraryVulnerabilitiesUrl(config);
170
- options.body = requestBody;
171
- return requestUtils.sendRequest({ method: 'put', options });
181
+ options.url = createSpecificReportStatusURL(config, snapshotId);
182
+ return requestUtils.sendRequest({ method: 'get', options });
172
183
  };
184
+ HTTPClient.prototype.getLibraryVulnerabilities =
185
+ function getLibraryVulnerabilities(config, requestBody) {
186
+ const options = _.cloneDeep(this.requestOptions);
187
+ options.url = createLibraryVulnerabilitiesUrl(config);
188
+ options.body = requestBody;
189
+ return requestUtils.sendRequest({ method: 'put', options });
190
+ };
173
191
  HTTPClient.prototype.getAppId = function getAppId(config) {
174
192
  const options = _.cloneDeep(this.requestOptions);
175
193
  let url = createAppNameUrl(config);
@@ -211,11 +229,12 @@ HTTPClient.prototype.getScanResources = async function getScanResources(config,
211
229
  const options = { ...this.requestOptions, url };
212
230
  return requestUtils.sendRequest({ method: 'get', options });
213
231
  };
214
- HTTPClient.prototype.getFunctionScanResults = async function getFunctionScanResults(config, params, scanId, functionArn) {
215
- const url = createScanResultsGetUrl(config, params, scanId, functionArn);
216
- const options = { ...this.requestOptions, url };
217
- return requestUtils.sendRequest({ method: 'get', options });
218
- };
232
+ HTTPClient.prototype.getFunctionScanResults =
233
+ async function getFunctionScanResults(config, params, scanId, functionArn) {
234
+ const url = createScanResultsGetUrl(config, params, scanId, functionArn);
235
+ const options = { ...this.requestOptions, url };
236
+ return requestUtils.sendRequest({ method: 'get', options });
237
+ };
219
238
  HTTPClient.prototype.checkLibrary = function checkLibrary(data) {
220
239
  const options = _.cloneDeep(this.requestOptions);
221
240
  let url = createDataUrl();
@@ -228,6 +247,15 @@ HTTPClient.prototype.getSbom = function getSbom(config) {
228
247
  options.url = createSbomCycloneDXUrl(config);
229
248
  return requestUtils.sendRequest({ method: 'get', options });
230
249
  };
250
+ HTTPClient.prototype.postAnalyticsFunction = function (config, provider, body) {
251
+ const url = createAnalyticsFunctionPostUrl(config, provider);
252
+ const options = { ...this.requestOptions, body, url };
253
+ return requestUtils.sendRequest({ method: 'post', options });
254
+ };
255
+ const createAnalyticsFunctionPostUrl = (config, provider) => {
256
+ const url = getServerlessHost(config);
257
+ return `${url}/organizations/${config.organizationId}/providers/${provider}/analytics`;
258
+ };
231
259
  const createGetScanIdURL = config => {
232
260
  return `${config.host}/Contrast/api/sast/v1/organizations/${config.organizationId}/projects/${config.projectId}/scans/`;
233
261
  };
@@ -249,6 +277,9 @@ function createHarmonyProjectsUrl(config) {
249
277
  function createScanProjectUrl(config) {
250
278
  return `${config.host}/Contrast/api/sast/v1/organizations/${config.organizationId}/projects/${config.projectId}`;
251
279
  }
280
+ const createEventCollectorURL = (config, scanId) => {
281
+ return `${config.host}/Contrast/api/sast/organizations/${config.organizationId}/projects/${config.projectId}/scans/${scanId}/events`;
282
+ };
252
283
  const createGlobalPropertiesUrl = protocol => {
253
284
  return `${protocol}/Contrast/api/ng/global/properties`;
254
285
  };
@@ -273,6 +304,9 @@ function createSpecificReportUrl(config, reportId) {
273
304
  function createSpecificReportWithProdUrl(config, reportId) {
274
305
  return createSpecificReportUrl(config, reportId).concat(`?nodesToInclude=PROD`);
275
306
  }
307
+ function createSpecificReportStatusURL(config, reportId) {
308
+ return `${config.host}/Contrast/api/ng/sca/organizations/${config.organizationId}/applications/${config.applicationId}/snapshots/${reportId}/status`;
309
+ }
276
310
  function createDataUrl() {
277
311
  return `https://ardy.contrastsecurity.com/production`;
278
312
  }
@@ -3,7 +3,7 @@ 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.findCommandOnError = 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.maxAppError = 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
8
  const handleResponseErrors = (res, api) => {
9
9
  if (res.statusCode === 400) {
@@ -36,23 +36,17 @@ const libraryAnalysisError = () => {
36
36
  };
37
37
  exports.libraryAnalysisError = libraryAnalysisError;
38
38
  const snapshotFailureError = () => {
39
- console.log('\n ******************************** ' +
40
- i18n_1.default.__('snapshotFailureHeader') +
41
- ' *********************************\n' +
42
- i18n_1.default.__('snapshotFailureMessage'));
39
+ console.log(i18n_1.default.__('snapshotFailureMessage'));
43
40
  };
41
+ exports.snapshotFailureError = snapshotFailureError;
44
42
  const vulnerabilitiesFailureError = () => {
45
- console.log('\n ******************************** ' +
46
- i18n_1.default.__('snapshotFailureHeader') +
47
- ' *********************************\n' +
48
- i18n_1.default.__('vulnerabilitiesFailureMessage'));
43
+ console.log(i18n_1.default.__('vulnerabilitiesFailureMessage'));
49
44
  };
45
+ exports.vulnerabilitiesFailureError = vulnerabilitiesFailureError;
50
46
  const reportFailureError = () => {
51
- console.log('\n ******************************** ' +
52
- i18n_1.default.__('snapshotFailureHeader') +
53
- ' *********************************\n' +
54
- i18n_1.default.__('reportFailureMessage'));
47
+ console.log(i18n_1.default.__('auditReportFailureMessage'));
55
48
  };
49
+ exports.reportFailureError = reportFailureError;
56
50
  const genericError = (missingCliOption) => {
57
51
  console.log(`*************************** ${i18n_1.default.__('yamlMissingParametersHeader')} ***************************\n${missingCliOption}`);
58
52
  console.error(i18n_1.default.__('yamlMissingParametersMessage'));
@@ -78,10 +72,11 @@ const proxyError = () => {
78
72
  generalError('proxyErrorHeader', 'proxyErrorMessage');
79
73
  };
80
74
  exports.proxyError = proxyError;
81
- const hostWarningError = () => {
82
- console.log(i18n_1.default.__('snapshotHostMessage'));
75
+ const maxAppError = () => {
76
+ generalError('No applications remaining', 'You have reached the maximum number of application you can create.');
77
+ process.exit(1);
83
78
  };
84
- exports.hostWarningError = hostWarningError;
79
+ exports.maxAppError = maxAppError;
85
80
  const failOptionError = () => {
86
81
  console.log('\n ******************************** ' +
87
82
  i18n_1.default.__('snapshotFailureHeader') +
@@ -27,6 +27,6 @@ async function findLatestCLIVersion(updateMessageHidden) {
27
27
  }
28
28
  exports.findLatestCLIVersion = findLatestCLIVersion;
29
29
  async function isCorrectNodeVersion(currentVersion) {
30
- return semver_1.default.satisfies(currentVersion, '>=16.13.2 <17');
30
+ return semver_1.default.satisfies(currentVersion, '>=16');
31
31
  }
32
32
  exports.isCorrectNodeVersion = isCorrectNodeVersion;
@@ -12,11 +12,22 @@ 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.4';
15
+ const APP_VERSION = '1.0.7';
16
16
  const TIMEOUT = 120000;
17
+ const HIGH_COLOUR = '#ff9900';
18
+ const CRITICAL_COLOUR = '#e35858';
19
+ const MEDIUM_COLOUR = '#f1c232';
20
+ const LOW_COLOUR = '#b7b7b7';
21
+ const NOTE_COLOUR = '#999999';
22
+ const CRITICAL_PRIORITY = 1;
23
+ const HIGH_PRIORITY = 2;
24
+ const MEDIUM_PRIORITY = 3;
25
+ const LOW_PRIORITY = 4;
26
+ const NOTE_PRIORITY = 5;
17
27
  const AUTH_UI_URL = 'https://cli-auth.contrastsecurity.com';
18
28
  const AUTH_CALLBACK_URL = 'https://cli-auth-api.contrastsecurity.com';
19
29
  const SARIF_FILE = 'SARIF';
30
+ const CE_URL = 'https://ce.contrastsecurity.com/';
20
31
  module.exports = {
21
32
  supportedLanguages: { NODE, DOTNET, JAVA, RUBY, PYTHON, GO, PHP, JAVASCRIPT },
22
33
  LOW,
@@ -28,5 +39,16 @@ module.exports = {
28
39
  TIMEOUT,
29
40
  AUTH_UI_URL,
30
41
  AUTH_CALLBACK_URL,
31
- SARIF_FILE
42
+ SARIF_FILE,
43
+ HIGH_COLOUR,
44
+ CRITICAL_COLOUR,
45
+ MEDIUM_COLOUR,
46
+ LOW_COLOUR,
47
+ NOTE_COLOUR,
48
+ CE_URL,
49
+ CRITICAL_PRIORITY,
50
+ HIGH_PRIORITY,
51
+ MEDIUM_PRIORITY,
52
+ LOW_PRIORITY,
53
+ NOTE_PRIORITY
32
54
  };
@@ -4,41 +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.',
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',
13
13
  catchErrorMessage: 'Contrast UI error: ',
14
14
  dependenciesNote: 'Please Note: We currently only support projects with one .csproj AND *.package.lock.json',
15
- languageAnalysisFailureMessage: 'LANGUAGE ANALYSIS FAILED',
15
+ languageAnalysisFailureMessage: 'SCA Analysis Failure',
16
16
  languageAnalysisFactoryFailureHeader: 'FAIL',
17
- projectPathParameter: 'Please set the %s to locate the source code for the project',
18
- apiKeyParameter: 'Please set the %s to connect to the Contrast UI',
19
- applicationNameParameter: 'Please provide a value for %s, to appear in the Contrast UI',
20
- languageParameter: 'Please set the %s to the language of the source project. Allowable values are JAVA, DOTNET, NODE, PYTHON and RUBY.',
21
- hostParameter: 'Please set the %s to the hostname and (optionally) the port expressed as <host>:<port> of the Contrast UI',
22
- organizationIdParameter: 'Please set the %s to correctly identify your organization within the Contrast UI',
23
- authorizationParameter: 'Please set the %s to your authorization header, found in the Contrast UI',
24
- applicationIdParameter: 'Please set the %s to the value provided within the Contrast UI for the target application',
25
- 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',
26
18
  yamlMissingParametersHeader: 'Missing Parameters',
27
- 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',
28
20
  unauthenticatedErrorHeader: '401 error - Unauthenticated',
29
- 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',
30
22
  badRequestErrorHeader: '400 error - Bad Request',
31
- badRequestErrorMessage: 'Please check the following key is correct: \n--application_id',
23
+ badRequestErrorMessage: 'Please check the following key is correct: \n--application-id',
32
24
  badRequestCatalogueErrorMessage: 'The application name already exists, please use a unique name',
33
25
  forbiddenRequestErrorHeader: '403 error - Forbidden',
34
26
  forbiddenRequestErrorMessage: 'You do not have permission to access this server.',
35
27
  proxyErrorHeader: '407 error - Proxy Authentication Required',
36
28
  proxyErrorMessage: 'Please provide valid authentication credentials for the proxy server.',
37
- downgradeHttpsHttp: 'Connection to ContrastUI using https failed. Attempting to connect using http...',
38
- setSpecifiedParameter: 'Please set the %s ',
39
- catalogueFailureCommand: 'Failed to catalogue a new application for reason: ',
40
- catalogueFailureHostCommand: 'Failed to catalogue a new application, please ensure you have the correct host and authentication. Error: ',
41
- catalogueSuccessCommand: 'This application ID can now be used to send dependency data to Contrast: ',
29
+ catalogueSuccessCommand: 'Application Created',
42
30
  dotnetAnalysisFailure: '.NET analysis failed because: ',
43
31
  dotnetReadLockfile: 'Failed to read the lock file @ %s because: ',
44
32
  dotnetParseLockfile: "Failed to parse .NET lock file @ '%s' because: ",
@@ -82,10 +70,9 @@ const en_locales = () => {
82
70
  constantsOptionalForCatalogue: '(optional for catalogue)',
83
71
  constantsRequired: '(required)',
84
72
  constantsRequiredCatalogue: '(required for catalogue)',
85
- constantsYamlPath: 'If you want to read params from the yaml file then enter the path to the file',
86
73
  constantsApiKey: 'An agent API key as provided by Contrast UI',
87
- constantsAuthorization: 'An agent Authorization credentials as provided by Contrast UI',
88
- 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',
89
76
  constantsApplicationId: 'The ID of the application cataloged by Contrast UI',
90
77
  constantsHostId: 'Provide the name of the host and optionally the port expressed as "<host>:<port>".',
91
78
  constantsApplicationName: 'The name of the application cataloged by Contrast UI',
@@ -109,7 +96,7 @@ const en_locales = () => {
109
96
  constantsCount: "The number of CVE's that must be exceeded to fail a build",
110
97
  constantsHeader: 'CodeSec by Contrast Security',
111
98
  constantsPrerequisitesContentScanLanguages: 'Java & JavaScript supported',
112
- 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.',
99
+ constantsContrastContent: "Use the 'contrast' command for fast and accurate security analysis of your applications and APIs (Java, JavaScript and .NET ) as well as serverless functions (AWS lambda, Java and Python).",
113
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.',
114
101
  constantsPrerequisitesHeader: 'Pre-requisites',
115
102
  constantsAuthUsageHeader: 'Usage',
@@ -163,17 +150,17 @@ const en_locales = () => {
163
150
  goReadProjectFile: 'Failed to read the project file @ "%s" because: "%s"',
164
151
  goAnalysisError: 'GO analysis failed because: ',
165
152
  goParseProjectFile: 'Failed to parse go mod graph output because: ',
166
- 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.",
167
154
  mavenDependencyTreeNonZero: 'Building maven dependancy tree failed with a non 0 exit code',
168
- 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.',
169
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",
170
- yamlPathCamelCaseError: ' Warning: The "yamlPath" parameter will be deprecated in a future release. Please look at our documentation for further guidance.',
171
- 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',
172
159
  constantsMetadata: 'Define a set of key=value pairs (which conforms to RFC 2253) for specifying user-defined metadata associated with the application.',
173
160
  constantsTags: 'Apply labels to an application. Labels must be formatted as a comma-delimited list. Example - label1,label2,label3',
174
161
  constantsCode: 'Add the application code this application should use in the Contrast UI',
175
- constantsIgnoreCertErrors: ' For EOP users with a local Teamserver install, this will bypass the SSL certificate and recognise a self signed certificate.',
176
- constantsSave: ' Saves the Scan Results SARIF 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.',
177
164
  scanLabel: "adds a label to the scan - defaults to 'Started by CLI tool at current date'",
178
165
  constantsIgnoreDev: 'Combined with the --report command excludes developer dependencies from the vulnerabilities report. By default all dependencies are included in a report.',
179
166
  constantsCommands: 'Commands',
@@ -189,8 +176,9 @@ const en_locales = () => {
189
176
  waitingTimedOut: 'Timed out.',
190
177
  responseMessage: 'Response: %s',
191
178
  searchingDirectoryScan: 'Searched 3 directory levels & found: ',
192
- 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)",
193
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',
194
182
  populateProjectIdMessage: 'project ID is %s',
195
183
  genericServiceError: 'returned with status code %s',
196
184
  projectIdError: 'Your project ID is %s please check this is correct',
@@ -229,6 +217,7 @@ const en_locales = () => {
229
217
  requiredParams: 'All required parameters are not present.',
230
218
  timeoutScan: 'Timeout set to 5 minutes.',
231
219
  searchingScanFileDirectory: 'Searching for file to scan from %s...',
220
+ searchingAuditFileDirectory: 'Searching for package manager files from %s...',
232
221
  scanHeader: 'Contrast Scan CLI',
233
222
  authHeader: 'Auth',
234
223
  lambdaHeader: 'Contrast Lambda CLI',
@@ -258,6 +247,7 @@ const en_locales = () => {
258
247
  redirectAuth: '\nOpening the authentication page in your web browser.\nSign in and complete the steps.\nReturn here to start using Contrast.\n\nIf your browser has trouble loading, try this:\n%s \n',
259
248
  scanZipError: 'A .zip archive can be used for Javascript Scan. Archive found %s does not contain .JS files for Scan.',
260
249
  fileNotExist: 'File specified does not exist, please check and try again.',
250
+ scanFileIsEmpty: 'File specified is empty. Please choose another.',
261
251
  fileHasWhiteSpacesError: 'File cannot have spaces, please rename or choose another file to Scan.',
262
252
  zipFileException: 'Error reading zip file',
263
253
  connectionError: 'An error has occurred when trying to get the Project Id please check your internet connection or provide the Project Id manually',
@@ -288,15 +278,20 @@ const en_locales = () => {
288
278
  auditOptionsIgnoreDevDependenciesDescription: 'ignores DevDependencies',
289
279
  auditOptionsSave: '-s, --save',
290
280
  auditOptionsSaveDescription: 'saves the output in specified format Txt text, sbom',
281
+ scanNotCompleted: 'Scan not completed. Check for framework and language support here: %s',
282
+ auditNotCompleted: 'audit not completed. Please try again',
291
283
  scanNoVulnerabilitiesFound: '👏 No vulnerabilities found',
284
+ scanNoVulnerabilitiesFoundSecureCode: '👍 Your code looks secure.',
285
+ scanNoVulnerabilitiesFoundGoodWork: '👏 Keep up the good work.',
292
286
  scanNoFiletypeSpecifiedForSave: 'Please specify file type to save results to, accepted value is SARIF',
293
287
  auditSBOMSaveSuccess: '\n Software Bill of Materials (SBOM) saved successfully',
294
288
  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.')}`,
295
289
  auditBadFiletypeSpecifiedForSave: `\n ${chalk.yellow.bold('Bad file type specified for --save option. Use audit --help to see valid --save options.')}`,
296
290
  auditReportWaiting: 'Waiting for report...',
297
291
  auditReportFail: 'Report Retrieval Failed, please try again',
298
- auditReportSuccessMessage: ' Report successfully retrieved',
299
- auditReportFailureMessage: ' Unable to generate library report.',
292
+ auditReportSuccessMessage: 'Report successfully retrieved',
293
+ auditReportFailureMessage: 'Unable to generate library report',
294
+ auditSCAAnalysisBegins: 'Contrast SCA analysis begins',
300
295
  ...lambda
301
296
  };
302
297
  };
package/dist/constants.js CHANGED
@@ -41,6 +41,14 @@ const scanOptionDefinitions = [
41
41
  '}: ' +
42
42
  i18n.__('constantsProjectId')
43
43
  },
44
+ {
45
+ name: 'project-path',
46
+ alias: 'i',
47
+ description: '{bold ' +
48
+ i18n.__('constantsOptional') +
49
+ '}: ' +
50
+ i18n.__('constantsProjectPath')
51
+ },
44
52
  {
45
53
  name: 'timeout',
46
54
  alias: 't',
@@ -129,6 +137,18 @@ const scanOptionDefinitions = [
129
137
  name: 'debug',
130
138
  alias: 'd',
131
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')
132
152
  }
133
153
  ];
134
154
  const authOptionDefinitions = [
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postAnalytics = void 0;
4
+ const commonApi_1 = require("../utils/commonApi");
5
+ const paramHandler_1 = require("../utils/paramsUtil/paramHandler");
6
+ const postAnalytics = (data, provider = 'aws') => {
7
+ const config = (0, paramHandler_1.getAuth)();
8
+ const client = (0, commonApi_1.getHttpClient)(config);
9
+ return client.postAnalyticsFunction(config, provider, data);
10
+ };
11
+ exports.postAnalytics = postAnalytics;