snyk 1.803.0 → 1.807.0

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 (31) hide show
  1. package/README.md +5 -3
  2. package/dist/cli/293.index.js +108 -50
  3. package/dist/cli/293.index.js.map +1 -1
  4. package/dist/cli/727.index.js +12 -16
  5. package/dist/cli/727.index.js.map +1 -1
  6. package/dist/cli/85.index.js +6 -2
  7. package/dist/cli/85.index.js.map +1 -1
  8. package/dist/cli/thirdPartyNotice.json +2 -2
  9. package/dist/lib/plugins/sast/analysis.d.ts +2 -2
  10. package/dist/lib/plugins/sast/checks.d.ts +1 -17
  11. package/dist/lib/plugins/sast/errors/index.d.ts +2 -0
  12. package/dist/lib/plugins/sast/errors/missing-configuration-error.d.ts +5 -0
  13. package/dist/lib/plugins/sast/format/output-format.d.ts +2 -2
  14. package/dist/lib/plugins/sast/settings.d.ts +3 -0
  15. package/dist/lib/plugins/sast/types.d.ts +17 -0
  16. package/help/README.md +1 -1
  17. package/help/cli-commands/{snyk.md → README.md} +15 -11
  18. package/help/cli-commands/{snyk-auth.md → auth.md} +0 -0
  19. package/help/cli-commands/{snyk-code.md → code.md} +0 -0
  20. package/help/cli-commands/{snyk-config.md → config.md} +0 -0
  21. package/help/cli-commands/{snyk-container.md → container.md} +0 -0
  22. package/help/cli-commands/{snyk-iac.md → iac.md} +0 -0
  23. package/help/cli-commands/{snyk-ignore.md → ignore.md} +0 -0
  24. package/help/cli-commands/{snyk-log4shell.md → log4shell.md} +1 -1
  25. package/help/cli-commands/{snyk-monitor.md → monitor.md} +0 -0
  26. package/help/cli-commands/{snyk-policy.md → policy.md} +0 -0
  27. package/help/cli-commands/{snyk-protect.md → protect.md} +0 -0
  28. package/help/cli-commands/{snyk-test.md → test.md} +0 -0
  29. package/help/cli-commands/{snyk-wizard.md → wizard.md} +0 -0
  30. package/package.json +2 -2
  31. package/dist/lib/plugins/sast/validate.d.ts +0 -2
package/README.md CHANGED
@@ -160,12 +160,14 @@ Snyk also offers many integrations into developer tooling. These integrations wi
160
160
 
161
161
  # Getting started with Snyk CLI
162
162
 
163
- Once you installed the Snyk CLI, you can verify it's working by running
163
+ Once you installed the Snyk CLI, you can verify it's working by running:
164
164
 
165
165
  ```bash
166
- snyk --version
166
+ snyk --help
167
167
  ```
168
168
 
169
+ See the [full Snyk CLI help](./help/cli-commands).
170
+
169
171
  ## Authorization
170
172
 
171
173
  Snyk CLI depends on [Snyk.io](https://snyk.io) APIs. Connect your Snyk CLI with [Snyk.io](https://snyk.io) by running:
@@ -246,7 +248,7 @@ Here are some flags that you might find useful:
246
248
 
247
249
  Auto-detect all projects in working directory
248
250
 
249
- See all the available commands and options by running `--help`:
251
+ [See all the available commands and options](./help/cli-commands) by running `--help`:
250
252
 
251
253
  ```bash
252
254
  snyk --help
@@ -4684,19 +4684,26 @@ const api_token_1 = __webpack_require__(95181);
4684
4684
  const config_1 = __webpack_require__(22541);
4685
4685
  const spinner_1 = __webpack_require__(86766);
4686
4686
  const utils_1 = __webpack_require__(33113);
4687
- const unsupported_feature_snyk_code_error_1 = __webpack_require__(90551);
4687
+ const errors_1 = __webpack_require__(61315);
4688
4688
  const proxy_from_env_1 = __webpack_require__(21394);
4689
4689
  const global_agent_1 = __webpack_require__(97959);
4690
- async function getCodeAnalysisAndParseResults(root, options) {
4690
+ async function getCodeAnalysisAndParseResults(root, options, sastSettings) {
4691
4691
  await spinner_1.spinner.clearAll();
4692
4692
  utils_1.analysisProgressUpdate();
4693
- const codeAnalysis = await getCodeAnalysis(root, options);
4693
+ const codeAnalysis = await getCodeAnalysis(root, options, sastSettings);
4694
4694
  spinner_1.spinner.clearAll();
4695
4695
  return parseSecurityResults(codeAnalysis);
4696
4696
  }
4697
4697
  exports.getCodeAnalysisAndParseResults = getCodeAnalysisAndParseResults;
4698
- async function getCodeAnalysis(root, options) {
4699
- const baseURL = config_1.default.CODE_CLIENT_PROXY_URL;
4698
+ async function getCodeAnalysis(root, options, sastSettings) {
4699
+ const isLocalCodeEngineEnabled = isLocalCodeEngine(sastSettings);
4700
+ if (isLocalCodeEngineEnabled) {
4701
+ validateLocalCodeEngineUrl(sastSettings.localCodeEngine.url);
4702
+ }
4703
+ const source = 'snyk-cli';
4704
+ const baseURL = isLocalCodeEngineEnabled
4705
+ ? sastSettings.localCodeEngine.url
4706
+ : config_1.default.CODE_CLIENT_PROXY_URL;
4700
4707
  // TODO(james) This mirrors the implementation in request.ts and we need to use this for deeproxy calls
4701
4708
  // This ensures we support lowercase http(s)_proxy values as well
4702
4709
  // The weird IF around it ensures we don't create an envvar with
@@ -4719,9 +4726,15 @@ async function getCodeAnalysis(root, options) {
4719
4726
  ? severityToAnalysisSeverity(options.severityThreshold)
4720
4727
  : code_client_1.AnalysisSeverity.info;
4721
4728
  const result = await code_client_1.analyzeFolders({
4722
- connection: { baseURL, sessionToken, source: 'snyk-cli' },
4729
+ connection: { baseURL, sessionToken, source },
4723
4730
  analysisOptions: { severity },
4724
4731
  fileOptions: { paths: [root] },
4732
+ analysisContext: {
4733
+ initiator: 'CLI',
4734
+ flow: source,
4735
+ orgDisplayName: config_1.default.org,
4736
+ projectName: config_1.default.PROJECT_NAME,
4737
+ },
4725
4738
  });
4726
4739
  if ((result === null || result === void 0 ? void 0 : result.analysisResults.type) === 'sarif') {
4727
4740
  return result.analysisResults.sarif;
@@ -4730,7 +4743,7 @@ async function getCodeAnalysis(root, options) {
4730
4743
  }
4731
4744
  function severityToAnalysisSeverity(severity) {
4732
4745
  if (severity === legacy_1.SEVERITY.CRITICAL) {
4733
- throw new unsupported_feature_snyk_code_error_1.FeatureNotSupportedBySnykCodeError(legacy_1.SEVERITY.CRITICAL);
4746
+ throw new errors_1.FeatureNotSupportedBySnykCodeError(legacy_1.SEVERITY.CRITICAL);
4734
4747
  }
4735
4748
  const severityLevel = {
4736
4749
  low: 1,
@@ -4777,6 +4790,15 @@ function getSecurityResultsOnly(results, securityRules) {
4777
4790
  }, []);
4778
4791
  return securityResults;
4779
4792
  }
4793
+ function isLocalCodeEngine(sastSettings) {
4794
+ const { sastEnabled, localCodeEngine } = sastSettings;
4795
+ return sastEnabled && localCodeEngine.enabled;
4796
+ }
4797
+ function validateLocalCodeEngineUrl(localCodeEngineUrl) {
4798
+ if (localCodeEngineUrl.length === 0) {
4799
+ throw new errors_1.MissingConfigurationError('Local Code Engine');
4800
+ }
4801
+ }
4780
4802
 
4781
4803
 
4782
4804
  /***/ }),
@@ -4822,6 +4844,41 @@ async function trackUsage(org) {
4822
4844
  exports.trackUsage = trackUsage;
4823
4845
 
4824
4846
 
4847
+ /***/ }),
4848
+
4849
+ /***/ 61315:
4850
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4851
+
4852
+ "use strict";
4853
+
4854
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4855
+ var missing_configuration_error_1 = __webpack_require__(73016);
4856
+ Object.defineProperty(exports, "MissingConfigurationError", ({ enumerable: true, get: function () { return missing_configuration_error_1.MissingConfigurationError; } }));
4857
+ var unsupported_feature_snyk_code_error_1 = __webpack_require__(90551);
4858
+ Object.defineProperty(exports, "FeatureNotSupportedBySnykCodeError", ({ enumerable: true, get: function () { return unsupported_feature_snyk_code_error_1.FeatureNotSupportedBySnykCodeError; } }));
4859
+
4860
+
4861
+ /***/ }),
4862
+
4863
+ /***/ 73016:
4864
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4865
+
4866
+ "use strict";
4867
+
4868
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4869
+ exports.MissingConfigurationError = void 0;
4870
+ const custom_error_1 = __webpack_require__(17188);
4871
+ class MissingConfigurationError extends custom_error_1.CustomError {
4872
+ constructor(action, additionalUserHelp = '') {
4873
+ super(`Missing configuration for ${action}.`);
4874
+ this.code = 422;
4875
+ this.action = action;
4876
+ this.userMessage = `'Configuration is missing or wrong for ${action}'. ${additionalUserHelp}`;
4877
+ }
4878
+ }
4879
+ exports.MissingConfigurationError = MissingConfigurationError;
4880
+
4881
+
4825
4882
  /***/ }),
4826
4883
 
4827
4884
  /***/ 90551:
@@ -4973,7 +5030,7 @@ exports.codePlugin = void 0;
4973
5030
  const chalk_1 = __webpack_require__(32589);
4974
5031
  const debugLib = __webpack_require__(15158);
4975
5032
  const analysis_1 = __webpack_require__(2806);
4976
- const validate_1 = __webpack_require__(33362);
5033
+ const settings_1 = __webpack_require__(24930);
4977
5034
  const output_format_1 = __webpack_require__(75802);
4978
5035
  const errors_1 = __webpack_require__(55191);
4979
5036
  const json_1 = __webpack_require__(27019);
@@ -4992,10 +5049,10 @@ exports.codePlugin = {
4992
5049
  var _a, _b;
4993
5050
  try {
4994
5051
  analytics.add('sast-scan', true);
4995
- await validate_1.validateCodeTest(options);
5052
+ const sastSettings = await settings_1.getSastSettings(options);
4996
5053
  // Currently code supports only one path
4997
5054
  const path = paths[0];
4998
- const sarifTypedResult = await analysis_1.getCodeAnalysisAndParseResults(path, options);
5055
+ const sarifTypedResult = await analysis_1.getCodeAnalysisAndParseResults(path, options, sastSettings);
4999
5056
  if (!sarifTypedResult) {
5000
5057
  throw new errors_1.NoSupportedSastFiles();
5001
5058
  }
@@ -5053,6 +5110,47 @@ function hasIssues(readableResult) {
5053
5110
  }
5054
5111
 
5055
5112
 
5113
+ /***/ }),
5114
+
5115
+ /***/ 24930:
5116
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
5117
+
5118
+ "use strict";
5119
+
5120
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
5121
+ exports.getSastSettings = void 0;
5122
+ const config_1 = __webpack_require__(22541);
5123
+ const checks_1 = __webpack_require__(15976);
5124
+ const errors_1 = __webpack_require__(55191);
5125
+ async function getSastSettings(options) {
5126
+ const org = options.org || config_1.default.org;
5127
+ // This is an unexpected path, code plugin executed for non-code command.
5128
+ if (!options.code) {
5129
+ throw new errors_1.FeatureNotSupportedForOrgError(org);
5130
+ }
5131
+ const sastSettingsResponse = await checks_1.getSastSettingsForOrg(org);
5132
+ if ((sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 401 ||
5133
+ (sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 403) {
5134
+ throw errors_1.AuthFailedError(sastSettingsResponse.error, sastSettingsResponse.code);
5135
+ }
5136
+ if ((sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 404) {
5137
+ throw new errors_1.NotFoundError(sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.userMessage);
5138
+ }
5139
+ if (!sastSettingsResponse.sastEnabled) {
5140
+ throw new errors_1.FeatureNotSupportedForOrgError(org, 'Snyk Code', 'enable in Settings > Snyk Code');
5141
+ }
5142
+ if (sastSettingsResponse.localCodeEngine.enabled) {
5143
+ throw new errors_1.CustomError('Snyk Code Local Engine is enabled, Snyk Code CLI is temporary disabled.');
5144
+ }
5145
+ const trackUsageResponse = await checks_1.trackUsage(org);
5146
+ if (trackUsageResponse.code === 429) {
5147
+ throw new errors_1.FailedToRunTestError(trackUsageResponse.userMessage, trackUsageResponse.code);
5148
+ }
5149
+ return sastSettingsResponse;
5150
+ }
5151
+ exports.getSastSettings = getSastSettings;
5152
+
5153
+
5056
5154
  /***/ }),
5057
5155
 
5058
5156
  /***/ 33113:
@@ -5097,46 +5195,6 @@ function analysisProgressUpdate() {
5097
5195
  exports.analysisProgressUpdate = analysisProgressUpdate;
5098
5196
 
5099
5197
 
5100
- /***/ }),
5101
-
5102
- /***/ 33362:
5103
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
5104
-
5105
- "use strict";
5106
-
5107
- Object.defineProperty(exports, "__esModule", ({ value: true }));
5108
- exports.validateCodeTest = void 0;
5109
- const config_1 = __webpack_require__(22541);
5110
- const checks_1 = __webpack_require__(15976);
5111
- const errors_1 = __webpack_require__(55191);
5112
- async function validateCodeTest(options) {
5113
- const org = options.org || config_1.default.org;
5114
- // This is an unexpected path, code plugin executed for non-code command.
5115
- if (!options.code) {
5116
- throw new errors_1.FeatureNotSupportedForOrgError(org);
5117
- }
5118
- const sastSettingsResponse = await checks_1.getSastSettingsForOrg(org);
5119
- if ((sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 401 ||
5120
- (sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 403) {
5121
- throw errors_1.AuthFailedError(sastSettingsResponse.error, sastSettingsResponse.code);
5122
- }
5123
- if ((sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.code) === 404) {
5124
- throw new errors_1.NotFoundError(sastSettingsResponse === null || sastSettingsResponse === void 0 ? void 0 : sastSettingsResponse.userMessage);
5125
- }
5126
- if (!sastSettingsResponse.sastEnabled) {
5127
- throw new errors_1.FeatureNotSupportedForOrgError(org, 'Snyk Code', 'enable in Settings > Snyk Code');
5128
- }
5129
- if (sastSettingsResponse.localCodeEngine.enabled) {
5130
- throw new errors_1.CustomError('Snyk Code Local Engine is enabled, Snyk Code CLI is temporary disabled.');
5131
- }
5132
- const trackUsageResponse = await checks_1.trackUsage(org);
5133
- if (trackUsageResponse.code === 429) {
5134
- throw new errors_1.FailedToRunTestError(trackUsageResponse.userMessage, trackUsageResponse.code);
5135
- }
5136
- }
5137
- exports.validateCodeTest = validateCodeTest;
5138
-
5139
-
5140
5198
  /***/ }),
5141
5199
 
5142
5200
  /***/ 8820: