snyk 1.857.0 → 1.858.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.
@@ -76,7 +76,7 @@ exports.performanceAnalyticsObject = {
76
76
  "use strict";
77
77
 
78
78
  Object.defineProperty(exports, "__esModule", ({ value: true }));
79
- exports.assertIaCOptionsFlags = exports.UnsupportedEntitlementCommandError = exports.UnsupportedEntitlementFlagError = exports.FlagValueError = exports.FlagError = void 0;
79
+ exports.isIacShareResultsOptions = exports.assertIaCOptionsFlags = exports.UnsupportedEntitlementCommandError = exports.UnsupportedEntitlementFlagError = exports.FlagValueError = exports.FeatureFlagError = exports.FlagError = void 0;
80
80
  const errors_1 = __webpack_require__(55191);
81
81
  const args_1 = __webpack_require__(94765);
82
82
  const error_utils_1 = __webpack_require__(23872);
@@ -100,6 +100,7 @@ const keys = [
100
100
  'quiet',
101
101
  'scan',
102
102
  'legacy',
103
+ 'report',
103
104
  // PolicyOptions
104
105
  'ignore-policy',
105
106
  'policy-path',
@@ -114,22 +115,33 @@ function getFlagName(key) {
114
115
  return `${dashes}${flag}`;
115
116
  }
116
117
  class FlagError extends errors_1.CustomError {
117
- constructor(key, featureFlag) {
118
+ constructor(key) {
119
+ const flag = getFlagName(key);
120
+ const msg = `Unsupported flag "${flag}" provided. Run snyk iac test --help for supported flags`;
121
+ super(msg);
122
+ this.code = types_1.IaCErrorCodes.FlagError;
123
+ this.strCode = error_utils_1.getErrorStringCode(this.code);
124
+ this.userMessage = msg;
125
+ }
126
+ }
127
+ exports.FlagError = FlagError;
128
+ class FeatureFlagError extends errors_1.CustomError {
129
+ constructor(key, featureFlag, hasSnykPreview) {
118
130
  const flag = getFlagName(key);
119
131
  let msg;
120
- if (featureFlag) {
132
+ if (hasSnykPreview) {
121
133
  msg = `Flag "${flag}" is only supported if feature flag '${featureFlag}' is enabled. The feature flag can be enabled via Snyk Preview if you are on the Enterprise Plan`;
122
134
  }
123
135
  else {
124
- msg = `Unsupported flag "${flag}" provided. Run snyk iac test --help for supported flags`;
136
+ msg = `Flag "${flag}" is only supported if feature flag "${featureFlag}" is enabled. To enable it, please contact Snyk support.`;
125
137
  }
126
138
  super(msg);
127
- this.code = types_1.IaCErrorCodes.FlagError;
139
+ this.code = types_1.IaCErrorCodes.FeatureFlagError;
128
140
  this.strCode = error_utils_1.getErrorStringCode(this.code);
129
141
  this.userMessage = msg;
130
142
  }
131
143
  }
132
- exports.FlagError = FlagError;
144
+ exports.FeatureFlagError = FeatureFlagError;
133
145
  class FlagValueError extends errors_1.CustomError {
134
146
  constructor(key, value) {
135
147
  const flag = getFlagName(key);
@@ -179,7 +191,7 @@ function assertIaCOptionsFlags(argv) {
179
191
  // flag strings passed to the command line (usually files)
180
192
  // and `iac` is the command provided.
181
193
  if (key !== '_' && key !== 'iac' && !allowed.has(key)) {
182
- throw new FlagError(key, '');
194
+ throw new FlagError(key);
183
195
  }
184
196
  }
185
197
  if (parsed.options.scan) {
@@ -196,6 +208,10 @@ function assertTerraformPlanModes(scanModeArgValue) {
196
208
  throw new FlagValueError('scan', scanModeArgValue);
197
209
  }
198
210
  }
211
+ function isIacShareResultsOptions(options) {
212
+ return options.iac && options.report && !options.legacy;
213
+ }
214
+ exports.isIacShareResultsOptions = isIacShareResultsOptions;
199
215
 
200
216
 
201
217
  /***/ }),
@@ -616,13 +632,14 @@ exports.FailedToExecutePolicyEngine = FailedToExecutePolicyEngine;
616
632
  "use strict";
617
633
 
618
634
  Object.defineProperty(exports, "__esModule", ({ value: true }));
619
- exports.computeCustomRulesBundleChecksum = exports.isValidBundle = exports.extractBundle = exports.createIacDir = void 0;
635
+ exports.computePaths = exports.computeCustomRulesBundleChecksum = exports.isValidBundle = exports.extractBundle = exports.createIacDir = void 0;
620
636
  const fs = __webpack_require__(35747);
621
637
  const tar = __webpack_require__(97998);
622
638
  const path = __webpack_require__(85622);
623
639
  const crypto = __webpack_require__(76417);
624
640
  const local_cache_1 = __webpack_require__(6255);
625
641
  const oci_pull_1 = __webpack_require__(5029);
642
+ const detect_1 = __webpack_require__(45318);
626
643
  function hashData(s) {
627
644
  const hashedData = crypto
628
645
  .createHash('sha1')
@@ -681,6 +698,33 @@ function computeCustomRulesBundleChecksum() {
681
698
  }
682
699
  }
683
700
  exports.computeCustomRulesBundleChecksum = computeCustomRulesBundleChecksum;
701
+ function computePaths(filePath, pathArg = '.') {
702
+ const targetFilePath = path.resolve(filePath, '.');
703
+ // the absolute path is needed to compute the full project path
704
+ const cmdPath = path.resolve(pathArg);
705
+ let projectPath;
706
+ let targetFile;
707
+ if (!detect_1.isLocalFolder(cmdPath)) {
708
+ // if the provided path points to a file, then the project starts at the parent folder of that file
709
+ // and the target file was provided as the path argument
710
+ projectPath = path.dirname(cmdPath);
711
+ targetFile = path.isAbsolute(pathArg)
712
+ ? path.relative(process.cwd(), pathArg)
713
+ : pathArg;
714
+ }
715
+ else {
716
+ // otherwise, the project starts at the provided path
717
+ // and the target file must be the relative path from the project path to the path of the scanned file
718
+ projectPath = cmdPath;
719
+ targetFile = path.relative(projectPath, targetFilePath);
720
+ }
721
+ return {
722
+ targetFilePath,
723
+ projectName: path.basename(projectPath),
724
+ targetFile,
725
+ };
726
+ }
727
+ exports.computePaths = computePaths;
684
728
 
685
729
 
686
730
  /***/ }),
@@ -705,6 +749,7 @@ const feature_flags_1 = __webpack_require__(63011);
705
749
  const rules_1 = __webpack_require__(98895);
706
750
  const file_loader_1 = __webpack_require__(13552);
707
751
  const file_parser_1 = __webpack_require__(2314);
752
+ const share_results_1 = __webpack_require__(3558);
708
753
  // this method executes the local processing engine and then formats the results to adapt with the CLI output.
709
754
  // this flow is the default GA flow for IAC scanning.
710
755
  async function test(pathToScan, options) {
@@ -771,7 +816,11 @@ async function test(pathToScan, options) {
771
816
  }
772
817
  const scannedFiles = await measurable_methods_1.scanFiles(parsedFiles);
773
818
  const resultsWithCustomSeverities = await measurable_methods_1.applyCustomSeverities(scannedFiles, iacOrgSettings.customPolicies);
774
- const formattedResults = measurable_methods_1.formatScanResults(resultsWithCustomSeverities, options, iacOrgSettings.meta);
819
+ let projectPublicIds = {};
820
+ if (options.report) {
821
+ projectPublicIds = await share_results_1.formatAndShareResults(resultsWithCustomSeverities, options, orgPublicId);
822
+ }
823
+ const formattedResults = measurable_methods_1.formatScanResults(resultsWithCustomSeverities, options, iacOrgSettings.meta, projectPublicIds);
775
824
  const { filteredIssues, ignoreCount } = policy_1.filterIgnoredIssues(policy, formattedResults);
776
825
  try {
777
826
  await measurable_methods_1.trackUsage(filteredIssues);
@@ -1573,16 +1622,15 @@ function toFormattedResult(adapter) {
1573
1622
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1574
1623
  exports.FailedToFormatResults = exports.filterPoliciesBySeverity = exports.formatScanResults = void 0;
1575
1624
  const types_1 = __webpack_require__(42258);
1576
- const path = __webpack_require__(85622);
1577
1625
  const common_1 = __webpack_require__(53110);
1578
1626
  const constants_1 = __webpack_require__(68620);
1579
1627
  const errors_1 = __webpack_require__(55191);
1580
1628
  const extract_line_number_1 = __webpack_require__(26747);
1581
1629
  const error_utils_1 = __webpack_require__(23872);
1582
- const detect_1 = __webpack_require__(45318);
1583
1630
  const cloud_config_parser_1 = __webpack_require__(98611);
1631
+ const file_utils_1 = __webpack_require__(58486);
1584
1632
  const severitiesArray = common_1.SEVERITIES.map((s) => s.verboseName);
1585
- function formatScanResults(scanResults, options, meta) {
1633
+ function formatScanResults(scanResults, options, meta, projectPublicIds) {
1586
1634
  try {
1587
1635
  const groupedByFile = scanResults.reduce((memo, scanResult) => {
1588
1636
  const res = formatScanResult(scanResult, meta, options);
@@ -1590,6 +1638,7 @@ function formatScanResults(scanResults, options, meta) {
1590
1638
  memo[scanResult.filePath].result.cloudConfigResults.push(...res.result.cloudConfigResults);
1591
1639
  }
1592
1640
  else {
1641
+ res.meta.projectId = projectPublicIds[res.targetFile];
1593
1642
  memo[scanResult.filePath] = res;
1594
1643
  }
1595
1644
  return memo;
@@ -1646,7 +1695,7 @@ function formatScanResult(scanResult, meta, options) {
1646
1695
  isGeneratedByCustomRule,
1647
1696
  };
1648
1697
  });
1649
- const { targetFilePath, projectName, targetFile } = computePaths(scanResult.filePath, options.path);
1698
+ const { targetFilePath, projectName, targetFile } = file_utils_1.computePaths(scanResult.filePath, options.path);
1650
1699
  return {
1651
1700
  result: {
1652
1701
  cloudConfigResults: filterPoliciesBySeverity(formattedIssues, options.severityThreshold),
@@ -1671,32 +1720,6 @@ function formatScanResult(scanResult, meta, options) {
1671
1720
  packageManager: engineTypeToProjectType[scanResult.engineType],
1672
1721
  };
1673
1722
  }
1674
- function computePaths(filePath, pathArg = '.') {
1675
- const targetFilePath = path.resolve(filePath, '.');
1676
- // the absolute path is needed to compute the full project path
1677
- const cmdPath = path.resolve(pathArg);
1678
- let projectPath;
1679
- let targetFile;
1680
- if (!detect_1.isLocalFolder(cmdPath)) {
1681
- // if the provided path points to a file, then the project starts at the parent folder of that file
1682
- // and the target file was provided as the path argument
1683
- projectPath = path.dirname(cmdPath);
1684
- targetFile = path.isAbsolute(pathArg)
1685
- ? path.relative(process.cwd(), pathArg)
1686
- : pathArg;
1687
- }
1688
- else {
1689
- // otherwise, the project starts at the provided path
1690
- // and the target file must be the relative path from the project path to the path of the scanned file
1691
- projectPath = cmdPath;
1692
- targetFile = path.relative(projectPath, targetFilePath);
1693
- }
1694
- return {
1695
- targetFilePath,
1696
- projectName: path.basename(projectPath),
1697
- targetFile,
1698
- };
1699
- }
1700
1723
  function filterPoliciesBySeverity(violatedPolicies, severityThreshold) {
1701
1724
  if (!severityThreshold || severityThreshold === common_1.SEVERITY.LOW) {
1702
1725
  return violatedPolicies.filter((violatedPolicy) => {
@@ -1881,6 +1904,72 @@ class FailedToExecuteCustomRulesError extends errors_1.CustomError {
1881
1904
  exports.FailedToExecuteCustomRulesError = FailedToExecuteCustomRulesError;
1882
1905
 
1883
1906
 
1907
+ /***/ }),
1908
+
1909
+ /***/ 37324:
1910
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1911
+
1912
+ "use strict";
1913
+
1914
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1915
+ exports.formatShareResults = void 0;
1916
+ const file_utils_1 = __webpack_require__(58486);
1917
+ function formatShareResults(scanResults, options) {
1918
+ const resultsGroupedByFilePath = groupByFilePath(scanResults);
1919
+ return resultsGroupedByFilePath.map((result) => {
1920
+ const { projectName, targetFile } = file_utils_1.computePaths(result.filePath, options.path);
1921
+ return {
1922
+ projectName,
1923
+ targetFile,
1924
+ filePath: result.filePath,
1925
+ fileType: result.fileType,
1926
+ projectType: result.projectType,
1927
+ violatedPolicies: result.violatedPolicies,
1928
+ };
1929
+ });
1930
+ }
1931
+ exports.formatShareResults = formatShareResults;
1932
+ function groupByFilePath(scanResults) {
1933
+ const groupedByFilePath = scanResults.reduce((memo, scanResult) => {
1934
+ scanResult.violatedPolicies.forEach((violatedPolicy) => {
1935
+ violatedPolicy.docId = scanResult.docId;
1936
+ });
1937
+ if (memo[scanResult.filePath]) {
1938
+ memo[scanResult.filePath].violatedPolicies.push(...scanResult.violatedPolicies);
1939
+ }
1940
+ else {
1941
+ memo[scanResult.filePath] = scanResult;
1942
+ }
1943
+ return memo;
1944
+ }, {});
1945
+ return Object.values(groupedByFilePath);
1946
+ }
1947
+
1948
+
1949
+ /***/ }),
1950
+
1951
+ /***/ 3558:
1952
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1953
+
1954
+ "use strict";
1955
+
1956
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1957
+ exports.formatAndShareResults = void 0;
1958
+ const feature_flags_1 = __webpack_require__(63011);
1959
+ const cli_share_results_1 = __webpack_require__(24016);
1960
+ const assert_iac_options_flag_1 = __webpack_require__(68590);
1961
+ const share_results_formatter_1 = __webpack_require__(37324);
1962
+ async function formatAndShareResults(results, options, orgPublicId) {
1963
+ const isCliReportEnabled = await feature_flags_1.isFeatureFlagSupportedForOrg('iacCliShareResults', orgPublicId);
1964
+ if (!isCliReportEnabled.ok) {
1965
+ throw new assert_iac_options_flag_1.FeatureFlagError('report', 'iacCliShareResults');
1966
+ }
1967
+ const formattedResults = share_results_formatter_1.formatShareResults(results, options);
1968
+ return await cli_share_results_1.shareResults(formattedResults);
1969
+ }
1970
+ exports.formatAndShareResults = formatAndShareResults;
1971
+
1972
+
1884
1973
  /***/ }),
1885
1974
 
1886
1975
  /***/ 80256:
@@ -2019,6 +2108,68 @@ exports.UnsupportedEntitlementError = UnsupportedEntitlementError;
2019
2108
  UnsupportedEntitlementError.ERROR_CODE = 403;
2020
2109
 
2021
2110
 
2111
+ /***/ }),
2112
+
2113
+ /***/ 24016:
2114
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2115
+
2116
+ "use strict";
2117
+
2118
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2119
+ exports.shareResults = void 0;
2120
+ const config_1 = __webpack_require__(22541);
2121
+ const request_1 = __webpack_require__(52050);
2122
+ const api_token_1 = __webpack_require__(95181);
2123
+ const envelope_formatters_1 = __webpack_require__(88784);
2124
+ const authentication_failed_error_1 = __webpack_require__(23770);
2125
+ async function shareResults(results) {
2126
+ const scanResults = results.map(envelope_formatters_1.convertIacResultToScanResult);
2127
+ const { res, body } = await request_1.makeRequest({
2128
+ method: 'POST',
2129
+ url: `${config_1.default.API}/iac-cli-share-results`,
2130
+ json: true,
2131
+ headers: {
2132
+ authorization: api_token_1.getAuthHeader(),
2133
+ },
2134
+ body: scanResults,
2135
+ });
2136
+ if (res.statusCode === 401) {
2137
+ throw authentication_failed_error_1.AuthFailedError();
2138
+ }
2139
+ return body;
2140
+ }
2141
+ exports.shareResults = shareResults;
2142
+
2143
+
2144
+ /***/ }),
2145
+
2146
+ /***/ 88784:
2147
+ /***/ ((__unused_webpack_module, exports) => {
2148
+
2149
+ "use strict";
2150
+
2151
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2152
+ exports.convertIacResultToScanResult = void 0;
2153
+ function convertIacResultToScanResult(iacResult) {
2154
+ return {
2155
+ identity: {
2156
+ type: iacResult.projectType,
2157
+ targetFile: iacResult.targetFile,
2158
+ },
2159
+ facts: [],
2160
+ findings: iacResult.violatedPolicies.map((policy) => {
2161
+ return {
2162
+ data: { metadata: policy, docId: policy.docId },
2163
+ type: 'iacIssue',
2164
+ };
2165
+ }),
2166
+ name: iacResult.projectName,
2167
+ target: { name: iacResult.projectName },
2168
+ };
2169
+ }
2170
+ exports.convertIacResultToScanResult = convertIacResultToScanResult;
2171
+
2172
+
2022
2173
  /***/ }),
2023
2174
 
2024
2175
  /***/ 24135: