@contrast/contrast 1.0.0 → 1.0.3

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 (213) hide show
  1. package/.prettierignore +3 -0
  2. package/README.md +115 -78
  3. package/dist/audit/AnalysisEngine.js +37 -0
  4. package/dist/audit/catalogueApplication/catalogueApplication.js +36 -0
  5. package/dist/audit/dotnetAnalysisEngine/index.js +25 -0
  6. package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +35 -0
  7. package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +15 -0
  8. package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +18 -0
  9. package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +14 -0
  10. package/dist/audit/dotnetAnalysisEngine/sanitizer.js +9 -0
  11. package/dist/audit/goAnalysisEngine/index.js +17 -0
  12. package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +164 -0
  13. package/dist/audit/goAnalysisEngine/readProjectFileContents.js +21 -0
  14. package/dist/audit/goAnalysisEngine/sanitizer.js +5 -0
  15. package/dist/audit/javaAnalysisEngine/index.js +34 -0
  16. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +153 -0
  17. package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +353 -0
  18. package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +98 -0
  19. package/dist/audit/javaAnalysisEngine/sanitizer.js +5 -0
  20. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +24 -0
  21. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +24 -0
  22. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +35 -0
  23. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +23 -0
  24. package/dist/audit/languageAnalysisEngine/commonApi.js +18 -0
  25. package/dist/audit/languageAnalysisEngine/constants.js +20 -0
  26. package/dist/audit/languageAnalysisEngine/filterProjectPath.js +20 -0
  27. package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +25 -0
  28. package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +39 -0
  29. package/dist/audit/languageAnalysisEngine/index.js +39 -0
  30. package/dist/audit/languageAnalysisEngine/langugageAnalysisFactory.js +95 -0
  31. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +121 -0
  32. package/dist/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +17 -0
  33. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +257 -0
  34. package/dist/audit/languageAnalysisEngine/report/newReportingFeature.js +81 -0
  35. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +133 -0
  36. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +41 -0
  37. package/dist/audit/languageAnalysisEngine/util/capabilities.js +11 -0
  38. package/dist/audit/languageAnalysisEngine/util/generalAPI.js +39 -0
  39. package/dist/audit/languageAnalysisEngine/util/requestUtils.js +14 -0
  40. package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +40 -0
  41. package/dist/audit/nodeAnalysisEngine/index.js +31 -0
  42. package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +18 -0
  43. package/dist/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +51 -0
  44. package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +18 -0
  45. package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +17 -0
  46. package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +14 -0
  47. package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +24 -0
  48. package/dist/audit/nodeAnalysisEngine/sanitizer.js +9 -0
  49. package/dist/audit/phpAnalysisEngine/index.js +23 -0
  50. package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +52 -0
  51. package/dist/audit/phpAnalysisEngine/readLockFileContents.js +13 -0
  52. package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +16 -0
  53. package/dist/audit/phpAnalysisEngine/sanitizer.js +5 -0
  54. package/dist/audit/pythonAnalysisEngine/index.js +25 -0
  55. package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +17 -0
  56. package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +21 -0
  57. package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +13 -0
  58. package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +14 -0
  59. package/dist/audit/pythonAnalysisEngine/sanitizer.js +7 -0
  60. package/dist/audit/rubyAnalysisEngine/index.js +25 -0
  61. package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +176 -0
  62. package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +22 -0
  63. package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +14 -0
  64. package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +14 -0
  65. package/dist/audit/rubyAnalysisEngine/sanitizer.js +6 -0
  66. package/dist/commands/audit/auditConfig.js +25 -0
  67. package/dist/commands/audit/auditController.js +31 -0
  68. package/dist/commands/audit/help.js +52 -0
  69. package/dist/commands/audit/processAudit.js +18 -0
  70. package/dist/commands/audit/saveFile.js +11 -0
  71. package/dist/commands/auth/auth.js +20 -2
  72. package/dist/commands/config/config.js +19 -8
  73. package/dist/commands/scan/processScan.js +9 -13
  74. package/dist/common/HTTPClient.js +112 -13
  75. package/dist/common/errorHandling.js +65 -1
  76. package/dist/common/versionChecker.js +30 -0
  77. package/dist/constants/constants.js +4 -2
  78. package/dist/constants/lambda.js +32 -4
  79. package/dist/constants/locales.js +60 -21
  80. package/dist/constants.js +181 -21
  81. package/dist/index.js +50 -23
  82. package/dist/lambda/aws.js +14 -11
  83. package/dist/lambda/help.js +4 -0
  84. package/dist/lambda/lambda.js +50 -27
  85. package/dist/lambda/lambdaUtils.js +72 -0
  86. package/dist/lambda/logUtils.js +11 -1
  87. package/dist/lambda/scanDetailCompletion.js +4 -4
  88. package/dist/lambda/scanRequest.js +11 -5
  89. package/dist/lambda/utils.js +110 -53
  90. package/dist/sbom/generateSbom.js +20 -0
  91. package/dist/scan/autoDetection.js +0 -32
  92. package/dist/scan/fileUtils.js +1 -1
  93. package/dist/scan/help.js +14 -40
  94. package/dist/scan/populateProjectIdAndProjectName.js +5 -0
  95. package/dist/scan/saveResults.js +14 -0
  96. package/dist/scan/scan.js +105 -40
  97. package/dist/scan/scanConfig.js +39 -0
  98. package/dist/scan/scanController.js +19 -16
  99. package/dist/scan/scanResults.js +24 -16
  100. package/dist/utils/commonApi.js +3 -3
  101. package/dist/utils/paramsUtil/commandlineParams.js +1 -20
  102. package/dist/utils/paramsUtil/paramHandler.js +3 -6
  103. package/dist/utils/parsedCLIOptions.js +14 -8
  104. package/dist/utils/requestUtils.js +1 -1
  105. package/dist/utils/saveFile.js +19 -0
  106. package/package.json +26 -21
  107. package/src/audit/AnalysisEngine.js +103 -0
  108. package/src/audit/catalogueApplication/catalogueApplication.js +42 -0
  109. package/src/audit/dotnetAnalysisEngine/index.js +26 -0
  110. package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +47 -0
  111. package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +29 -0
  112. package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +30 -0
  113. package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +26 -0
  114. package/src/audit/dotnetAnalysisEngine/sanitizer.js +11 -0
  115. package/src/audit/goAnalysisEngine/index.js +18 -0
  116. package/src/audit/goAnalysisEngine/parseProjectFileContents.js +209 -0
  117. package/src/audit/goAnalysisEngine/readProjectFileContents.js +31 -0
  118. package/src/audit/goAnalysisEngine/sanitizer.js +7 -0
  119. package/src/audit/javaAnalysisEngine/index.js +41 -0
  120. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +222 -0
  121. package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +420 -0
  122. package/src/audit/javaAnalysisEngine/readProjectFileContents.js +141 -0
  123. package/src/audit/javaAnalysisEngine/sanitizer.js +6 -0
  124. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +35 -0
  125. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +41 -0
  126. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +54 -0
  127. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +32 -0
  128. package/src/audit/languageAnalysisEngine/commonApi.js +20 -0
  129. package/src/audit/languageAnalysisEngine/constants.js +23 -0
  130. package/src/audit/languageAnalysisEngine/filterProjectPath.js +21 -0
  131. package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +41 -0
  132. package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +72 -0
  133. package/src/audit/languageAnalysisEngine/index.js +45 -0
  134. package/src/audit/languageAnalysisEngine/langugageAnalysisFactory.js +126 -0
  135. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +177 -0
  136. package/src/audit/languageAnalysisEngine/report/checkIgnoreDevDep.js +27 -0
  137. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.js +303 -0
  138. package/src/audit/languageAnalysisEngine/report/newReportingFeature.js +124 -0
  139. package/src/audit/languageAnalysisEngine/report/reportingFeature.js +190 -0
  140. package/src/audit/languageAnalysisEngine/sendSnapshot.js +51 -0
  141. package/src/audit/languageAnalysisEngine/util/capabilities.js +12 -0
  142. package/src/audit/languageAnalysisEngine/util/generalAPI.js +43 -0
  143. package/src/audit/languageAnalysisEngine/util/requestUtils.js +17 -0
  144. package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +49 -0
  145. package/src/audit/nodeAnalysisEngine/index.js +35 -0
  146. package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +20 -0
  147. package/src/audit/nodeAnalysisEngine/parseYarn2LockFileContents.js +63 -0
  148. package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +26 -0
  149. package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +23 -0
  150. package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +27 -0
  151. package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +36 -0
  152. package/src/audit/nodeAnalysisEngine/sanitizer.js +11 -0
  153. package/src/audit/phpAnalysisEngine/index.js +27 -0
  154. package/src/audit/phpAnalysisEngine/parseLockFileContents.js +60 -0
  155. package/src/audit/phpAnalysisEngine/readLockFileContents.js +14 -0
  156. package/src/audit/phpAnalysisEngine/readProjectFileContents.js +25 -0
  157. package/src/audit/phpAnalysisEngine/sanitizer.js +4 -0
  158. package/src/audit/pythonAnalysisEngine/index.js +55 -0
  159. package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +23 -0
  160. package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +33 -0
  161. package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +16 -0
  162. package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +22 -0
  163. package/src/audit/pythonAnalysisEngine/sanitizer.js +9 -0
  164. package/src/audit/rubyAnalysisEngine/index.js +30 -0
  165. package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +215 -0
  166. package/src/audit/rubyAnalysisEngine/parsedGemfile.js +39 -0
  167. package/src/audit/rubyAnalysisEngine/readGemfileContents.js +18 -0
  168. package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +17 -0
  169. package/src/audit/rubyAnalysisEngine/sanitizer.js +8 -0
  170. package/src/commands/audit/auditConfig.ts +30 -0
  171. package/src/commands/audit/auditController.ts +31 -0
  172. package/src/commands/audit/help.ts +48 -0
  173. package/src/commands/audit/processAudit.ts +18 -0
  174. package/src/commands/audit/saveFile.ts +6 -0
  175. package/src/commands/auth/auth.js +26 -2
  176. package/src/commands/config/config.js +22 -8
  177. package/src/commands/scan/processScan.js +9 -13
  178. package/src/common/HTTPClient.js +149 -14
  179. package/src/common/errorHandling.ts +85 -2
  180. package/src/common/versionChecker.ts +39 -0
  181. package/src/constants/constants.js +5 -4
  182. package/src/constants/lambda.js +45 -4
  183. package/src/constants/locales.js +76 -26
  184. package/src/constants.js +204 -23
  185. package/src/index.ts +67 -27
  186. package/src/lambda/aws.ts +13 -12
  187. package/src/lambda/help.ts +4 -0
  188. package/src/lambda/lambda.ts +53 -34
  189. package/src/lambda/lambdaUtils.ts +111 -0
  190. package/src/lambda/logUtils.ts +19 -1
  191. package/src/lambda/scanDetailCompletion.ts +4 -4
  192. package/src/lambda/scanRequest.ts +13 -11
  193. package/src/lambda/utils.ts +149 -81
  194. package/src/sbom/generateSbom.ts +17 -0
  195. package/src/scan/autoDetection.js +0 -29
  196. package/src/scan/fileUtils.js +1 -1
  197. package/src/scan/help.js +14 -45
  198. package/src/scan/populateProjectIdAndProjectName.js +5 -0
  199. package/src/scan/saveResults.js +14 -0
  200. package/src/scan/scan.js +127 -58
  201. package/src/scan/scanConfig.js +54 -0
  202. package/src/scan/scanController.js +22 -15
  203. package/src/scan/scanResults.js +32 -19
  204. package/src/utils/commonApi.js +2 -3
  205. package/src/utils/getConfig.ts +2 -0
  206. package/src/utils/paramsUtil/commandlineParams.js +1 -26
  207. package/src/utils/paramsUtil/paramHandler.js +3 -7
  208. package/src/utils/parsedCLIOptions.js +11 -9
  209. package/src/utils/requestUtils.js +1 -1
  210. package/src/utils/saveFile.js +19 -0
  211. package/dist/lambda/scanDetail.js +0 -30
  212. package/dist/scan/fileFinder.js +0 -15
  213. package/dist/utils/paramsUtil/yamlParams.js +0 -6
@@ -9,11 +9,52 @@ const lambda = {
9
9
  'Required parameter --function-name is missing.\nRun command with --help to see usage',
10
10
  failedToGetResults: 'Failed to get results',
11
11
  missingResults: 'Missing vulnerabilities',
12
- missingParameter: 'Required function parameter is missing', // should use it again
13
12
  awsError: 'AWS error',
14
- missingFlagArguments: 'The following flags are missing an arguments:\n%s',
13
+ missingFlagArguments:
14
+ 'The following flags are missing an arguments:\n{{flags}}',
15
15
  notSupportedFlags:
16
- 'The following flags are not supported:\n%s\nRun command with --help to see usage',
16
+ 'The following flags are not supported:\n{{flags}}\nRun command with --help to see usage',
17
+ layerNotFound:
18
+ 'The layer {{layerArn}} could not be found. The scan will continue without it',
19
+
20
+ // ====== general ===== //
21
+ noVulnerabilitiesFound: '👏 No vulnerabilities found',
22
+ scanCompleted: '----- Scan completed {{time}}s -----',
23
+ sendingScanRequest:
24
+ '{{icon}} Sending Lambda Function scan request to Contrast',
25
+ scanRequestedSuccessfully: '{{icon}} Scan requested successfully',
26
+ fetchingConfiguration:
27
+ '{{icon}} Fetching configuration and policies for Lambda Function {{functionName}}',
28
+ fetchedConfiguration: '{{icon}} Fetched configuration from AWS',
29
+
30
+ // ====== scan polling ===== //
31
+ scanStarted: 'Scan Started',
32
+ scanFailed: 'Scan Failed',
33
+ scanTimedOut: 'Scan timed out',
34
+
35
+ // ====== lambda utils ===== //
36
+ loadingFunctionList: 'Loading lambda function list',
37
+ functionsFound: '{{count}} functions found',
38
+ noFunctionsFound: 'No functions found',
39
+ failedToLoadFunctions: 'Faled to load lambda functions',
40
+ availableForScan: '{{icon}} {{count}} available for scan',
41
+ runtimeCount: '----- {{runtime}} ({{count}}) -----',
42
+
43
+ // ====== print vulnerabilities ===== //
44
+ whatHappenedTitle: 'What happened:',
45
+ whatHappenedItem: '{{policy}} have:\n{{comments}}\n',
46
+ recommendation: 'Recommendation:',
47
+ vulnerableDependency: 'Vulnerable dependency',
48
+ dependenciesCount: {
49
+ one: '1 Dependency',
50
+ other: '%s Dependencies'
51
+ },
52
+ foundVulnerabilities: {
53
+ one: 'Found 1 vulnerability',
54
+ other: 'Found %s vulnerabilities'
55
+ },
56
+ vulnerableDependencyDescriptions:
57
+ '{packageName} (v{version}) has {NUM} known {NUM, plural,one{CVE}other{CVEs}}\n {cves}',
17
58
 
18
59
  // ====== errorCodes ===== //
19
60
  something_went_wrong: 'Something went wrong',
@@ -22,7 +63,7 @@ const lambda = {
22
63
  inactive_account:
23
64
  'Scanning a function of an inactive account is not supported',
24
65
  not_supported_runtime:
25
- 'Scanning resource of runtime "%s" is not supported.\nSupported runtimes: %s',
66
+ 'Scanning resource of runtime "{{runtime}}" is not supported.\nSupported runtimes: {{supportedRuntimes}}',
26
67
  not_supported_onboard_account:
27
68
  'Scanning a function of onboard account is not supported',
28
69
  scan_lock:
@@ -1,4 +1,5 @@
1
1
  const { lambda } = require('./lambda')
2
+ const chalk = require('chalk')
2
3
 
3
4
  const en_locales = () => {
4
5
  return {
@@ -159,12 +160,10 @@ const en_locales = () => {
159
160
  'Specify the sub project within your gradle application.',
160
161
  constantsScan: 'Upload java binaries to the static scan service',
161
162
  constantsWaitForScan: 'Waits for the result of the scan',
162
- constantsProjectName: 'The name of the scan project in Contrast',
163
- constantsFileName: 'The name of the file to Scan',
163
+ constantsProjectName:
164
+ 'Contrast project name. If not specified, Contrast uses contrast.settings to identify the project or creates a project.',
164
165
  constantsProjectId:
165
166
  'The ID associated with a scan project. Replace <ProjectID> with the ID for the scan project. To find the ID, select a scan project in Contrast and locate the last number in the URL.',
166
- constantsScanTimeout:
167
- 'Set a specific time span before the function times out. Default timeout is 300 seconds if scan_timeout is not set. The format of the value of the parameter is "20" seconds or "80" seconds.',
168
167
  constantsReport: 'Display vulnerability information for this application',
169
168
  constantsFail:
170
169
  'Set the process to fail if this option is set in combination with the --report and --cve_severity.',
@@ -173,27 +172,34 @@ const en_locales = () => {
173
172
  constantsSeverity:
174
173
  '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.',
175
174
  constantsCount: "The number of CVE's that must be exceeded to fail a build",
176
- constantsHeader: 'Contrast CLI',
175
+ constantsHeader: 'CodeSec by Contrast Security',
177
176
  constantsPrerequisitesContentScanLanguages: 'Java & JavaScript supported',
178
177
  constantsContrastContent:
179
- 'Use the Contrast CLI, the fastest and most accurate code scan, to help find and eliminate security bugs in your code.',
178
+ '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.',
180
179
  constantsUsageGuideContentRecommendation:
181
180
  '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.',
182
181
  constantsPrerequisitesHeader: 'Pre-requisites',
182
+ constantsAuthUsageHeader: 'Usage',
183
+ constantsAuthUsageContents: 'contrast auth',
184
+ constantsAuthHeaderContents:
185
+ 'Authorize with external identity provider to perform scans on code',
186
+ configHeader: 'Config',
187
+ constantsConfigUsageContents: 'view / clear the configuration',
183
188
  constantsPrerequisitesContent:
184
189
  'To scan a Java project you will need a .jar or .war file for analysis\n' +
185
- 'To scan a Javascript project you will need a .js or.zip file for analysis\n',
190
+ 'To scan a Javascript project you will need a .js or.zip file for analysis\n' +
191
+ 'To scan a .NET c# webforms project you will need a .exe or a .zip file for analysis\n',
186
192
  constantsUsage: 'Usage',
187
193
  constantsUsageCommandExample: 'contrast [command] [options]',
188
194
  constantsUsageCommandInfo:
189
- 'The file argument is optional. If no file is given, Contrast will search for a .jar, .war, .js or .zip file in the working directory.\n',
195
+ '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',
190
196
  constantsUsageCommandInfo24Hours:
191
197
  'Submitted files are encrypted during upload and deleted in 24 hours.',
192
198
  constantsAnd: 'AND',
193
199
  constantsJava:
194
200
  '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.',
195
201
  constantsJavaNote:
196
- '*Please Note: Running "mvn dependency:tree" or "./gradlew dependencies" in the project directory locally must be successful.',
202
+ 'Note: Running "mvn dependency:tree" or "./gradlew dependencies" in the project directory locally must be successful.',
197
203
  constantsJavaNoteGradle:
198
204
  'We currently support v4.8 and upwards on Gradle projects',
199
205
  constantsDotNet:
@@ -268,6 +274,7 @@ const en_locales = () => {
268
274
  'Add the application code this application should use in the Contrast UI',
269
275
  constantsIgnoreCertErrors:
270
276
  ' For EOP users with a local Teamserver install, this will bypass the SSL certificate and recognise a self signed certificate.',
277
+ constantsSave: ' Saves the Scan Results JSON to file.',
271
278
  constantsIgnoreDev:
272
279
  'Combined with the --report command excludes developer dependencies from the vulnerabilities report. By default all dependencies are included in a report.',
273
280
  constantsCommands: 'Commands',
@@ -288,12 +295,14 @@ const en_locales = () => {
288
295
  specifyFileScanError:
289
296
  '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>"',
290
297
  populateProjectIdMessage: 'project ID is %s',
298
+ genericServiceError: 'returned with status code %s',
299
+ permissionsError:
300
+ 'You do not have the correct permissions here. \n Contact support@contrastsecurity.com to get this fixed.',
291
301
  scanErrorFileMessage:
292
302
  'We only accept the following file types: \nJava - .jar, .war \nJavaScript - .js or .zip files',
293
303
  helpAuthSummary:
294
304
  'Authenticate Contrast using your Github or Google account',
295
- helpScanSummary:
296
- 'Searches for a .jar, .war, .js or .zip file in the working directory, uploads for analysis and returns the results',
305
+ helpScanSummary: 'Perform static analysis on binaries / code artifacts',
297
306
  helpLambdaSummary: 'Perform scan on AWS Lambda functions',
298
307
  helpVersionSummary: 'Displays version of Contrast CLI',
299
308
  helpConfigSummary: 'Displays stored credentials',
@@ -304,37 +313,36 @@ const en_locales = () => {
304
313
  versionName: 'version',
305
314
  configName: 'config',
306
315
  helpName: 'help',
307
- scanOptionsFileName: '-f, --file',
308
- scanOptionsLanguage: '-l, --language',
309
- scanOptionsName: '-n, --name',
310
- scanOptionsTimeout: '-t, --time-out',
311
- scanOptionsVerbose: '-v, --verbose',
312
- scanOptionsFileNameSummary:
313
- 'Path of the file you want to scan. If no file is specified, Contrast searches for a .jar, .war, .js. or .zip file in the working directory.',
316
+ scanOptionsLanguageSummary: 'Valid values are JAVA, JAVASCRIPT and DOTNET',
314
317
  scanOptionsLanguageSummaryOptional:
315
318
  'Language of file to send for analysis. ',
316
319
  scanOptionsLanguageSummaryRequired:
317
320
  'If you scan a .zip file or you use the --file option.',
318
- scanOptionsNameSummary:
319
- 'Contrast project name. If not specified, Contrast uses contrast.settings to identify the project or creates a project.',
320
321
  scanOptionsTimeoutSummary:
321
322
  'Time in seconds to wait for scan to complete. Default value is 300 seconds.',
322
- scanOptionsVerboseSummary: 'Returns extended information to the terminal.',
323
+ scanOptionsFileNameSummary:
324
+ '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.',
325
+ scanOptionsVerboseSummary: ' Returns extended information to the terminal.',
323
326
  authSuccessMessage: 'Authentication successful',
324
- runScanMessage: 'Now run Contrast Scan',
327
+ runAuthSuccessMessage:
328
+ "Now you can use Contrast CLI \nRun 'contrast scan' on your file \n" +
329
+ "or 'contrast help' to learn more about the capabilities.",
325
330
  authWaitingMessage: 'Waiting for auth...',
326
331
  authTimedOutMessage: 'Auth Timed out, try again',
327
332
  zipErrorScan:
328
333
  'We only support zip files for JAVASCRIPT language, please set the flag --language JAVASCRIPT',
329
334
  unknownFileErrorScan: 'Unsupported file selected for Scan.',
330
- foundScanFile: 'found: %s',
331
- foundVulnerabilities: 'Found %s vulnerabilities',
335
+ foundScanFile: 'Found: %s',
332
336
  foundDetailedVulnerabilities:
333
- '%s Critical %s High %s Medium %s Low %s Note',
337
+ chalk.bold('%s Critical') +
338
+ ' | ' +
339
+ chalk.bold('%s High') +
340
+ ' | %s Medium | %s Low | %s Note',
334
341
  requiredParams: 'All required parameters are not present.',
335
342
  timeoutScan: 'Timeout set to 5 minutes.',
336
343
  searchingScanFileDirectory: 'Searching for file to scan from %s...',
337
344
  scanHeader: 'Contrast Scan CLI',
345
+ authHeader: 'Auth',
338
346
  lambdaHeader: 'Contrast lambda help',
339
347
  lambdaSummary:
340
348
  'Performs static security scan on an AWS Lambda Function.\nProduces CVE (Vulnerable Dependencies) and Least Privilege violations/remediation results.',
@@ -342,6 +350,7 @@ const en_locales = () => {
342
350
  lambdaPrerequisitesContent: 'contrast cli',
343
351
  scanFileNameOption: ' -f, --file',
344
352
  lambdaFunctionNameOption: ' -f, --function-name',
353
+ lambdaListFunctionsOption: ' -l, --list-functions',
345
354
  lambdaEndpointOption: '-e, --endpoint-url',
346
355
  lambdaRegionOption: '-r, --region',
347
356
  lambdaProfileOption: '-p, --profile',
@@ -349,6 +358,7 @@ const en_locales = () => {
349
358
  lambdaVerboseOption: '-v, --verbose',
350
359
  lambdaHelpOption: '-h, --help',
351
360
  lambdaFunctionNameSummery: 'Name of AWS lambda function to scan.',
361
+ lambdaListFunctionsSummery: 'List all available lambda functions to scan.',
352
362
  lambdaEndpointSummery: 'AWS Endpoint override, works like in AWS CLI.',
353
363
  lambdaRegionSummery:
354
364
  'Region override, default to AWS_DEAFAULT_REGION env var, works like in AWS CLI.',
@@ -371,7 +381,47 @@ const en_locales = () => {
371
381
  'An error has occurred when trying to get the Project Id please check your internet connection or provide the Project Id manually',
372
382
  internalServerErrorHeader: '500 error - Internal server error',
373
383
  resourceLockedErrorHeader: '423 error - Resource is locked',
374
-
384
+ auditHeader: 'Contrast Audit',
385
+ auditHeaderMessage: `
386
+ Performs software composition analysis (SCA) on your application/code time to show you the dependencies between open source libraries, including where vulnerabilities were introduced.\n
387
+ 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.`,
388
+ constantsAuditPrerequisitesContentSupportedLanguages:
389
+ 'Supported languages and their requirements are:',
390
+ constantsAuditPrerequisitesContentJava: 'Java: ',
391
+ constantsAuditPrerequisitesContentMessage: `
392
+ pom.xml AND Maven build platform, including the dependency plugin.
393
+ For a Gradle project (v4.8+) use build.gradle. A gradle-wrapper.properties file is also required.
394
+ Kotlin is also supported requiring a build.gradle.kts file.`,
395
+ constantsAuditPrerequisitesContentDotNet: '.NET framework and .NET core: ',
396
+ constantsAuditPrerequisitesContentDotNetMessage: `
397
+ MSBuild 15.0 or greater and have a packages.lock.json file are supported.\n
398
+ Note: If the packages.lock.json file is unavailable it can be generated by setting RestorePackagesWithLockFile to true within each *.csproj file and running dotnet build.\n`,
399
+ constantsAuditPrerequisitesContentLanguageNode: 'Node: ',
400
+ constantsAuditPrerequisitesContentLanguageRuby: 'Ruby: ',
401
+ constantsAuditPrerequisitesContentLanguagePython: 'Python: ',
402
+ constantsAuditPrerequisitesContentLanguageNodeMessage:
403
+ '*.package.json AND a lock file either *.package-lock.json or *.yarn.lock',
404
+ constantsAuditPrerequisitesContentLanguageRubyMessage:
405
+ 'gemfile AND gemfile.lock',
406
+ constantsAuditPrerequisitesContentLanguagePythonMessage:
407
+ 'pipfile AND pipfile.lock',
408
+ constantsAuditOptions: 'Audit Options',
409
+ auditOptionsIgnoreDevDependencies: '-igd, --ignore-dev',
410
+ auditOptionsIgnoreDevDependenciesDescription: 'ignores DevDependencies',
411
+ auditOptionsSave: '-s, --save',
412
+ auditOptionsSaveDescription:
413
+ 'saves the output in specified format Txt text, sbom',
414
+ scanNoVulnerabilitiesFound: '👏 No vulnerabilities found',
415
+ scanNoFiletypeSpecifiedForSave:
416
+ 'Please specify file type to save results to, accepted value is SARIF',
417
+ auditSBOMSaveSuccess:
418
+ '\n Software Bill of Materials (SBOM) saved successfully',
419
+ auditNoFiletypeSpecifiedForSave: `\n ${chalk.yellow.bold(
420
+ 'No file type specified for --save option to save audit results to. Use audit --help to see valid --save options.'
421
+ )}`,
422
+ auditBadFiletypeSpecifiedForSave: `\n ${chalk.yellow.bold(
423
+ 'Bad file type specified for --save option. Use audit --help to see valid --save options.'
424
+ )}`,
375
425
  ...lambda
376
426
  }
377
427
  }
package/src/constants.js CHANGED
@@ -20,6 +20,15 @@ const scanOptionDefinitions = [
20
20
  '}: ' +
21
21
  i18n.__('constantsProjectName')
22
22
  },
23
+ {
24
+ name: 'language',
25
+ alias: 'l',
26
+ description:
27
+ '{bold ' +
28
+ i18n.__('constantsOptional') +
29
+ '}: ' +
30
+ i18n.__('scanOptionsLanguageSummary')
31
+ },
23
32
  {
24
33
  name: 'file',
25
34
  alias: 'f',
@@ -27,7 +36,7 @@ const scanOptionDefinitions = [
27
36
  '{bold ' +
28
37
  i18n.__('constantsOptional') +
29
38
  '}: ' +
30
- i18n.__('constantsFileName')
39
+ i18n.__('scanOptionsFileNameSummary')
31
40
  },
32
41
  {
33
42
  name: 'project-id',
@@ -46,16 +55,7 @@ const scanOptionDefinitions = [
46
55
  '{bold ' +
47
56
  i18n.__('constantsOptional') +
48
57
  '}: ' +
49
- i18n.__('constantsScanTimeout')
50
- },
51
- {
52
- name: 'language',
53
- alias: 'l',
54
- description:
55
- '{bold ' +
56
- i18n.__('constantsRequiredCatalogue') +
57
- '}: ' +
58
- i18n.__('constantsLanguage')
58
+ i18n.__('scanOptionsTimeoutSummary')
59
59
  },
60
60
  {
61
61
  name: 'organization-id',
@@ -66,15 +66,6 @@ const scanOptionDefinitions = [
66
66
  '}: ' +
67
67
  i18n.__('constantsOrganizationId')
68
68
  },
69
- {
70
- name: 'yaml-path',
71
- alias: 'y',
72
- description:
73
- '{bold ' +
74
- i18n.__('constantsOptional') +
75
- '}: ' +
76
- i18n.__('constantsYamlPath')
77
- },
78
69
  {
79
70
  name: 'api-key',
80
71
  description:
@@ -93,8 +84,6 @@ const scanOptionDefinitions = [
93
84
  },
94
85
  {
95
86
  name: 'host',
96
- alias: 'h',
97
- defaultValue: 'app.contrastsecurity.com',
98
87
  description:
99
88
  '{bold ' +
100
89
  i18n.__('constantsRequired') +
@@ -127,12 +116,200 @@ const scanOptionDefinitions = [
127
116
  '}:' +
128
117
  i18n.__('constantsIgnoreCertErrors')
129
118
  },
119
+ {
120
+ name: 'verbose',
121
+ alias: 'v',
122
+ type: Boolean,
123
+ description:
124
+ '{bold ' +
125
+ i18n.__('constantsOptional') +
126
+ '}:' +
127
+ i18n.__('scanOptionsVerboseSummary')
128
+ },
129
+ {
130
+ name: 'save',
131
+ alias: 's',
132
+ description:
133
+ '{bold ' + i18n.__('constantsOptional') + '}:' + i18n.__('constantsSave')
134
+ },
130
135
  {
131
136
  name: 'help',
137
+ alias: 'h',
138
+ type: Boolean
139
+ },
140
+ {
141
+ name: 'debug',
142
+ alias: 'd',
132
143
  type: Boolean
133
144
  }
134
145
  ]
135
146
 
147
+ const authOptionDefinitions = [
148
+ {
149
+ name: 'help',
150
+ alias: 'h',
151
+ type: Boolean
152
+ }
153
+ ]
154
+
155
+ const configOptionDefinitions = [
156
+ {
157
+ name: 'help',
158
+ alias: 'h',
159
+ type: Boolean,
160
+ description: 'Help text'
161
+ },
162
+ {
163
+ name: 'clear',
164
+ alias: 'c',
165
+ type: Boolean,
166
+ description: 'Clear the currently stored config'
167
+ }
168
+ ]
169
+
170
+ const auditOptionDefinitions = [
171
+ {
172
+ name: 'application-id',
173
+ description:
174
+ '{bold ' +
175
+ i18n.__('constantsRequired') +
176
+ '}: ' +
177
+ i18n.__('constantsApplicationId')
178
+ },
179
+ {
180
+ name: 'application-name',
181
+ description:
182
+ '{bold ' +
183
+ i18n.__('constantsOptional') +
184
+ '}: ' +
185
+ i18n.__('constantsApplicationName')
186
+ },
187
+ {
188
+ name: 'project-path',
189
+ defaultValue: process.env.PWD,
190
+ description:
191
+ '{bold ' +
192
+ i18n.__('constantsOptional') +
193
+ '}: ' +
194
+ i18n.__('constantsProjectPath')
195
+ },
196
+ {
197
+ name: 'app-groups',
198
+ description:
199
+ '{bold ' +
200
+ i18n.__('constantsOptionalForCatalogue') +
201
+ '}: ' +
202
+ i18n.__('constantsAppGroups')
203
+ },
204
+ {
205
+ name: 'sub-project',
206
+ description:
207
+ '{bold ' +
208
+ i18n.__('constantsOptional') +
209
+ '}: ' +
210
+ i18n.__('constantsGradleMultiProject')
211
+ },
212
+ {
213
+ name: 'metadata',
214
+ description:
215
+ '{bold ' +
216
+ i18n.__('constantsOptional') +
217
+ '}: ' +
218
+ i18n.__('constantsMetadata')
219
+ },
220
+ {
221
+ name: 'tags',
222
+ description:
223
+ '{bold ' + i18n.__('constantsOptional') + '}: ' + i18n.__('constantsTags')
224
+ },
225
+ {
226
+ name: 'code',
227
+ description:
228
+ '{bold ' + i18n.__('constantsOptional') + '}: ' + i18n.__('constantsCode')
229
+ },
230
+ {
231
+ name: 'ignore-dev',
232
+ type: Boolean,
233
+ description:
234
+ '{bold ' +
235
+ i18n.__('constantsOptional') +
236
+ '}: ' +
237
+ i18n.__('constantsIgnoreDev')
238
+ },
239
+ {
240
+ name: 'maven-settings-path'
241
+ },
242
+ {
243
+ name: 'language',
244
+ alias: 'l',
245
+ description:
246
+ '{bold ' +
247
+ i18n.__('constantsRequiredCatalogue') +
248
+ '}: ' +
249
+ i18n.__('constantsLanguage')
250
+ },
251
+ {
252
+ name: 'organization-id',
253
+ alias: 'o',
254
+ description:
255
+ '{bold ' +
256
+ i18n.__('constantsRequired') +
257
+ '}: ' +
258
+ i18n.__('constantsOrganizationId')
259
+ },
260
+ {
261
+ name: 'api-key',
262
+ description:
263
+ '{bold ' +
264
+ i18n.__('constantsRequired') +
265
+ '}: ' +
266
+ i18n.__('constantsApiKey')
267
+ },
268
+ {
269
+ name: 'authorization',
270
+ description:
271
+ '{bold ' +
272
+ i18n.__('constantsRequired') +
273
+ '}: ' +
274
+ i18n.__('constantsAuthorization')
275
+ },
276
+ {
277
+ name: 'host',
278
+ alias: 'h',
279
+ description:
280
+ '{bold ' +
281
+ i18n.__('constantsRequired') +
282
+ '}: ' +
283
+ i18n.__('constantsHostId')
284
+ },
285
+ {
286
+ name: 'proxy',
287
+ description:
288
+ '{bold ' +
289
+ i18n.__('constantsOptional') +
290
+ '}: ' +
291
+ i18n.__('constantsProxyServer')
292
+ },
293
+ {
294
+ name: 'ignore-cert-errors',
295
+ type: Boolean,
296
+ description:
297
+ '{bold ' +
298
+ i18n.__('constantsOptional') +
299
+ '}:' +
300
+ i18n.__('constantsIgnoreCertErrors')
301
+ },
302
+ {
303
+ name: 'save',
304
+ alias: 's',
305
+ description:
306
+ '{bold ' +
307
+ i18n.__('constantsOptional') +
308
+ '}: ' +
309
+ i18n.__('auditOptionsSaveDescription')
310
+ }
311
+ ]
312
+
136
313
  const mainUsageGuide = commandLineUsage([
137
314
  {
138
315
  header: i18n.__('constantsHeader'),
@@ -146,6 +323,7 @@ const mainUsageGuide = commandLineUsage([
146
323
  header: i18n.__('constantsCommands'),
147
324
  content: [
148
325
  { name: i18n.__('authName'), summary: i18n.__('helpAuthSummary') },
326
+ { name: i18n.__('scanName'), summary: i18n.__('helpScanSummary') },
149
327
  { name: i18n.__('lambdaName'), summary: i18n.__('helpLambdaSummary') },
150
328
  { name: i18n.__('versionName'), summary: i18n.__('helpVersionSummary') },
151
329
  { name: i18n.__('configName'), summary: i18n.__('helpConfigSummary') },
@@ -163,6 +341,9 @@ module.exports = {
163
341
  commandLineDefinitions: {
164
342
  mainUsageGuide,
165
343
  mainDefinition,
166
- scanOptionDefinitions
344
+ scanOptionDefinitions,
345
+ auditOptionDefinitions,
346
+ authOptionDefinitions,
347
+ configOptionDefinitions
167
348
  }
168
349
  }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import commandLineArgs from 'command-line-args'
2
+ import { processAudit } from './commands/audit/processAudit'
2
3
  import { processAuth } from './commands/auth/auth'
3
4
  import { processConfig } from './commands/config/config'
4
5
  import { processScan } from './commands/scan/processScan'
@@ -6,6 +7,11 @@ import constants from './constants'
6
7
  import { APP_NAME, APP_VERSION } from './constants/constants'
7
8
  import { processLambda } from './lambda/lambda'
8
9
  import { localConfig } from './utils/getConfig'
10
+ import {
11
+ findLatestCLIVersion,
12
+ isCorrectNodeVersion
13
+ } from './common/versionChecker'
14
+ import { findCommandOnError } from './common/errorHandling'
9
15
 
10
16
  const {
11
17
  commandLineDefinitions: { mainUsageGuide, mainDefinition }
@@ -28,41 +34,75 @@ const getMainOption = () => {
28
34
  }
29
35
 
30
36
  const start = async () => {
31
- const { mainOptions, argv: argvMain } = getMainOption()
32
- const command =
33
- mainOptions.command != undefined ? mainOptions.command.toLowerCase() : ''
34
- if (command === 'version') {
35
- console.log(APP_VERSION)
36
- return
37
- }
37
+ if (await isCorrectNodeVersion(process.version)) {
38
+ const { mainOptions, argv: argvMain } = getMainOption()
39
+ const command =
40
+ mainOptions.command != undefined ? mainOptions.command.toLowerCase() : ''
41
+ if (
42
+ command === 'version' ||
43
+ argvMain.includes('--v') ||
44
+ argvMain.includes('--version')
45
+ ) {
46
+ console.log(APP_VERSION)
47
+ await findLatestCLIVersion()
48
+ return
49
+ }
38
50
 
39
- if (command === 'config') {
40
- return processConfig(argvMain, config)
41
- }
51
+ // @ts-ignore
52
+ config.set('numOfRuns', config.get('numOfRuns') + 1)
42
53
 
43
- if (command === 'auth') {
44
- return await processAuth(config)
45
- }
54
+ // @ts-ignore
55
+ if (config.get('numOfRuns') >= 5) {
56
+ // @ts-ignore
57
+ await findLatestCLIVersion()
58
+ config.set('numOfRuns', 0)
59
+ }
46
60
 
47
- if (command === 'lambda') {
48
- return await processLambda(argvMain)
49
- }
61
+ if (command === 'config') {
62
+ return processConfig(argvMain, config)
63
+ }
50
64
 
51
- /* second - parse the merge command options */
52
- if (command === 'scan') {
53
- return await processScan()
54
- }
65
+ if (command === 'auth') {
66
+ return await processAuth(argvMain, config)
67
+ }
68
+
69
+ if (command === 'lambda') {
70
+ return await processLambda(argvMain)
71
+ }
72
+
73
+ if (command === 'scan') {
74
+ return await processScan(argvMain)
75
+ }
76
+
77
+ if (command === 'audit') {
78
+ return await processAudit(argvMain)
79
+ }
80
+
81
+ if (
82
+ command === 'help' ||
83
+ argvMain.includes('--help') ||
84
+ Object.keys(mainOptions).length === 0
85
+ ) {
86
+ console.log(mainUsageGuide)
87
+ } else if (mainOptions._unknown !== undefined) {
88
+ const foundCommand = findCommandOnError(mainOptions._unknown)
55
89
 
56
- if (
57
- command === 'help' ||
58
- argvMain.includes('--help') ||
59
- Object.keys(mainOptions).length === 0
60
- ) {
61
- console.log(mainUsageGuide)
90
+ foundCommand
91
+ ? console.log(
92
+ `Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`
93
+ )
94
+ : console.log(
95
+ `Unknown Command: ${command} \nUse --help for the full list`
96
+ )
97
+ } else {
98
+ console.log(`Unknown Command: ${command} \nUse --help for the full list`)
99
+ }
100
+ process.exit(9)
62
101
  } else {
63
102
  console.log(
64
- 'Unknown Command: ' + command + ' \nUse --help for the full list'
103
+ 'Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.'
65
104
  )
105
+ process.exit(9)
66
106
  }
67
107
  }
68
108