snyk 1.777.0 → 1.781.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.
@@ -53,22 +53,25 @@ const types_1 = __webpack_require__(42258);
53
53
  const analytics = __webpack_require__(82744);
54
54
  const math_utils_1 = __webpack_require__(48537);
55
55
  const file_utils_1 = __webpack_require__(58486);
56
- function addIacAnalytics(formattedResults, ignoredIssuesCount, isLocalCustomRules) {
56
+ function addIacAnalytics(formattedResults, ignoredIssuesCount) {
57
57
  let totalIssuesCount = 0;
58
58
  const customRulesIdsFoundInIssues = {};
59
59
  let issuesFromCustomRulesCount = 0;
60
- const issuesByType = {};
60
+ const projectTypeAnalytics = {};
61
61
  const packageManagers = Array();
62
62
  formattedResults.forEach((res) => {
63
+ var _a;
63
64
  totalIssuesCount =
64
65
  (totalIssuesCount || 0) + res.result.cloudConfigResults.length;
65
- const packageManagerConfig = res.packageManager;
66
- packageManagers.push(packageManagerConfig);
66
+ const projectType = res.packageManager;
67
+ packageManagers.push(projectType);
68
+ projectTypeAnalytics[projectType] = (_a = projectTypeAnalytics[projectType]) !== null && _a !== void 0 ? _a : {
69
+ count: 0,
70
+ };
71
+ projectTypeAnalytics[projectType]['count']++;
67
72
  res.result.cloudConfigResults.forEach((policy) => {
68
- var _a;
69
- issuesByType[packageManagerConfig] = (_a = issuesByType[packageManagerConfig]) !== null && _a !== void 0 ? _a : {};
70
- issuesByType[packageManagerConfig][policy.severity] =
71
- (issuesByType[packageManagerConfig][policy.severity] || 0) + 1;
73
+ projectTypeAnalytics[projectType][policy.severity] =
74
+ (projectTypeAnalytics[projectType][policy.severity] || 0) + 1;
72
75
  if (policy.isGeneratedByCustomRule) {
73
76
  issuesFromCustomRulesCount++;
74
77
  customRulesIdsFoundInIssues[policy.publicId] = true;
@@ -79,14 +82,12 @@ function addIacAnalytics(formattedResults, ignoredIssuesCount, isLocalCustomRule
79
82
  analytics.add('packageManager', Array.from(new Set(packageManagers)));
80
83
  analytics.add('iac-issues-count', totalIssuesCount);
81
84
  analytics.add('iac-ignored-issues-count', ignoredIssuesCount);
82
- analytics.add('iac-type', issuesByType);
85
+ analytics.add('iac-type', projectTypeAnalytics);
83
86
  analytics.add('iac-metrics', exports.performanceAnalyticsObject);
84
87
  analytics.add('iac-test-count', formattedResults.length);
85
88
  analytics.add('iac-custom-rules-issues-count', issuesFromCustomRulesCount);
86
89
  analytics.add('iac-custom-rules-issues-percentage', math_utils_1.calculatePercentage(issuesFromCustomRulesCount, totalIssuesCount));
87
- if (!isLocalCustomRules) {
88
- analytics.add('iac-custom-rules-checksum', file_utils_1.computeCustomRulesBundleChecksum());
89
- }
90
+ analytics.add('iac-custom-rules-checksum', file_utils_1.computeCustomRulesBundleChecksum());
90
91
  analytics.add('iac-custom-rules-coverage-count', uniqueCustomRulesCount);
91
92
  }
92
93
  exports.addIacAnalytics = addIacAnalytics;
@@ -679,7 +680,6 @@ const analytics_1 = __webpack_require__(22716);
679
680
  const usage_tracking_1 = __webpack_require__(43156);
680
681
  const policy_1 = __webpack_require__(25476);
681
682
  const measurable_methods_1 = __webpack_require__(78272);
682
- const feature_flags_1 = __webpack_require__(63011);
683
683
  const assert_iac_options_flag_1 = __webpack_require__(68590);
684
684
  const user_config_1 = __webpack_require__(28137);
685
685
  const config_1 = __webpack_require__(22541);
@@ -687,26 +687,33 @@ const policy_2 = __webpack_require__(32615);
687
687
  const errors_1 = __webpack_require__(55191);
688
688
  const error_utils_1 = __webpack_require__(23872);
689
689
  const oci_pull_1 = __webpack_require__(5029);
690
- const unsupported_entitlement_error_1 = __webpack_require__(78673);
691
690
  const url_utils_1 = __webpack_require__(80256);
691
+ const chalk_1 = __webpack_require__(32589);
692
692
  // this method executes the local processing engine and then formats the results to adapt with the CLI output.
693
693
  // this flow is the default GA flow for IAC scanning.
694
694
  async function test(pathToScan, options) {
695
- var _a;
695
+ var _a, _b, _c;
696
696
  try {
697
697
  let customRulesPath;
698
698
  const orgPublicId = (_a = options.org) !== null && _a !== void 0 ? _a : config_1.default.org;
699
699
  const iacOrgSettings = await measurable_methods_1.getIacOrgSettings(orgPublicId);
700
700
  if (options.rules) {
701
- await assertRulesFlagAvailable(orgPublicId, iacOrgSettings);
701
+ if (!((_b = iacOrgSettings.entitlements) === null || _b === void 0 ? void 0 : _b.iacCustomRulesEntitlement)) {
702
+ throw new assert_iac_options_flag_1.UnsupportedEntitlementFlagError('rules', 'iacCustomRulesEntitlement');
703
+ }
702
704
  customRulesPath = options.rules;
703
705
  }
704
706
  const isOCIRegistryURLProvided = checkOCIRegistryURLProvided(iacOrgSettings);
707
+ if (isOCIRegistryURLProvided || customRulesPath) {
708
+ console.log(chalk_1.default.hex('#ff9b00')('Using custom rules to generate misconfigurations.'));
709
+ }
705
710
  if (isOCIRegistryURLProvided && customRulesPath) {
706
711
  throw new FailedToExecuteCustomRulesError();
707
712
  }
708
713
  if (isOCIRegistryURLProvided) {
709
- await assertPullAvailable(orgPublicId, iacOrgSettings);
714
+ if (!((_c = iacOrgSettings.entitlements) === null || _c === void 0 ? void 0 : _c.iacCustomRulesEntitlement)) {
715
+ throw new oci_pull_1.UnsupportedEntitlementPullError('iacCustomRulesEntitlement');
716
+ }
710
717
  await pullIaCCustomRules(iacOrgSettings);
711
718
  }
712
719
  else {
@@ -736,7 +743,7 @@ async function test(pathToScan, options) {
736
743
  // If something has gone wrong, err on the side of allowing the user to
737
744
  // run their tests by squashing the error.
738
745
  }
739
- analytics_1.addIacAnalytics(filteredIssues, ignoreCount, !!customRulesPath);
746
+ analytics_1.addIacAnalytics(filteredIssues, ignoreCount);
740
747
  // TODO: add support for proper typing of old TestResult interface.
741
748
  return {
742
749
  results: filteredIssues,
@@ -829,7 +836,7 @@ async function pullIaCCustomRules(iacOrgSettings) {
829
836
  throw new FailedToPullCustomBundleError('There was an authentication error. Incorrect credentials provided.');
830
837
  }
831
838
  else if (err.statusCode === 404) {
832
- throw new FailedToPullCustomBundleError('The remote repository could not be found. Please check the provided URL.');
839
+ throw new FailedToPullCustomBundleError('The remote repository could not be found. Please check the provided registry URL.');
833
840
  }
834
841
  else if (err instanceof oci_pull_1.InvalidManifestSchemaVersionError) {
835
842
  throw new FailedToPullCustomBundleError(err.message);
@@ -846,62 +853,15 @@ async function pullIaCCustomRules(iacOrgSettings) {
846
853
  }
847
854
  }
848
855
  exports.pullIaCCustomRules = pullIaCCustomRules;
849
- /**
850
- * Asserts the custom-rules feature is available for the provided org.
851
- */
852
- async function assertCustomRulesAvailable(orgPublicId, iacOrgSettings) {
853
- var _a;
854
- const isCustomRulesEnabled = !!(await feature_flags_1.isFeatureFlagSupportedForOrg('iacCustomRules', orgPublicId)).ok;
855
- if (!isCustomRulesEnabled) {
856
- throw new errors_1.UnsupportedFeatureFlagError('iacCustomRules');
857
- }
858
- const isEntitledToCustomRules = !!((_a = iacOrgSettings.entitlements) === null || _a === void 0 ? void 0 : _a.iacCustomRulesEntitlement);
859
- if (!isEntitledToCustomRules) {
860
- throw new unsupported_entitlement_error_1.UnsupportedEntitlementError('iacCustomRulesEntitlement');
861
- }
862
- }
863
- /**
864
- * Asserts the --rules flag is available for the provided org.
865
- */
866
- async function assertRulesFlagAvailable(orgPublicId, iacOrgSettings) {
867
- try {
868
- await assertCustomRulesAvailable(orgPublicId, iacOrgSettings);
869
- }
870
- catch (err) {
871
- if (err instanceof unsupported_entitlement_error_1.UnsupportedEntitlementError) {
872
- throw new assert_iac_options_flag_1.UnsupportedEntitlementFlagError('rules', err.entitlement);
873
- }
874
- else if (err instanceof errors_1.UnsupportedFeatureFlagError) {
875
- throw new assert_iac_options_flag_1.FlagError('rules', err.featureFlag);
876
- }
877
- else {
878
- throw err;
879
- }
880
- }
881
- }
882
- /**
883
- * Asserts the feature custom-rules bundles pulling feature is available for the provided org.
884
- */
885
- async function assertPullAvailable(orgPublicId, iacOrgSettings) {
886
- try {
887
- await assertCustomRulesAvailable(orgPublicId, iacOrgSettings);
888
- }
889
- catch (err) {
890
- if (err instanceof unsupported_entitlement_error_1.UnsupportedEntitlementError) {
891
- throw new oci_pull_1.UnsupportedEntitlementPullError(err.entitlement);
892
- }
893
- else if (err instanceof errors_1.UnsupportedFeatureFlagError) {
894
- throw new oci_pull_1.UnsupportedFeatureFlagPullError(err.featureFlag);
895
- }
896
- }
897
- }
898
856
  class FailedToPullCustomBundleError extends errors_1.CustomError {
899
857
  constructor(message) {
900
858
  super(message || 'Could not pull custom bundle');
901
859
  this.code = types_1.IaCErrorCodes.FailedToPullCustomBundleError;
902
860
  this.strCode = error_utils_1.getErrorStringCode(this.code);
903
- this.userMessage = `${message ? message + ' ' : ''}
904
- We were unable to download the custom bundle to the disk. Please ensure access to the remote Registry and validate you have provided all the right parameters.`;
861
+ this.userMessage =
862
+ `${message ? message + ' ' : ''}` +
863
+ '\nWe were unable to download the custom bundle to the disk. Please ensure access to the remote Registry and validate you have provided all the right parameters.' +
864
+ '\nSee documentation on troubleshooting: https://docs.snyk.io/products/snyk-infrastructure-as-code/custom-rules/use-IaC-custom-rules-with-CLI/using-a-remote-custom-rules-bundle#troubleshooting';
905
865
  }
906
866
  }
907
867
  exports.FailedToPullCustomBundleError = FailedToPullCustomBundleError;
@@ -1188,7 +1148,7 @@ exports.pull = measurableOciPull;
1188
1148
  "use strict";
1189
1149
 
1190
1150
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1191
- exports.UnsupportedEntitlementPullError = exports.UnsupportedFeatureFlagPullError = exports.InvalidRemoteRegistryURLError = exports.InvalidManifestSchemaVersionError = exports.FailedToBuildOCIArtifactError = exports.pull = exports.extractOCIRegistryURLComponents = exports.CUSTOM_RULES_TARBALL = void 0;
1151
+ exports.UnsupportedEntitlementPullError = exports.InvalidRemoteRegistryURLError = exports.InvalidManifestSchemaVersionError = exports.FailedToBuildOCIArtifactError = exports.pull = exports.extractOCIRegistryURLComponents = exports.CUSTOM_RULES_TARBALL = void 0;
1192
1152
  const registryClient = __webpack_require__(28310);
1193
1153
  const fs_1 = __webpack_require__(35747);
1194
1154
  const path = __webpack_require__(85622);
@@ -1286,15 +1246,6 @@ class InvalidRemoteRegistryURLError extends errors_1.CustomError {
1286
1246
  }
1287
1247
  }
1288
1248
  exports.InvalidRemoteRegistryURLError = InvalidRemoteRegistryURLError;
1289
- class UnsupportedFeatureFlagPullError extends errors_1.CustomError {
1290
- constructor(featureFlag) {
1291
- super('OCI Pull not supported - Missing the ${featureFlag} feature flag');
1292
- this.code = types_1.IaCErrorCodes.UnsupportedFeatureFlagPullError;
1293
- this.strCode = error_utils_1.getErrorStringCode(this.code);
1294
- this.userMessage = `The custom rules feature is not supported for this org - The feature flag '${featureFlag}' is not currently enabled. It can be enabled via Snyk Preview, if you are on the Enterprise Plan.`;
1295
- }
1296
- }
1297
- exports.UnsupportedFeatureFlagPullError = UnsupportedFeatureFlagPullError;
1298
1249
  class UnsupportedEntitlementPullError extends errors_1.CustomError {
1299
1250
  constructor(entitlement) {
1300
1251
  super(`OCI Pull not supported - Missing the ${entitlement} entitlement`);
@@ -1740,7 +1691,9 @@ function formatScanResult(scanResult, meta, options) {
1740
1691
  },
1741
1692
  severity: policy.severity,
1742
1693
  lineNumber,
1743
- documentation: `https://snyk.io/security-rules/${policy.publicId}`,
1694
+ documentation: !isGeneratedByCustomRule
1695
+ ? `https://snyk.io/security-rules/${policy.publicId}`
1696
+ : undefined,
1744
1697
  isGeneratedByCustomRule,
1745
1698
  };
1746
1699
  });
@@ -1987,6 +1940,7 @@ exports.test = test;
1987
1940
 
1988
1941
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1989
1942
  const Debug = __webpack_require__(15158);
1943
+ const os_1 = __webpack_require__(12087);
1990
1944
  const cloneDeep = __webpack_require__(83465);
1991
1945
  const assign = __webpack_require__(31730);
1992
1946
  const chalk_1 = __webpack_require__(32589);
@@ -2007,6 +1961,8 @@ const set_default_test_options_1 = __webpack_require__(13285);
2007
1961
  const process_command_args_1 = __webpack_require__(52369);
2008
1962
  const format_test_error_1 = __webpack_require__(68214);
2009
1963
  const display_result_1 = __webpack_require__(89667);
1964
+ const analytics = __webpack_require__(82744);
1965
+ const protect_update_notification_1 = __webpack_require__(79304);
2010
1966
  const debug = Debug('snyk-test');
2011
1967
  const SEPARATOR = '\n-------------------------------------------------------\n';
2012
1968
  // TODO: avoid using `as any` whenever it's possible
@@ -2015,6 +1971,8 @@ async function test(...args) {
2015
1971
  const options = set_default_test_options_1.setDefaultTestOptions(originalOptions);
2016
1972
  validate_test_options_1.validateTestOptions(options);
2017
1973
  validate_credentials_1.validateCredentials(options);
1974
+ const packageJsonPathsWithSnykDepForProtect = protect_update_notification_1.getPackageJsonPathsContainingSnykDependency(options.file, paths);
1975
+ analytics.add('upgradable-snyk-protect-paths', packageJsonPathsWithSnykDepForProtect.length);
2018
1976
  // Handles no image arg provided to the container command until
2019
1977
  // a validation interface is implemented in the docker plugin.
2020
1978
  if (options.docker && paths.length === 0) {
@@ -2180,6 +2138,8 @@ async function test(...args) {
2180
2138
  if (!fail) {
2181
2139
  // return here to prevent throwing failure
2182
2140
  response += chalk_1.default.bold.green(summaryMessage);
2141
+ response += os_1.EOL + os_1.EOL;
2142
+ response += protect_update_notification_1.getProtectUpgradeWarningForPaths(packageJsonPathsWithSnykDepForProtect);
2183
2143
  return types_1.TestCommandResult.createHumanReadableTestCommandResult(response, stringifiedJsonData, stringifiedSarifData);
2184
2144
  }
2185
2145
  }
@@ -2196,6 +2156,8 @@ async function test(...args) {
2196
2156
  throw error;
2197
2157
  }
2198
2158
  response += chalk_1.default.bold.green(summaryMessage);
2159
+ response += os_1.EOL + os_1.EOL;
2160
+ response += protect_update_notification_1.getProtectUpgradeWarningForPaths(packageJsonPathsWithSnykDepForProtect);
2199
2161
  return types_1.TestCommandResult.createHumanReadableTestCommandResult(response, stringifiedJsonData, stringifiedSarifData);
2200
2162
  }
2201
2163
  exports.default = test;
@@ -2358,28 +2320,6 @@ FailOnError.ERROR_MESSAGE = 'Invalid fail on argument, please use one of: ' +
2358
2320
  Object.keys(common_1.FAIL_ON).join(' | ');
2359
2321
 
2360
2322
 
2361
- /***/ }),
2362
-
2363
- /***/ 78673:
2364
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2365
-
2366
- "use strict";
2367
-
2368
- Object.defineProperty(exports, "__esModule", ({ value: true }));
2369
- exports.UnsupportedEntitlementError = void 0;
2370
- const custom_error_1 = __webpack_require__(17188);
2371
- class UnsupportedEntitlementError extends custom_error_1.CustomError {
2372
- constructor(entitlement, userMessage = `This feature is currently not enabled for your org. To enable it, please contact snyk support.`) {
2373
- super('Unsupported feature - Missing the ${entitlementName} entitlement');
2374
- this.entitlement = entitlement;
2375
- this.code = UnsupportedEntitlementError.ERROR_CODE;
2376
- this.userMessage = userMessage;
2377
- }
2378
- }
2379
- exports.UnsupportedEntitlementError = UnsupportedEntitlementError;
2380
- UnsupportedEntitlementError.ERROR_CODE = 403;
2381
-
2382
-
2383
2323
  /***/ }),
2384
2324
 
2385
2325
  /***/ 9401:
@@ -2996,6 +2936,110 @@ function metadataForVuln(vuln) {
2996
2936
  }
2997
2937
 
2998
2938
 
2939
+ /***/ }),
2940
+
2941
+ /***/ 79304:
2942
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2943
+
2944
+ "use strict";
2945
+
2946
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2947
+ exports.getPackageJsonPathsContainingSnykDependency = exports.checkPackageJsonForSnykDependency = exports.packageJsonFileExistsInDirectory = exports.getProtectUpgradeWarningForPaths = void 0;
2948
+ const os_1 = __webpack_require__(12087);
2949
+ const theme = __webpack_require__(86988);
2950
+ const fs = __webpack_require__(35747);
2951
+ const path = __webpack_require__(85622);
2952
+ const createDebug = __webpack_require__(15158);
2953
+ const debug = createDebug('snyk-protect-update-notification');
2954
+ function getProtectUpgradeWarningForPaths(packageJsonPaths) {
2955
+ try {
2956
+ if ((packageJsonPaths === null || packageJsonPaths === void 0 ? void 0 : packageJsonPaths.length) > 0) {
2957
+ let message = theme.color.status.warn(`${theme.icon.WARNING} WARNING: It looks like you have the \`snyk\` dependency in the \`package.json\` file(s) at the following path(s):` +
2958
+ os_1.EOL);
2959
+ packageJsonPaths.forEach((p) => {
2960
+ message += theme.color.status.warn(` - ${p}` + os_1.EOL);
2961
+ });
2962
+ const githubReadmeUrlShort = 'https://snyk.co/ud1cR'; // https://github.com/snyk/snyk/tree/master/packages/snyk-protect#migrating-from-snyk-protect-to-snykprotect
2963
+ message += theme.color.status.warn(`For more information and migration instructions, see ${githubReadmeUrlShort}` +
2964
+ os_1.EOL);
2965
+ return message;
2966
+ }
2967
+ else {
2968
+ return '';
2969
+ }
2970
+ }
2971
+ catch (e) {
2972
+ debug('Error in getProtectUpgradeWarningForPaths()', e);
2973
+ return '';
2974
+ }
2975
+ }
2976
+ exports.getProtectUpgradeWarningForPaths = getProtectUpgradeWarningForPaths;
2977
+ function packageJsonFileExistsInDirectory(directoryPath) {
2978
+ try {
2979
+ const packageJsonPath = path.resolve(directoryPath, 'package.json');
2980
+ const fileExists = fs.existsSync(packageJsonPath);
2981
+ return fileExists;
2982
+ }
2983
+ catch (e) {
2984
+ debug('Error in packageJsonFileExistsInDirectory()', e);
2985
+ return false;
2986
+ }
2987
+ }
2988
+ exports.packageJsonFileExistsInDirectory = packageJsonFileExistsInDirectory;
2989
+ function checkPackageJsonForSnykDependency(packageJsonPath) {
2990
+ try {
2991
+ const fileExists = fs.existsSync(packageJsonPath);
2992
+ if (fileExists) {
2993
+ const packageJson = fs.readFileSync(packageJsonPath, 'utf8');
2994
+ const packageJsonObject = JSON.parse(packageJson);
2995
+ const snykDependency = packageJsonObject.dependencies['snyk'];
2996
+ if (snykDependency) {
2997
+ return true;
2998
+ }
2999
+ }
3000
+ }
3001
+ catch (e) {
3002
+ debug('Error in checkPackageJsonForSnykDependency()', e);
3003
+ }
3004
+ return false;
3005
+ }
3006
+ exports.checkPackageJsonForSnykDependency = checkPackageJsonForSnykDependency;
3007
+ function getPackageJsonPathsContainingSnykDependency(fileOption, paths) {
3008
+ const packageJsonPathsWithSnykDepForProtect = [];
3009
+ try {
3010
+ if (fileOption) {
3011
+ if (fileOption.endsWith('package.json') ||
3012
+ fileOption.endsWith('package-lock.json')) {
3013
+ const directoryWithPackageJson = path.dirname(fileOption);
3014
+ if (packageJsonFileExistsInDirectory(directoryWithPackageJson)) {
3015
+ const packageJsonPath = path.resolve(directoryWithPackageJson, 'package.json');
3016
+ const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(packageJsonPath);
3017
+ if (packageJsonContainsSnykDep) {
3018
+ packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);
3019
+ }
3020
+ }
3021
+ }
3022
+ }
3023
+ else {
3024
+ paths.forEach((testPath) => {
3025
+ if (packageJsonFileExistsInDirectory(testPath)) {
3026
+ const packageJsonPath = path.resolve(testPath, 'package.json');
3027
+ const packageJsonContainsSnykDep = checkPackageJsonForSnykDependency(packageJsonPath);
3028
+ if (packageJsonContainsSnykDep) {
3029
+ packageJsonPathsWithSnykDepForProtect.push(packageJsonPath);
3030
+ }
3031
+ }
3032
+ });
3033
+ }
3034
+ }
3035
+ catch (e) {
3036
+ debug('Error in getPackageJsonPathsContainingSnykDependency()', e);
3037
+ }
3038
+ return packageJsonPathsWithSnykDepForProtect;
3039
+ }
3040
+ exports.getPackageJsonPathsContainingSnykDependency = getPackageJsonPathsContainingSnykDependency;
3041
+
3042
+
2999
3043
  /***/ }),
3000
3044
 
3001
3045
  /***/ 46816: