@contrast/contrast 1.0.8 → 1.0.11

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 (217) hide show
  1. package/README.md +2 -2
  2. package/dist/audit/languageAnalysisEngine/getProjectRootFilenames.js +16 -25
  3. package/dist/audit/languageAnalysisEngine/report/commonReportingFunctions.js +103 -57
  4. package/dist/audit/languageAnalysisEngine/report/models/reportGuidanceModel.js +6 -0
  5. package/dist/audit/languageAnalysisEngine/report/models/reportOutputModel.js +3 -3
  6. package/dist/audit/languageAnalysisEngine/report/models/severityCountModel.js +1 -0
  7. package/dist/audit/languageAnalysisEngine/report/reportingFeature.js +68 -17
  8. package/dist/audit/languageAnalysisEngine/report/utils/reportUtils.js +39 -7
  9. package/dist/audit/languageAnalysisEngine/sendSnapshot.js +6 -30
  10. package/dist/audit/save.js +21 -13
  11. package/dist/commands/audit/auditConfig.js +3 -19
  12. package/dist/commands/audit/auditController.js +1 -10
  13. package/dist/commands/audit/help.js +7 -24
  14. package/dist/commands/audit/processAudit.js +5 -9
  15. package/dist/commands/audit/saveFile.js +2 -2
  16. package/dist/commands/auth/auth.js +1 -1
  17. package/dist/commands/config/config.js +2 -2
  18. package/dist/commands/scan/processScan.js +11 -4
  19. package/dist/commands/scan/sca/scaAnalysis.js +37 -13
  20. package/dist/common/HTTPClient.js +17 -8
  21. package/dist/common/errorHandling.js +2 -2
  22. package/dist/common/fail.js +66 -0
  23. package/dist/common/versionChecker.js +1 -1
  24. package/dist/constants/constants.js +7 -2
  25. package/dist/constants/locales.js +40 -38
  26. package/dist/constants.js +62 -12
  27. package/dist/index.js +57 -45
  28. package/dist/lambda/lambda.js +5 -2
  29. package/dist/sbom/generateSbom.js +2 -2
  30. package/dist/scaAnalysis/common/formatMessage.js +7 -1
  31. package/dist/scaAnalysis/common/scaParserForGoAndJava.js +32 -0
  32. package/dist/scaAnalysis/common/treeUpload.js +24 -10
  33. package/dist/scaAnalysis/dotnet/analysis.js +55 -0
  34. package/dist/scaAnalysis/dotnet/index.js +10 -0
  35. package/dist/scaAnalysis/go/goAnalysis.js +8 -2
  36. package/dist/scaAnalysis/java/analysis.js +10 -6
  37. package/dist/scaAnalysis/java/index.js +7 -1
  38. package/dist/scaAnalysis/java/javaBuildDepsParser.js +19 -3
  39. package/dist/scaAnalysis/javascript/analysis.js +4 -7
  40. package/dist/scaAnalysis/javascript/index.js +16 -4
  41. package/dist/scaAnalysis/php/analysis.js +14 -33
  42. package/dist/scaAnalysis/php/index.js +11 -4
  43. package/dist/scaAnalysis/python/analysis.js +43 -5
  44. package/dist/scaAnalysis/python/index.js +7 -2
  45. package/dist/scaAnalysis/ruby/analysis.js +16 -14
  46. package/dist/scan/autoDetection.js +13 -24
  47. package/dist/scan/fileUtils.js +31 -12
  48. package/dist/scan/formatScanOutput.js +9 -8
  49. package/dist/scan/populateProjectIdAndProjectName.js +5 -0
  50. package/dist/scan/scan.js +4 -0
  51. package/dist/scan/scanConfig.js +5 -5
  52. package/dist/scan/scanResults.js +39 -3
  53. package/dist/telemetry/telemetry.js +137 -0
  54. package/dist/utils/commonApi.js +1 -1
  55. package/dist/utils/getConfig.js +3 -8
  56. package/dist/utils/parsedCLIOptions.js +3 -1
  57. package/dist/utils/requestUtils.js +7 -1
  58. package/package.json +2 -3
  59. package/src/audit/languageAnalysisEngine/getProjectRootFilenames.js +21 -57
  60. package/src/audit/languageAnalysisEngine/report/commonReportingFunctions.ts +155 -77
  61. package/src/audit/languageAnalysisEngine/report/models/reportGuidanceModel.ts +5 -0
  62. package/src/audit/languageAnalysisEngine/report/models/reportOutputModel.ts +5 -5
  63. package/src/audit/languageAnalysisEngine/report/models/severityCountModel.ts +2 -0
  64. package/src/audit/languageAnalysisEngine/report/reportingFeature.ts +56 -27
  65. package/src/audit/languageAnalysisEngine/report/utils/reportUtils.ts +45 -6
  66. package/src/audit/languageAnalysisEngine/sendSnapshot.js +6 -32
  67. package/src/audit/save.js +32 -16
  68. package/src/commands/audit/auditConfig.ts +10 -28
  69. package/src/commands/audit/auditController.ts +0 -11
  70. package/src/commands/audit/help.ts +7 -24
  71. package/src/commands/audit/processAudit.ts +16 -8
  72. package/src/commands/audit/saveFile.ts +2 -2
  73. package/src/commands/auth/auth.js +3 -1
  74. package/src/commands/config/config.js +4 -2
  75. package/src/commands/scan/processScan.js +18 -5
  76. package/src/commands/scan/sca/scaAnalysis.js +50 -18
  77. package/src/common/HTTPClient.js +23 -9
  78. package/src/common/errorHandling.ts +2 -3
  79. package/src/common/fail.js +75 -0
  80. package/src/common/versionChecker.ts +1 -1
  81. package/src/constants/constants.js +9 -3
  82. package/src/constants/locales.js +70 -45
  83. package/src/constants.js +67 -13
  84. package/src/index.ts +91 -66
  85. package/src/lambda/lambda.ts +5 -2
  86. package/src/lambda/types.ts +1 -0
  87. package/src/sbom/generateSbom.ts +2 -2
  88. package/src/scaAnalysis/common/formatMessage.js +8 -1
  89. package/src/scaAnalysis/common/scaParserForGoAndJava.js +41 -0
  90. package/src/scaAnalysis/common/treeUpload.js +25 -11
  91. package/src/scaAnalysis/dotnet/analysis.js +72 -0
  92. package/src/scaAnalysis/dotnet/index.js +11 -0
  93. package/src/scaAnalysis/go/goAnalysis.js +9 -2
  94. package/src/scaAnalysis/java/analysis.js +11 -6
  95. package/src/scaAnalysis/java/index.js +9 -1
  96. package/src/scaAnalysis/java/javaBuildDepsParser.js +25 -6
  97. package/src/scaAnalysis/javascript/analysis.js +6 -7
  98. package/src/scaAnalysis/javascript/index.js +25 -6
  99. package/src/scaAnalysis/php/analysis.js +15 -35
  100. package/src/scaAnalysis/php/index.js +15 -4
  101. package/src/scaAnalysis/python/analysis.js +49 -5
  102. package/src/scaAnalysis/python/index.js +7 -2
  103. package/src/scaAnalysis/ruby/analysis.js +18 -15
  104. package/src/scan/autoDetection.js +14 -27
  105. package/src/scan/fileUtils.js +33 -12
  106. package/src/scan/formatScanOutput.ts +10 -8
  107. package/src/scan/populateProjectIdAndProjectName.js +5 -1
  108. package/src/scan/scan.ts +4 -0
  109. package/src/scan/scanConfig.js +7 -7
  110. package/src/scan/scanResults.js +46 -3
  111. package/src/telemetry/telemetry.ts +154 -0
  112. package/src/utils/commonApi.js +1 -1
  113. package/src/utils/getConfig.ts +5 -18
  114. package/src/utils/parsedCLIOptions.js +14 -1
  115. package/src/utils/requestUtils.js +8 -1
  116. package/dist/audit/AnalysisEngine.js +0 -37
  117. package/dist/audit/autodetection/autoDetectLanguage.js +0 -32
  118. package/dist/audit/dotnetAnalysisEngine/index.js +0 -25
  119. package/dist/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -35
  120. package/dist/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -15
  121. package/dist/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -18
  122. package/dist/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -14
  123. package/dist/audit/dotnetAnalysisEngine/sanitizer.js +0 -9
  124. package/dist/audit/goAnalysisEngine/index.js +0 -17
  125. package/dist/audit/goAnalysisEngine/parseProjectFileContents.js +0 -164
  126. package/dist/audit/goAnalysisEngine/readProjectFileContents.js +0 -21
  127. package/dist/audit/goAnalysisEngine/sanitizer.js +0 -5
  128. package/dist/audit/javaAnalysisEngine/index.js +0 -34
  129. package/dist/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -155
  130. package/dist/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -353
  131. package/dist/audit/javaAnalysisEngine/readProjectFileContents.js +0 -98
  132. package/dist/audit/javaAnalysisEngine/sanitizer.js +0 -5
  133. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -25
  134. package/dist/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -25
  135. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -35
  136. package/dist/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -24
  137. package/dist/audit/languageAnalysisEngine/constants.js +0 -20
  138. package/dist/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -25
  139. package/dist/audit/languageAnalysisEngine/index.js +0 -39
  140. package/dist/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -66
  141. package/dist/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -166
  142. package/dist/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -40
  143. package/dist/audit/nodeAnalysisEngine/index.js +0 -31
  144. package/dist/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -18
  145. package/dist/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -18
  146. package/dist/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -17
  147. package/dist/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -14
  148. package/dist/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -24
  149. package/dist/audit/nodeAnalysisEngine/sanitizer.js +0 -9
  150. package/dist/audit/phpAnalysisEngine/index.js +0 -23
  151. package/dist/audit/phpAnalysisEngine/parseLockFileContents.js +0 -52
  152. package/dist/audit/phpAnalysisEngine/readLockFileContents.js +0 -13
  153. package/dist/audit/phpAnalysisEngine/readProjectFileContents.js +0 -16
  154. package/dist/audit/phpAnalysisEngine/sanitizer.js +0 -5
  155. package/dist/audit/pythonAnalysisEngine/index.js +0 -25
  156. package/dist/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -17
  157. package/dist/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -21
  158. package/dist/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -13
  159. package/dist/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -14
  160. package/dist/audit/pythonAnalysisEngine/sanitizer.js +0 -7
  161. package/dist/audit/rubyAnalysisEngine/index.js +0 -25
  162. package/dist/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -176
  163. package/dist/audit/rubyAnalysisEngine/parsedGemfile.js +0 -22
  164. package/dist/audit/rubyAnalysisEngine/readGemfileContents.js +0 -14
  165. package/dist/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -14
  166. package/dist/audit/rubyAnalysisEngine/sanitizer.js +0 -6
  167. package/src/audit/AnalysisEngine.js +0 -103
  168. package/src/audit/autodetection/autoDetectLanguage.ts +0 -40
  169. package/src/audit/dotnetAnalysisEngine/index.js +0 -26
  170. package/src/audit/dotnetAnalysisEngine/parseLockFileContents.js +0 -47
  171. package/src/audit/dotnetAnalysisEngine/parseProjectFileContents.js +0 -29
  172. package/src/audit/dotnetAnalysisEngine/readLockFileContents.js +0 -30
  173. package/src/audit/dotnetAnalysisEngine/readProjectFileContents.js +0 -26
  174. package/src/audit/dotnetAnalysisEngine/sanitizer.js +0 -11
  175. package/src/audit/goAnalysisEngine/index.js +0 -18
  176. package/src/audit/goAnalysisEngine/parseProjectFileContents.js +0 -209
  177. package/src/audit/goAnalysisEngine/readProjectFileContents.js +0 -31
  178. package/src/audit/goAnalysisEngine/sanitizer.js +0 -7
  179. package/src/audit/javaAnalysisEngine/index.js +0 -41
  180. package/src/audit/javaAnalysisEngine/parseMavenProjectFileContents.js +0 -225
  181. package/src/audit/javaAnalysisEngine/parseProjectFileContents.js +0 -420
  182. package/src/audit/javaAnalysisEngine/readProjectFileContents.js +0 -141
  183. package/src/audit/javaAnalysisEngine/sanitizer.js +0 -6
  184. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedLanguages.js +0 -36
  185. package/src/audit/languageAnalysisEngine/checkForMultipleIdentifiedProjectFiles.js +0 -42
  186. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasLockFile.js +0 -54
  187. package/src/audit/languageAnalysisEngine/checkIdentifiedLanguageHasProjectFile.js +0 -33
  188. package/src/audit/languageAnalysisEngine/constants.js +0 -23
  189. package/src/audit/languageAnalysisEngine/getIdentifiedLanguageInfo.js +0 -41
  190. package/src/audit/languageAnalysisEngine/index.js +0 -45
  191. package/src/audit/languageAnalysisEngine/languageAnalysisFactory.js +0 -96
  192. package/src/audit/languageAnalysisEngine/reduceIdentifiedLanguages.js +0 -251
  193. package/src/audit/nodeAnalysisEngine/handleNPMLockFileV2.js +0 -49
  194. package/src/audit/nodeAnalysisEngine/index.js +0 -35
  195. package/src/audit/nodeAnalysisEngine/parseNPMLockFileContents.js +0 -20
  196. package/src/audit/nodeAnalysisEngine/parseYarnLockFileContents.js +0 -26
  197. package/src/audit/nodeAnalysisEngine/readNPMLockFileContents.js +0 -23
  198. package/src/audit/nodeAnalysisEngine/readProjectFileContents.js +0 -27
  199. package/src/audit/nodeAnalysisEngine/readYarnLockFileContents.js +0 -36
  200. package/src/audit/nodeAnalysisEngine/sanitizer.js +0 -11
  201. package/src/audit/phpAnalysisEngine/index.js +0 -27
  202. package/src/audit/phpAnalysisEngine/parseLockFileContents.js +0 -60
  203. package/src/audit/phpAnalysisEngine/readLockFileContents.js +0 -14
  204. package/src/audit/phpAnalysisEngine/readProjectFileContents.js +0 -25
  205. package/src/audit/phpAnalysisEngine/sanitizer.js +0 -4
  206. package/src/audit/pythonAnalysisEngine/index.js +0 -55
  207. package/src/audit/pythonAnalysisEngine/parsePipfileLockContents.js +0 -23
  208. package/src/audit/pythonAnalysisEngine/parseProjectFileContents.js +0 -33
  209. package/src/audit/pythonAnalysisEngine/readPipfileLockFileContents.js +0 -16
  210. package/src/audit/pythonAnalysisEngine/readPythonProjectFileContents.js +0 -22
  211. package/src/audit/pythonAnalysisEngine/sanitizer.js +0 -9
  212. package/src/audit/rubyAnalysisEngine/index.js +0 -30
  213. package/src/audit/rubyAnalysisEngine/parseGemfileLockContents.js +0 -215
  214. package/src/audit/rubyAnalysisEngine/parsedGemfile.js +0 -39
  215. package/src/audit/rubyAnalysisEngine/readGemfileContents.js +0 -18
  216. package/src/audit/rubyAnalysisEngine/readGemfileLockContents.js +0 -17
  217. package/src/audit/rubyAnalysisEngine/sanitizer.js +0 -8
@@ -20,8 +20,8 @@ const en_locales = () => {
20
20
  libraryAnalysisError:
21
21
  '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',
22
22
  yamlMissingParametersHeader: 'Missing Parameters',
23
- yamlMissingParametersMessage:
24
- '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',
23
+ genericErrorMessage:
24
+ 'An error has occur please check your command again. For more information use the --help commands.',
25
25
  unauthenticatedErrorHeader: '401 error - Unauthenticated',
26
26
  unauthenticatedErrorMessage:
27
27
  'Please check the following keys are correct:\n--organization-id, --api-key or --authorization',
@@ -53,8 +53,10 @@ const en_locales = () => {
53
53
  "Identified project language as '%s' but found multiple project files: %s. Please specify which project file you would like analyzed with the %s CLI option.",
54
54
  languageAnalysisHasNoLockFile:
55
55
  "Identified project language as '%s' but no project lock file was found.",
56
+ languageAnalysisHasNoPackageJsonFile:
57
+ 'Identified project language as javascript but no package.json file was found.',
56
58
  languageAnalysisHasMultipleLockFiles:
57
- "Identified project language as '%s' but multiple project lock files were found: %s \n",
59
+ "Identified project language as '%s' but multiple project lock files were found.",
58
60
  languageAnalysisProjectFileError:
59
61
  "Identified project language as '%s' but no project file was found.",
60
62
  languageAnalysisProjectRootFileNameReadError:
@@ -64,17 +66,20 @@ const en_locales = () => {
64
66
  languageAnalysisProjectRootFileNameFailure:
65
67
  'Failed to get information about the file or directory @ %s because: ',
66
68
  languageAnalysisFailure: ' analysis failed because: ',
67
- languageAnalysisNoLanguage: 'No language detected in project path @ %s',
69
+ languageAnalysisNoLanguage:
70
+ 'We cannot detect a project, use -f <path> to specify a file or folder to analyze.',
71
+ languageAnalysisNoLanguageHelpLine: `${chalk.bold(
72
+ 'contrast audit --help'
73
+ )} for more information.`,
68
74
  NodeAnalysisFailure: 'NODE analysis failed because: ',
69
75
  phpAnalysisFailure: 'PHP analysis failed because: ',
70
- NodeParseNPM:
71
- "Failed to parse NODE package-lock.json file @ '%s' because: ",
76
+ NodeParseNPM: 'Failed to parse NODE package-lock.json file because: ',
72
77
  phpParseComposerLock:
73
78
  "Failed to parse PHP composer.lock file @ '%s' because: ",
74
79
  NodeReadNpmError:
75
80
  'Failed to read the package-lock.json file @ "%s" because: ',
76
81
  phpReadError: 'Failed to read the composer.lock file @ "%s" because: ',
77
- NodeParseYarn: "Failed to parse Node yarn.lock version 1 @ '%s' because: ",
82
+ NodeParseYarn: 'Failed to parse yarn.lock version %s because: ',
78
83
  NodeParseYarn2: "Failed to parse Node yarn.lock version 2 @ '%s' because: ",
79
84
  nodeReadProjectFileError:
80
85
  'Failed to read the NODE project file @ "%s" because: ',
@@ -116,10 +121,11 @@ const en_locales = () => {
116
121
  'The name of the application cataloged by Contrast UI',
117
122
  constantsCatalogueApplication:
118
123
  'Provide this if you want to catalogue an application',
124
+ failOptionErrorMessage:
125
+ ' FAIL - CVEs have been detected that match at least the cve_severity option specified.',
119
126
  constantsLanguage:
120
127
  'Valid values are JAVA, DOTNET, NODE, PYTHON and RUBY. If there are multiple project configuration files in the project_path, language is also required. Also, provide this when cataloguing an application',
121
- constantsFilePath:
122
- 'The directory root of a project/application that you would like analyzed. Defaults to current directory.',
128
+ constantsFilePath: `Specify a directory or the file where dependencies are declared. (By default, CodeSec will search for project files in the current directory.)`,
123
129
  constantsSilent: 'Silences JSON output.',
124
130
  constantsAppGroups:
125
131
  'Assign your application to one or more pre-existing groups when using the catalogue command. Group lists should be comma separated.',
@@ -138,15 +144,22 @@ const en_locales = () => {
138
144
  constantsReport: 'Display vulnerability information for this application',
139
145
  constantsFail:
140
146
  'Set the process to fail if this option is set in combination with --cve_severity.',
141
- failOptionErrorMessage:
142
- ' FAIL - CVEs have been detected that match at least the cve_severity or cve_threshold option specified.',
147
+ failThresholdOptionErrorMessage: 'More than 0 vulnerabilities found',
148
+ failSeverityOptionErrorMessage:
149
+ ' FAIL - Results detected vulnerabilities over accepted severity level',
143
150
  constantsSeverity:
144
151
  '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.',
145
152
  constantsCount: 'The number of CVEs that must be exceeded to fail a build',
146
153
  constantsHeader: 'CodeSec by Contrast Security',
147
- constantsPrerequisitesContentScanLanguages: 'Java & JavaScript supported',
154
+ configHeader2: 'Config options',
155
+ clearHeader: '-c, --clear',
156
+ clearContent: 'Removes stored credentials',
157
+ constantsPrerequisitesContentScanLanguages:
158
+ 'Java, Javascript and .NET supported',
148
159
  constantsContrastContent:
149
- "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).",
160
+ 'Use the contrast command for fast and accurate security analysis of your applications, APIs, serverless functions, and libraries.',
161
+ constantsContrastCategories:
162
+ '\n Code: Java, .NET, .NET Core, JavaScript\n Serverless: AWS Lambda - Java, Python\n Libraries: Java, .NET, Node, Ruby, Python, Go, PHP\n',
150
163
  constantsUsageGuideContentRecommendation:
151
164
  '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.',
152
165
  constantsPrerequisitesHeader: 'Pre-requisites',
@@ -249,7 +262,7 @@ const en_locales = () => {
249
262
  scanLabel:
250
263
  "adds a label to the scan - defaults to 'Started by CLI tool at current date'",
251
264
  constantsIgnoreDev:
252
- 'Excludes developer dependencies from the output. By default all dependencies are included.',
265
+ 'Excludes developer dependencies from the results. All dependencies are included by default.',
253
266
  constantsCommands: 'Commands',
254
267
  constantsScanOptions: 'Scan Options',
255
268
  sbomError: 'All required parameters are not present.',
@@ -277,12 +290,17 @@ const en_locales = () => {
277
290
  'We only accept the following file types: \nJava - .jar, .war \nJavaScript - .js or .zip files',
278
291
  helpAuthSummary:
279
292
  'Authenticate Contrast using your Github or Google account',
280
- helpScanSummary: 'Perform static analysis on binaries / code artifacts',
281
- helpLambdaSummary: 'Perform scan on AWS Lambda functions',
293
+ helpAuditSummary:
294
+ 'Searches for a suitable file in the working directory to perform a security audit of dependencies and returns the results. [Contrast audit --help (for options).]',
295
+ helpScanSummary:
296
+ 'Searches for a .jar, .war, .js, or .zip file in the working directory, uploads files for analysis, and returns the results. [For further help/options, enter scan --help]',
297
+ helpLambdaSummary:
298
+ 'Performs a static security scan on an AWS lambda function. lambda --help (for options)',
282
299
  helpVersionSummary: 'Displays version of Contrast CLI',
283
300
  helpConfigSummary: 'Displays stored credentials',
284
301
  helpSummary: 'Displays usage guide',
285
302
  authName: 'auth',
303
+ auditName: 'audit',
286
304
  scanName: 'scan',
287
305
  lambdaName: 'lambda',
288
306
  versionName: 'version',
@@ -300,8 +318,7 @@ const en_locales = () => {
300
318
  scanOptionsVerboseSummary: ' Returns extended information to the terminal.',
301
319
  authSuccessMessage: 'Authentication successful',
302
320
  runAuthSuccessMessage:
303
- "Now you can use Contrast CLI \nRun 'contrast scan' on your file \n" +
304
- "or 'contrast help' to learn more about the capabilities.",
321
+ "Now you can use CodeSec by Contrast \nRun: \n'contrast scan' on your file \n'contrast audit' on a file or directory,\n'contrast lambda' on an AWS function.\nor 'contrast help' to learn more about the capabilities.",
305
322
  authWaitingMessage: 'Waiting for auth...',
306
323
  authTimedOutMessage: 'Auth Timed out, try again',
307
324
  zipErrorScan:
@@ -329,7 +346,7 @@ const en_locales = () => {
329
346
  'Supported runtimes: Java & Python',
330
347
  lambdaPrerequisitesContentLambdaDescriptionTitle: 'AWS Requirements\n',
331
348
  lambdaPrerequisitesContentLambdaDescription:
332
- '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',
349
+ '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, ListFunctions\n - IAM: GetRolePolicy, GetPolicy, GetPolicyVersion, ListRolePolicies, ListAttachedRolePolicies',
333
350
  scanFileNameOption: '-f, --file',
334
351
  lambdaFunctionNameOption: '-f, --function-name',
335
352
  lambdaListFunctionsOption: '-l, --list-functions',
@@ -364,36 +381,44 @@ const en_locales = () => {
364
381
  'An error has occurred when trying to get the Project Id please check your internet connection or provide the Project Id manually',
365
382
  internalServerErrorHeader: '500 error - Internal server error',
366
383
  resourceLockedErrorHeader: '423 error - Resource is locked',
367
- auditHeader: 'Contrast Audit',
368
- auditHeaderMessage: `
369
- 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
370
- 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.`,
384
+ auditHeader: 'Contrast audit help',
385
+ auditHeaderMessage:
386
+ "Use 'contrast audit' to analyze a project’s dependencies for vulnerabilities.",
371
387
  constantsAuditPrerequisitesContentSupportedLanguages:
372
388
  'Supported languages and their requirements are:',
373
- constantsAuditPrerequisitesContentJava: 'Java: ',
374
- constantsAuditPrerequisitesContentMessage: `
375
- pom.xml AND Maven build platform, including the dependency plugin.
376
- For a Gradle project (v4.8+) use build.gradle. A gradle-wrapper.properties file is also required.
377
- Kotlin is also supported requiring a build.gradle.kts file.`,
378
- constantsAuditPrerequisitesContentDotNet: '.NET framework and .NET core: ',
389
+ constantsAuditPrerequisitesJavaContentMessage: `
390
+ ${chalk.bold('Java:')} pom.xml ${chalk.bold(
391
+ 'and'
392
+ )} Maven build platform including the dependency plugin.
393
+ ${chalk.bold('Or')} build.gradle ${chalk.bold(
394
+ 'and'
395
+ )} gradle dependencies or ./gradlew dependencies must be supported`,
379
396
  constantsAuditPrerequisitesContentDotNetMessage: `
380
- MSBuild 15.0 or greater and have a packages.lock.json file are supported.\n
381
- 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`,
382
- constantsAuditPrerequisitesContentLanguageNode: 'Node: ',
383
- constantsAuditPrerequisitesContentLanguageRuby: 'Ruby: ',
384
- constantsAuditPrerequisitesContentLanguagePython: 'Python: ',
385
- constantsAuditPrerequisitesContentLanguageNodeMessage:
386
- '*.package.json AND a lock file either *.package-lock.json or *.yarn.lock',
387
- constantsAuditPrerequisitesContentLanguageRubyMessage:
388
- 'gemfile AND gemfile.lock',
389
- constantsAuditPrerequisitesContentLanguagePythonMessage:
390
- 'pipfile AND pipfile.lock',
397
+ ${chalk.bold(
398
+ '.NET framework and .NET core:'
399
+ )} MSBuild 15.0 or greater and a packages.lock.json file.
400
+ 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`,
401
+ constantsAuditPrerequisitesContentNodeMessage: `${chalk.bold(
402
+ 'Node:'
403
+ )} package.json and a lock file (either .package-lock.json or .yarn.lock.)\n`,
404
+ constantsAuditPrerequisitesContentRubyMessage: `${chalk.bold(
405
+ 'Ruby:'
406
+ )} gemfile and gemfile.lock\n`,
407
+ constantsAuditPrerequisitesContentPythonMessage: `${chalk.bold(
408
+ 'Python:'
409
+ )} pipfile and pipfile.lock\n`,
410
+ constantsAuditPrerequisitesContentGoMessage: `${chalk.bold(
411
+ 'Go:'
412
+ )} go.mod\n`,
413
+ constantsAuditPrerequisitesContentPHPMessage: `${chalk.bold(
414
+ 'PHP:'
415
+ )} composer.json and composer.lock\n`,
391
416
  constantsAuditOptions: 'Audit Options',
392
- auditOptionsIgnoreDevDependencies: '-igd, --ignore-dev',
393
- auditOptionsIgnoreDevDependenciesDescription: 'ignores DevDependencies',
394
- auditOptionsSave: '-s, --save',
395
417
  auditOptionsSaveDescription:
396
- 'saves the output in specified format, options: sbom',
418
+ 'Generate and save an SBOM (Software Bill of Materials)\n',
419
+ auditOptionsSaveOptionsDescription:
420
+ 'Valid options are: --save spdx and --save cyclonedx (CycloneDX is the default format.)',
421
+ exceededFreeTier: `It looks like you are really loving CodeSec! \nYou have reached the monthly scan limit on the FREE tier. \nPlease contact sales@contrastsecurity.com to upgrade.`,
397
422
  scanNotCompleted:
398
423
  'Scan not completed. Check for framework and language support here: %s',
399
424
  auditNotCompleted: 'audit not completed. Please try again',
@@ -415,7 +440,7 @@ const en_locales = () => {
415
440
  auditReportSuccessMessage: 'Report successfully retrieved',
416
441
  auditReportFailureMessage: 'Unable to generate library report',
417
442
  auditSCAAnalysisBegins: 'Contrast SCA audit started',
418
- auditSCAAnalysisComplete: 'Contrast SCA audit complete',
443
+ auditSCAAnalysisComplete: 'Contrast audit complete',
419
444
  ...lambda
420
445
  }
421
446
  }
package/src/constants.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const commandLineUsage = require('command-line-usage')
2
2
  const i18n = require('i18n')
3
3
  const { en_locales } = require('./constants/locales.js')
4
+ const { parseSeverity } = require('./common/fail')
4
5
 
5
6
  i18n.configure({
6
7
  staticCatalog: {
@@ -106,6 +107,24 @@ const scanOptionDefinitions = [
106
107
  '}: ' +
107
108
  i18n.__('constantsProxyServer')
108
109
  },
110
+ {
111
+ name: 'fail',
112
+ type: Boolean,
113
+ description:
114
+ '{bold ' +
115
+ i18n.__('constantsOptional') +
116
+ '}: ' +
117
+ i18n.__('failOptionErrorMessage')
118
+ },
119
+ {
120
+ name: 'severity',
121
+ type: severity => parseSeverity(severity),
122
+ description:
123
+ '{bold ' +
124
+ i18n.__('constantsOptional') +
125
+ '}: ' +
126
+ i18n.__('constantsSeverity')
127
+ },
109
128
  {
110
129
  name: 'ff',
111
130
  type: Boolean,
@@ -213,13 +232,31 @@ const auditOptionDefinitions = [
213
232
  {
214
233
  name: 'file',
215
234
  alias: 'f',
216
- defaultValue: process.cwd(),
235
+ defaultValue: process.cwd().concat('/'),
217
236
  description:
218
237
  '{bold ' +
219
238
  i18n.__('constantsOptional') +
220
239
  '}: ' +
221
240
  i18n.__('constantsFilePath')
222
241
  },
242
+ {
243
+ name: 'fail',
244
+ type: Boolean,
245
+ description:
246
+ '{bold ' +
247
+ i18n.__('constantsOptional') +
248
+ '}: ' +
249
+ i18n.__('failOptionErrorMessage')
250
+ },
251
+ {
252
+ name: 'severity',
253
+ type: severity => parseSeverity(severity),
254
+ description:
255
+ '{bold ' +
256
+ i18n.__('constantsOptional') +
257
+ '}: ' +
258
+ i18n.__('constantsSeverity')
259
+ },
223
260
  {
224
261
  name: 'app-groups',
225
262
  description:
@@ -257,6 +294,7 @@ const auditOptionDefinitions = [
257
294
  {
258
295
  name: 'ignore-dev',
259
296
  type: Boolean,
297
+ alias: 'i',
260
298
  description:
261
299
  '{bold ' +
262
300
  i18n.__('constantsOptional') +
@@ -266,15 +304,6 @@ const auditOptionDefinitions = [
266
304
  {
267
305
  name: 'maven-settings-path'
268
306
  },
269
- {
270
- name: 'language',
271
- alias: 'l',
272
- description:
273
- '{bold ' +
274
- i18n.__('constantsRequiredCatalogue') +
275
- '}: ' +
276
- i18n.__('constantsLanguage')
277
- },
278
307
  {
279
308
  name: 'organization-id',
280
309
  alias: 'o',
@@ -302,7 +331,6 @@ const auditOptionDefinitions = [
302
331
  },
303
332
  {
304
333
  name: 'host',
305
- alias: 'h',
306
334
  description:
307
335
  '{bold ' +
308
336
  i18n.__('constantsRequired') +
@@ -333,19 +361,38 @@ const auditOptionDefinitions = [
333
361
  '{bold ' +
334
362
  i18n.__('constantsOptional') +
335
363
  '}: ' +
336
- i18n.__('auditOptionsSaveDescription')
364
+ i18n.__('auditOptionsSaveDescription') +
365
+ i18n.__('auditOptionsSaveOptionsDescription')
337
366
  },
338
367
  {
339
368
  name: 'experimental',
340
369
  alias: 'e',
341
370
  type: Boolean
371
+ },
372
+ {
373
+ name: 'timeout',
374
+ alias: 't',
375
+ type: Number,
376
+ description:
377
+ '{bold ' +
378
+ i18n.__('constantsOptional') +
379
+ '}: ' +
380
+ i18n.__('scanOptionsTimeoutSummary')
381
+ },
382
+ {
383
+ name: 'help',
384
+ alias: 'h',
385
+ type: Boolean
342
386
  }
343
387
  ]
344
388
 
345
389
  const mainUsageGuide = commandLineUsage([
346
390
  {
347
391
  header: i18n.__('constantsHeader'),
348
- content: [i18n.__('constantsContrastContent')]
392
+ content: [
393
+ i18n.__('constantsContrastContent'),
394
+ i18n.__('constantsContrastCategories')
395
+ ]
349
396
  },
350
397
  {
351
398
  header: i18n.__('constantsUsage'),
@@ -357,6 +404,7 @@ const mainUsageGuide = commandLineUsage([
357
404
  { name: i18n.__('authName'), summary: i18n.__('helpAuthSummary') },
358
405
  { name: i18n.__('scanName'), summary: i18n.__('helpScanSummary') },
359
406
  { name: i18n.__('lambdaName'), summary: i18n.__('helpLambdaSummary') },
407
+ { name: i18n.__('auditName'), summary: i18n.__('helpAuditSummary') },
360
408
  { name: i18n.__('versionName'), summary: i18n.__('helpVersionSummary') },
361
409
  { name: i18n.__('configName'), summary: i18n.__('helpConfigSummary') },
362
410
  { name: i18n.__('helpName'), summary: i18n.__('helpSummary') }
@@ -365,6 +413,12 @@ const mainUsageGuide = commandLineUsage([
365
413
  {
366
414
  content:
367
415
  '{underline https://developer.contrastsecurity.com/} \n For technical support head to {underline https://support.contrastsecurity.com}'
416
+ },
417
+ {
418
+ header: i18n.__('configHeader2'),
419
+ content: [
420
+ { name: i18n.__('clearHeader'), summary: i18n.__('clearContent') }
421
+ ]
368
422
  }
369
423
  ])
370
424
 
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  isCorrectNodeVersion
15
15
  } from './common/versionChecker'
16
16
  import { findCommandOnError } from './common/errorHandling'
17
+ import { sendTelemetryConfigAsConfObj } from './telemetry/telemetry'
17
18
 
18
19
  const {
19
20
  commandLineDefinitions: { mainUsageGuide, mainDefinition }
@@ -36,74 +37,98 @@ const getMainOption = () => {
36
37
  }
37
38
 
38
39
  const start = async () => {
39
- if (await isCorrectNodeVersion(process.version)) {
40
- const { mainOptions, argv: argvMain } = getMainOption()
41
- const command =
42
- mainOptions.command != undefined ? mainOptions.command.toLowerCase() : ''
43
- if (
44
- command === 'version' ||
45
- argvMain.includes('--v') ||
46
- argvMain.includes('--version')
47
- ) {
48
- console.log(APP_VERSION)
49
- await findLatestCLIVersion(config)
50
- return
51
- }
52
-
53
- // @ts-ignore
54
- config.set('numOfRuns', config.get('numOfRuns') + 1)
55
-
56
- // @ts-ignore
57
- if (config.get('numOfRuns') >= 1) {
58
- await findLatestCLIVersion(config)
59
- config.set('numOfRuns', 0)
60
- }
61
-
62
- if (command === 'config') {
63
- return processConfig(argvMain, config)
64
- }
65
-
66
- if (command === 'auth') {
67
- return await processAuth(argvMain, config)
68
- }
69
-
70
- if (command === 'lambda') {
71
- return await processLambda(argvMain)
72
- }
73
-
74
- if (command === 'scan') {
75
- return await processScan(argvMain)
76
- }
77
-
78
- if (command === 'audit') {
79
- return await processAudit(argvMain)
80
- }
81
-
82
- if (
83
- command === 'help' ||
84
- argvMain.includes('--help') ||
85
- Object.keys(mainOptions).length === 0
86
- ) {
87
- console.log(mainUsageGuide)
88
- } else if (mainOptions._unknown !== undefined) {
89
- const foundCommand = findCommandOnError(mainOptions._unknown)
90
-
91
- foundCommand
92
- ? console.log(
93
- `Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`
94
- )
95
- : console.log(
96
- `Unknown Command: ${command} \nUse --help for the full list`
97
- )
40
+ try {
41
+ if (await isCorrectNodeVersion(process.version)) {
42
+ const { mainOptions, argv: argvMain } = getMainOption()
43
+ const command =
44
+ mainOptions.command != undefined
45
+ ? mainOptions.command.toLowerCase()
46
+ : ''
47
+ if (
48
+ command === 'version' ||
49
+ argvMain.includes('--v') ||
50
+ argvMain.includes('--version')
51
+ ) {
52
+ console.log(APP_VERSION)
53
+ await findLatestCLIVersion(config)
54
+ return
55
+ }
56
+
57
+ // @ts-ignore
58
+ config.set('numOfRuns', config.get('numOfRuns') + 1)
59
+
60
+ // @ts-ignore
61
+ if (config.get('numOfRuns') >= 1) {
62
+ await findLatestCLIVersion(config)
63
+ config.set('numOfRuns', 0)
64
+ }
65
+
66
+ if (command === 'config') {
67
+ return processConfig(argvMain, config)
68
+ }
69
+
70
+ if (command === 'auth') {
71
+ return await processAuth(argvMain, config)
72
+ }
73
+
74
+ if (command === 'lambda') {
75
+ return await processLambda(argvMain)
76
+ }
77
+
78
+ if (command === 'scan') {
79
+ return await processScan(config, argvMain)
80
+ }
81
+
82
+ if (command === 'audit') {
83
+ return await processAudit(config, argvMain)
84
+ }
85
+
86
+ if (
87
+ command === 'help' ||
88
+ argvMain.includes('--help') ||
89
+ Object.keys(mainOptions).length === 0
90
+ ) {
91
+ console.log(mainUsageGuide)
92
+ } else if (mainOptions._unknown !== undefined) {
93
+ const foundCommand = findCommandOnError(mainOptions._unknown)
94
+
95
+ foundCommand
96
+ ? console.log(
97
+ `Unknown Command: Did you mean "${foundCommand}"? \nUse "${foundCommand} --help" for the full list of options`
98
+ )
99
+ : console.log(
100
+ `Unknown Command: ${command} \nUse --help for the full list`
101
+ )
102
+ await sendTelemetryConfigAsConfObj(
103
+ config,
104
+ command,
105
+ argvMain,
106
+ 'FAILURE',
107
+ 'undefined'
108
+ )
109
+ } else {
110
+ console.log(
111
+ `Unknown Command: ${command} \nUse --help for the full list`
112
+ )
113
+ await sendTelemetryConfigAsConfObj(
114
+ config,
115
+ command,
116
+ argvMain,
117
+ 'FAILURE',
118
+ 'undefined'
119
+ )
120
+ }
121
+ process.exit(9)
98
122
  } else {
99
- console.log(`Unknown Command: ${command} \nUse --help for the full list`)
123
+ console.log(
124
+ 'Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.'
125
+ )
126
+ process.exit(9)
100
127
  }
101
- process.exit(9)
102
- } else {
103
- console.log(
104
- 'Contrast supports Node versions >=16.13.2 <17. Please use one of those versions.'
105
- )
106
- process.exit(9)
128
+ } catch (err: any) {
129
+ console.log()
130
+ console.log(err.message.toString())
131
+ process.exit(1)
107
132
  }
108
133
  }
109
134
 
@@ -16,6 +16,7 @@ import { sleep } from '../utils/requestUtils'
16
16
  import ora from '../utils/oraWrapper'
17
17
  import { postAnalytics } from './analytics'
18
18
  import { LambdaOptions, AnalyticsOption, StatusType, EventType } from './types'
19
+ import { APP_VERSION } from '../constants/constants'
19
20
 
20
21
  type ApiParams = {
21
22
  organizationId: string
@@ -73,7 +74,8 @@ const processLambda = async (argv: string[]) => {
73
74
  const startCommandAnalytics: AnalyticsOption = {
74
75
  arguments: lambdaOptions,
75
76
  sessionId: commandSessionId,
76
- eventType: EventType.START
77
+ eventType: EventType.START,
78
+ packageVersion: APP_VERSION
77
79
  }
78
80
  postAnalytics(startCommandAnalytics).catch((error: Error) => {
79
81
  /* ignore */
@@ -99,7 +101,8 @@ const processLambda = async (argv: string[]) => {
99
101
  const endCommandAnalytics: AnalyticsOption = {
100
102
  sessionId: commandSessionId,
101
103
  eventType: EventType.END,
102
- status: errorMsg ? StatusType.FAILED : StatusType.SUCCESS
104
+ status: errorMsg ? StatusType.FAILED : StatusType.SUCCESS,
105
+ packageVersion: APP_VERSION
103
106
  }
104
107
  if (errorMsg) {
105
108
  endCommandAnalytics.errorMsg = errorMsg
@@ -28,6 +28,7 @@ type ScanFunctionData = {
28
28
  export type AnalyticsOption = {
29
29
  sessionId: string
30
30
  eventType: EventType
31
+ packageVersion: string
31
32
  arguments?: LambdaOptions
32
33
  scanFunctionData?: ScanFunctionData
33
34
  status?: StatusType
@@ -1,9 +1,9 @@
1
1
  import { getHttpClient } from '../utils/commonApi'
2
2
 
3
- export const generateSbom = (config: any) => {
3
+ export const generateSbom = (config: any, type: string) => {
4
4
  const client = getHttpClient(config)
5
5
  return client
6
- .getSbom(config)
6
+ .getSbom(config, type)
7
7
  .then((res: { statusCode: number; body: any }) => {
8
8
  if (res.statusCode === 200) {
9
9
  return res.body
@@ -50,11 +50,18 @@ const createPhpTSMessage = phpTree => {
50
50
  }
51
51
  }
52
52
 
53
+ const createDotNetTSMessage = dotnetTree => {
54
+ return {
55
+ dotnet: dotnetTree
56
+ }
57
+ }
58
+
53
59
  module.exports = {
54
60
  createJavaScriptTSMessage,
55
61
  createJavaTSMessage,
56
62
  createGoTSMessage,
57
63
  createPhpTSMessage,
58
64
  createRubyTSMessage,
59
- createPythonTSMessage
65
+ createPythonTSMessage,
66
+ createDotNetTSMessage
60
67
  }
@@ -0,0 +1,41 @@
1
+ const parseDependenciesForSCAServices = dependencyTreeObject => {
2
+ let parsedDependencyTree = {}
3
+ let subDeps
4
+
5
+ for (let tree in dependencyTreeObject) {
6
+ let unParsedDependencyTree = dependencyTreeObject[tree]
7
+ for (let dependency in unParsedDependencyTree) {
8
+ subDeps = parseSubDependencies(unParsedDependencyTree[dependency].edges)
9
+
10
+ let parsedDependency = {
11
+ name: unParsedDependencyTree[dependency].artifactID,
12
+ group: unParsedDependencyTree[dependency].group,
13
+ version: unParsedDependencyTree[dependency].version,
14
+ directDependency: unParsedDependencyTree[dependency].type === 'direct',
15
+ isProduction: true,
16
+ dependencies: subDeps
17
+ }
18
+ parsedDependencyTree[dependency] = parsedDependency
19
+ }
20
+ }
21
+ return parsedDependencyTree
22
+ }
23
+
24
+ const parseSubDependencies = dependencies => {
25
+ // converting:
26
+ // dependencies: {
27
+ // 'gopkg.in/check.v1@v0.0.0-2': 'gopkg.in/check.v1@v0.0.0-2'
28
+ // }
29
+ // to:
30
+ // dependencies: [ 'gopkg.in/check.v1@v0.0.0-2' ]
31
+ let subDeps = []
32
+ for (let x in dependencies) {
33
+ subDeps.push(dependencies[x])
34
+ }
35
+ return subDeps
36
+ }
37
+
38
+ module.exports = {
39
+ parseDependenciesForSCAServices,
40
+ parseSubDependencies
41
+ }