snyk 1.967.0 → 1.968.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.
- package/dist/cli/917.index.js +150 -666
- package/dist/cli/917.index.js.map +1 -1
- package/dist/cli/commands/test/iac/local-execution/measurable-methods.d.ts +2 -3
- package/dist/cli/commands/test/iac/local-execution/process-results/{v2/cli-share-results.d.ts → cli-share-results.d.ts} +3 -3
- package/dist/cli/commands/test/iac/local-execution/process-results/{v1/extract-line-number.d.ts → extract-line-number.d.ts} +0 -0
- package/dist/cli/commands/test/iac/local-execution/process-results/index.d.ts +0 -11
- package/dist/cli/commands/test/iac/local-execution/process-results/{v2/policy.d.ts → policy.d.ts} +2 -2
- package/dist/cli/commands/test/iac/local-execution/process-results/{v2/index.d.ts → process-results.d.ts} +3 -3
- package/dist/cli/commands/test/iac/local-execution/process-results/{v2/results-formatter.d.ts → results-formatter.d.ts} +3 -3
- package/dist/cli/commands/test/iac/local-execution/process-results/{v2/share-results-formatter.d.ts → share-results-formatter.d.ts} +1 -1
- package/dist/cli/commands/test/iac/local-execution/process-results/{v2/share-results.d.ts → share-results.d.ts} +3 -3
- package/dist/cli/commands/test/iac/output.d.ts +1 -2
- package/dist/cli/commands/test/iac/scan.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cli/commands/test/iac/local-execution/process-results/v1/index.d.ts +0 -7
- package/dist/cli/commands/test/iac/local-execution/process-results/v1/policy.d.ts +0 -6
- package/dist/cli/commands/test/iac/local-execution/process-results/v1/results-formatter.d.ts +0 -8
- package/dist/cli/commands/test/iac/local-execution/process-results/v1/share-results-formatter.d.ts +0 -2
- package/dist/cli/commands/test/iac/local-execution/process-results/v1/share-results.d.ts +0 -12
- package/dist/cli/commands/test/iac/local-execution/process-results/v2/extract-line-number.d.ts +0 -3
package/dist/cli/917.index.js
CHANGED
|
@@ -79,12 +79,12 @@ async function default_1(...args) {
|
|
|
79
79
|
options,
|
|
80
80
|
isNewIacOutputSupported,
|
|
81
81
|
});
|
|
82
|
+
const projectRoot = process.cwd();
|
|
82
83
|
output_1.printHeader({
|
|
83
|
-
paths,
|
|
84
84
|
options,
|
|
85
85
|
isNewIacOutputSupported,
|
|
86
86
|
});
|
|
87
|
-
const { iacOutputMeta, iacScanFailures, iacIgnoredIssuesCount, results, resultOptions, } = await scan_1.scan(iacOrgSettings, options, testSpinner, paths, orgPublicId, buildOciRegistry);
|
|
87
|
+
const { iacOutputMeta, iacScanFailures, iacIgnoredIssuesCount, results, resultOptions, } = await scan_1.scan(iacOrgSettings, options, testSpinner, paths, orgPublicId, buildOciRegistry, projectRoot);
|
|
88
88
|
return output_1.buildOutput({
|
|
89
89
|
results,
|
|
90
90
|
options,
|
|
@@ -697,11 +697,10 @@ exports.InvalidVarFilePath = InvalidVarFilePath;
|
|
|
697
697
|
"use strict";
|
|
698
698
|
|
|
699
699
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
700
|
-
exports.pull = exports.localTest = exports.cleanLocalCache = exports.trackUsage = exports.formatScanResultsV2 = exports.
|
|
700
|
+
exports.pull = exports.localTest = exports.cleanLocalCache = exports.trackUsage = exports.formatScanResultsV2 = exports.applyCustomSeverities = exports.getIacOrgSettings = exports.scanFiles = exports.parseFiles = exports.loadContentForFiles = exports.initLocalCache = exports.performanceAnalyticsDecorator = exports.asyncPerformanceAnalyticsDecorator = void 0;
|
|
701
701
|
const file_parser_1 = __webpack_require__(39331);
|
|
702
702
|
const file_scanner_1 = __webpack_require__(88361);
|
|
703
|
-
const results_formatter_1 = __webpack_require__(
|
|
704
|
-
const results_formatter_2 = __webpack_require__(50350);
|
|
703
|
+
const results_formatter_1 = __webpack_require__(11059);
|
|
705
704
|
const usage_tracking_1 = __webpack_require__(70413);
|
|
706
705
|
const local_cache_1 = __webpack_require__(50089);
|
|
707
706
|
const apply_custom_severities_1 = __webpack_require__(71632);
|
|
@@ -748,10 +747,8 @@ const measurableApplyCustomSeverities = asyncPerformanceAnalyticsDecorator(apply
|
|
|
748
747
|
exports.applyCustomSeverities = measurableApplyCustomSeverities;
|
|
749
748
|
const measurableCleanLocalCache = performanceAnalyticsDecorator(local_cache_1.cleanLocalCache, types_1.PerformanceAnalyticsKey.CacheCleanup);
|
|
750
749
|
exports.cleanLocalCache = measurableCleanLocalCache;
|
|
751
|
-
const
|
|
752
|
-
exports.
|
|
753
|
-
const measurableFormatScanResultsV2 = performanceAnalyticsDecorator(results_formatter_2.formatScanResults, types_1.PerformanceAnalyticsKey.ResultFormatting);
|
|
754
|
-
exports.formatScanResultsV2 = measurableFormatScanResultsV2;
|
|
750
|
+
const measurableFormatScanResults = performanceAnalyticsDecorator(results_formatter_1.formatScanResults, types_1.PerformanceAnalyticsKey.ResultFormatting);
|
|
751
|
+
exports.formatScanResultsV2 = measurableFormatScanResults;
|
|
755
752
|
const measurableTrackUsage = asyncPerformanceAnalyticsDecorator(usage_tracking_1.trackUsage, types_1.PerformanceAnalyticsKey.UsageTracking);
|
|
756
753
|
exports.trackUsage = measurableTrackUsage;
|
|
757
754
|
const measurableLocalTest = asyncPerformanceAnalyticsDecorator(index_1.test, types_1.PerformanceAnalyticsKey.Total);
|
|
@@ -933,550 +930,107 @@ function getReference(value) {
|
|
|
933
930
|
var _a;
|
|
934
931
|
return (_a = value.references) === null || _a === void 0 ? void 0 : _a[0];
|
|
935
932
|
}
|
|
936
|
-
function getResourceName(index, name) {
|
|
937
|
-
return index !== undefined ? `${name}["${index}"]` : name;
|
|
938
|
-
}
|
|
939
|
-
function resourceChangeReducer(scanInput, resource, isFullScan) {
|
|
940
|
-
// TODO: investigate if we need to address also `after_unknown` field.
|
|
941
|
-
const { actions, after } = resource.change || { actions: [], after: {} };
|
|
942
|
-
if (isValidResourceActions(actions, isFullScan)) {
|
|
943
|
-
const resourceForReduction = { ...resource, values: after || {} };
|
|
944
|
-
return terraformPlanReducer(scanInput, resourceForReduction);
|
|
945
|
-
}
|
|
946
|
-
return scanInput;
|
|
947
|
-
}
|
|
948
|
-
function isValidResourceActions(action, isFullScan) {
|
|
949
|
-
const VALID_ACTIONS = isFullScan
|
|
950
|
-
? types_1.VALID_RESOURCE_ACTIONS_FOR_FULL_SCAN
|
|
951
|
-
: types_1.VALID_RESOURCE_ACTIONS_FOR_DELTA_SCAN;
|
|
952
|
-
return VALID_ACTIONS.some((validAction) => {
|
|
953
|
-
if (action.length !== validAction.length) {
|
|
954
|
-
return false;
|
|
955
|
-
}
|
|
956
|
-
return validAction.every((field, idx) => action[idx] === field);
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
function referencedResourcesResolver(scanInput, resources) {
|
|
960
|
-
var _a, _b;
|
|
961
|
-
// check root module for references in first depth of attributes
|
|
962
|
-
for (const resource of resources) {
|
|
963
|
-
const { type, name, mode, index, expressions } = resource;
|
|
964
|
-
// don't care about references in data sources for time being
|
|
965
|
-
if (mode == 'data') {
|
|
966
|
-
continue;
|
|
967
|
-
}
|
|
968
|
-
const inputKey = 'resource';
|
|
969
|
-
// only update the references in resources that have some resolved attributes already
|
|
970
|
-
const resolvedResource = (_b = (_a = scanInput[inputKey]) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b[getResourceName(index, name)];
|
|
971
|
-
if (resolvedResource && expressions) {
|
|
972
|
-
const resourceExpressions = getExpressions(expressions);
|
|
973
|
-
for (const key of Object.keys(resourceExpressions)) {
|
|
974
|
-
// only add non existing attributes. If we already have resolved value do not overwrite it with reference
|
|
975
|
-
if (!resolvedResource[key]) {
|
|
976
|
-
resolvedResource[key] = resourceExpressions[key];
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
scanInput[inputKey][type][getResourceName(index, name)] = resolvedResource;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
return scanInput;
|
|
983
|
-
}
|
|
984
|
-
function extractResourceChanges(terraformPlanJson) {
|
|
985
|
-
return terraformPlanJson.resource_changes || [];
|
|
986
|
-
}
|
|
987
|
-
function extractReferencedResources(terraformPlanJson) {
|
|
988
|
-
var _a, _b;
|
|
989
|
-
return ((_b = (_a = terraformPlanJson.configuration) === null || _a === void 0 ? void 0 : _a.root_module) === null || _b === void 0 ? void 0 : _b.resources) || [];
|
|
990
|
-
}
|
|
991
|
-
function extractResourcesForScan(terraformPlanJson, isFullScan = false) {
|
|
992
|
-
const resourceChanges = extractResourceChanges(terraformPlanJson);
|
|
993
|
-
const scanInput = resourceChanges.reduce((memo, curr) => resourceChangeReducer(memo, curr, isFullScan), {
|
|
994
|
-
resource: {},
|
|
995
|
-
data: {},
|
|
996
|
-
});
|
|
997
|
-
const referencedResources = extractReferencedResources(terraformPlanJson);
|
|
998
|
-
return referencedResourcesResolver(scanInput, referencedResources);
|
|
999
|
-
}
|
|
1000
|
-
function isTerraformPlan(terraformPlanJson) {
|
|
1001
|
-
const missingRequiredFields = terraformPlanJson.resource_changes === undefined;
|
|
1002
|
-
return !missingRequiredFields;
|
|
1003
|
-
}
|
|
1004
|
-
exports.isTerraformPlan = isTerraformPlan;
|
|
1005
|
-
function tryParsingTerraformPlan(terraformPlanFile, terraformPlanJson, { isFullScan } = { isFullScan: false }) {
|
|
1006
|
-
try {
|
|
1007
|
-
return [
|
|
1008
|
-
{
|
|
1009
|
-
...terraformPlanFile,
|
|
1010
|
-
jsonContent: extractResourcesForScan(terraformPlanJson, isFullScan),
|
|
1011
|
-
engineType: types_1.EngineType.Terraform,
|
|
1012
|
-
projectType: constants_1.IacProjectType.TERRAFORM,
|
|
1013
|
-
},
|
|
1014
|
-
];
|
|
1015
|
-
}
|
|
1016
|
-
catch (err) {
|
|
1017
|
-
throw new FailedToExtractResourcesInTerraformPlanError();
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
exports.tryParsingTerraformPlan = tryParsingTerraformPlan;
|
|
1021
|
-
// This error is due to the complex reduction logic, so it catches scenarios we might have not covered.
|
|
1022
|
-
class FailedToExtractResourcesInTerraformPlanError extends errors_1.CustomError {
|
|
1023
|
-
constructor(message) {
|
|
1024
|
-
super(message || 'Failed to extract resources from Terraform plan JSON file');
|
|
1025
|
-
this.code = types_1.IaCErrorCodes.FailedToExtractResourcesInTerraformPlanError;
|
|
1026
|
-
this.strCode = error_utils_1.getErrorStringCode(this.code);
|
|
1027
|
-
this.userMessage =
|
|
1028
|
-
'We failed to extract resource changes from the Terraform plan file, please contact support@snyk.io, if possible with a redacted version of the file';
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
exports.FailedToExtractResourcesInTerraformPlanError = FailedToExtractResourcesInTerraformPlanError;
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
/***/ }),
|
|
1035
|
-
|
|
1036
|
-
/***/ 1229:
|
|
1037
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1038
|
-
|
|
1039
|
-
"use strict";
|
|
1040
|
-
|
|
1041
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1042
|
-
exports.MultipleGroupsResultsProcessor = exports.SingleGroupResultsProcessor = void 0;
|
|
1043
|
-
const v2_1 = __webpack_require__(89324);
|
|
1044
|
-
const v1_1 = __webpack_require__(97884);
|
|
1045
|
-
class SingleGroupResultsProcessor {
|
|
1046
|
-
constructor(projectRoot, orgPublicId, iacOrgSettings, options) {
|
|
1047
|
-
this.projectRoot = projectRoot;
|
|
1048
|
-
this.orgPublicId = orgPublicId;
|
|
1049
|
-
this.iacOrgSettings = iacOrgSettings;
|
|
1050
|
-
this.options = options;
|
|
1051
|
-
}
|
|
1052
|
-
processResults(resultsWithCustomSeverities, policy, tags, attributes) {
|
|
1053
|
-
return v2_1.processResults(resultsWithCustomSeverities, this.orgPublicId, this.iacOrgSettings, policy, tags, attributes, this.options, this.projectRoot);
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
exports.SingleGroupResultsProcessor = SingleGroupResultsProcessor;
|
|
1057
|
-
class MultipleGroupsResultsProcessor {
|
|
1058
|
-
constructor(pathToScan, orgPublicId, iacOrgSettings, options) {
|
|
1059
|
-
this.pathToScan = pathToScan;
|
|
1060
|
-
this.orgPublicId = orgPublicId;
|
|
1061
|
-
this.iacOrgSettings = iacOrgSettings;
|
|
1062
|
-
this.options = options;
|
|
1063
|
-
}
|
|
1064
|
-
processResults(resultsWithCustomSeverities, policy, tags, attributes) {
|
|
1065
|
-
return v1_1.processResults(resultsWithCustomSeverities, this.orgPublicId, this.iacOrgSettings, policy, tags, attributes, this.options, this.pathToScan);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
exports.MultipleGroupsResultsProcessor = MultipleGroupsResultsProcessor;
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
/***/ }),
|
|
1072
|
-
|
|
1073
|
-
/***/ 29576:
|
|
1074
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1075
|
-
|
|
1076
|
-
"use strict";
|
|
1077
|
-
|
|
1078
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1079
|
-
exports.extractLineNumber = exports.getFileTypeForParser = void 0;
|
|
1080
|
-
const types_1 = __webpack_require__(94820);
|
|
1081
|
-
const errors_1 = __webpack_require__(55191);
|
|
1082
|
-
const cloud_config_parser_1 = __webpack_require__(98611);
|
|
1083
|
-
const file_parser_1 = __webpack_require__(39331);
|
|
1084
|
-
const analytics = __webpack_require__(82744);
|
|
1085
|
-
const Debug = __webpack_require__(15158);
|
|
1086
|
-
const error_utils_1 = __webpack_require__(36401);
|
|
1087
|
-
const debug = Debug('iac-extract-line-number');
|
|
1088
|
-
function getFileTypeForParser(fileType) {
|
|
1089
|
-
switch (fileType) {
|
|
1090
|
-
case 'yaml':
|
|
1091
|
-
case 'yml':
|
|
1092
|
-
return cloud_config_parser_1.CloudConfigFileTypes.YAML;
|
|
1093
|
-
case 'json':
|
|
1094
|
-
return cloud_config_parser_1.CloudConfigFileTypes.JSON;
|
|
1095
|
-
case 'tf':
|
|
1096
|
-
return cloud_config_parser_1.CloudConfigFileTypes.TF;
|
|
1097
|
-
default:
|
|
1098
|
-
throw new file_parser_1.UnsupportedFileTypeError(fileType);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
exports.getFileTypeForParser = getFileTypeForParser;
|
|
1102
|
-
function extractLineNumber(cloudConfigPath, fileType, treeByDocId) {
|
|
1103
|
-
try {
|
|
1104
|
-
return cloud_config_parser_1.getLineNumber(cloudConfigPath, fileType, treeByDocId);
|
|
1105
|
-
}
|
|
1106
|
-
catch {
|
|
1107
|
-
const err = new FailedToExtractLineNumberError();
|
|
1108
|
-
analytics.add('error-code', err.code);
|
|
1109
|
-
debug('Parser library failed. Could not assign lineNumber to issue');
|
|
1110
|
-
return -1;
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
exports.extractLineNumber = extractLineNumber;
|
|
1114
|
-
class FailedToExtractLineNumberError extends errors_1.CustomError {
|
|
1115
|
-
constructor(message) {
|
|
1116
|
-
super(message || 'Parser library failed. Could not assign lineNumber to issue');
|
|
1117
|
-
this.code = types_1.IaCErrorCodes.FailedToExtractLineNumberError;
|
|
1118
|
-
this.strCode = error_utils_1.getErrorStringCode(this.code);
|
|
1119
|
-
this.userMessage = ''; // Not a user facing error.
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
/***/ }),
|
|
1125
|
-
|
|
1126
|
-
/***/ 97884:
|
|
1127
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1128
|
-
|
|
1129
|
-
"use strict";
|
|
1130
|
-
|
|
1131
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1132
|
-
exports.processResults = void 0;
|
|
1133
|
-
const policy_1 = __webpack_require__(31748);
|
|
1134
|
-
const share_results_1 = __webpack_require__(20588);
|
|
1135
|
-
const measurable_methods_1 = __webpack_require__(5687);
|
|
1136
|
-
async function processResults(resultsWithCustomSeverities, orgPublicId, iacOrgSettings, policy, tags, attributes, options, pathToScan) {
|
|
1137
|
-
let projectPublicIds = {};
|
|
1138
|
-
let gitRemoteUrl;
|
|
1139
|
-
if (options.report) {
|
|
1140
|
-
({ projectPublicIds, gitRemoteUrl } = await share_results_1.formatAndShareResults({
|
|
1141
|
-
results: resultsWithCustomSeverities,
|
|
1142
|
-
options,
|
|
1143
|
-
orgPublicId,
|
|
1144
|
-
policy,
|
|
1145
|
-
tags,
|
|
1146
|
-
attributes,
|
|
1147
|
-
pathToScan,
|
|
1148
|
-
}));
|
|
1149
|
-
}
|
|
1150
|
-
const formattedResults = measurable_methods_1.formatScanResultsV1(resultsWithCustomSeverities, options, iacOrgSettings.meta, projectPublicIds, gitRemoteUrl);
|
|
1151
|
-
return policy_1.filterIgnoredIssues(policy, formattedResults);
|
|
1152
|
-
}
|
|
1153
|
-
exports.processResults = processResults;
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
/***/ }),
|
|
1157
|
-
|
|
1158
|
-
/***/ 31748:
|
|
1159
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
1160
|
-
|
|
1161
|
-
"use strict";
|
|
1162
|
-
|
|
1163
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1164
|
-
exports.filterIgnoredIssues = void 0;
|
|
1165
|
-
function filterIgnoredIssues(policy, results) {
|
|
1166
|
-
if (!policy) {
|
|
1167
|
-
return { filteredIssues: results, ignoreCount: 0 };
|
|
1168
|
-
}
|
|
1169
|
-
const vulns = results.map((res) => policy.filter(toIaCVulnAdapter(res), undefined, 'exact'));
|
|
1170
|
-
const ignoreCount = vulns.reduce((totalIgnored, vuln) => totalIgnored + vuln.filtered.ignore.length, 0);
|
|
1171
|
-
const filteredIssues = vulns.map((vuln) => toFormattedResult(vuln));
|
|
1172
|
-
return { filteredIssues, ignoreCount };
|
|
1173
|
-
}
|
|
1174
|
-
exports.filterIgnoredIssues = filterIgnoredIssues;
|
|
1175
|
-
function toIaCVulnAdapter(result) {
|
|
1176
|
-
return {
|
|
1177
|
-
vulnerabilities: result.result.cloudConfigResults.map((cloudConfigResult) => {
|
|
1178
|
-
const annotatedResult = cloudConfigResult;
|
|
1179
|
-
// Copy the cloudConfigPath array to avoid modifying the original with
|
|
1180
|
-
// splice.
|
|
1181
|
-
// Insert the targetFile into the path so that it is taken into account
|
|
1182
|
-
// when determining whether an ignore rule should be applied.
|
|
1183
|
-
const path = [...annotatedResult.cloudConfigPath];
|
|
1184
|
-
path.splice(0, 0, result.targetFile);
|
|
1185
|
-
return {
|
|
1186
|
-
id: cloudConfigResult.id,
|
|
1187
|
-
from: path,
|
|
1188
|
-
};
|
|
1189
|
-
}),
|
|
1190
|
-
originalResult: result,
|
|
1191
|
-
};
|
|
1192
|
-
}
|
|
1193
|
-
function toFormattedResult(adapter) {
|
|
1194
|
-
const original = adapter.originalResult;
|
|
1195
|
-
const filteredCloudConfigResults = original.result.cloudConfigResults.filter((res) => {
|
|
1196
|
-
return adapter.vulnerabilities.some((vuln) => {
|
|
1197
|
-
if (vuln.id !== res.id) {
|
|
1198
|
-
return false;
|
|
1199
|
-
}
|
|
1200
|
-
// Unfortunately we are forced to duplicate the logic in
|
|
1201
|
-
// toIaCVulnAdapter so that we're comparing path components properly,
|
|
1202
|
-
// including target file context. As that logic changes, so must this.
|
|
1203
|
-
const annotatedResult = res;
|
|
1204
|
-
const significantPath = [...annotatedResult.cloudConfigPath];
|
|
1205
|
-
significantPath.splice(0, 0, original.targetFile);
|
|
1206
|
-
if (vuln.from.length !== significantPath.length) {
|
|
1207
|
-
return false;
|
|
1208
|
-
}
|
|
1209
|
-
for (let i = 0; i < vuln.from.length; i++) {
|
|
1210
|
-
if (vuln.from[i] !== significantPath[i]) {
|
|
1211
|
-
return false;
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
return true;
|
|
1215
|
-
});
|
|
1216
|
-
});
|
|
1217
|
-
original.result.cloudConfigResults = filteredCloudConfigResults;
|
|
1218
|
-
return original;
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
/***/ }),
|
|
1223
|
-
|
|
1224
|
-
/***/ 47354:
|
|
1225
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1226
|
-
|
|
1227
|
-
"use strict";
|
|
1228
|
-
|
|
1229
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1230
|
-
exports.FailedToFormatResults = exports.filterPoliciesBySeverity = exports.formatScanResults = void 0;
|
|
1231
|
-
const types_1 = __webpack_require__(94820);
|
|
1232
|
-
const common_1 = __webpack_require__(53110);
|
|
1233
|
-
const constants_1 = __webpack_require__(68620);
|
|
1234
|
-
const errors_1 = __webpack_require__(55191);
|
|
1235
|
-
const extract_line_number_1 = __webpack_require__(29576);
|
|
1236
|
-
const error_utils_1 = __webpack_require__(36401);
|
|
1237
|
-
const cloud_config_parser_1 = __webpack_require__(98611);
|
|
1238
|
-
const path = __webpack_require__(85622);
|
|
1239
|
-
const detect_1 = __webpack_require__(45318);
|
|
1240
|
-
const severitiesArray = common_1.SEVERITIES.map((s) => s.verboseName);
|
|
1241
|
-
function formatScanResults(scanResults, options, meta, projectPublicIds, gitRemoteUrl) {
|
|
1242
|
-
try {
|
|
1243
|
-
const groupedByFile = scanResults.reduce((memo, scanResult) => {
|
|
1244
|
-
const res = formatScanResult(scanResult, meta, options);
|
|
1245
|
-
if (memo[scanResult.filePath]) {
|
|
1246
|
-
memo[scanResult.filePath].result.cloudConfigResults.push(...res.result.cloudConfigResults);
|
|
1247
|
-
}
|
|
1248
|
-
else {
|
|
1249
|
-
res.meta.gitRemoteUrl = gitRemoteUrl;
|
|
1250
|
-
res.meta.projectId = projectPublicIds[res.targetFile];
|
|
1251
|
-
memo[scanResult.filePath] = res;
|
|
1252
|
-
}
|
|
1253
|
-
return memo;
|
|
1254
|
-
}, {});
|
|
1255
|
-
return Object.values(groupedByFile);
|
|
1256
|
-
}
|
|
1257
|
-
catch (e) {
|
|
1258
|
-
throw new FailedToFormatResults();
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
exports.formatScanResults = formatScanResults;
|
|
1262
|
-
const engineTypeToProjectType = {
|
|
1263
|
-
[types_1.EngineType.Kubernetes]: constants_1.IacProjectType.K8S,
|
|
1264
|
-
[types_1.EngineType.Terraform]: constants_1.IacProjectType.TERRAFORM,
|
|
1265
|
-
[types_1.EngineType.CloudFormation]: constants_1.IacProjectType.CLOUDFORMATION,
|
|
1266
|
-
[types_1.EngineType.ARM]: constants_1.IacProjectType.ARM,
|
|
1267
|
-
[types_1.EngineType.Custom]: constants_1.IacProjectType.CUSTOM,
|
|
1268
|
-
};
|
|
1269
|
-
function formatScanResult(scanResult, meta, options) {
|
|
1270
|
-
const fileType = extract_line_number_1.getFileTypeForParser(scanResult.fileType);
|
|
1271
|
-
const isGeneratedByCustomRule = scanResult.engineType === types_1.EngineType.Custom;
|
|
1272
|
-
let treeByDocId;
|
|
1273
|
-
try {
|
|
1274
|
-
treeByDocId = cloud_config_parser_1.getTrees(fileType, scanResult.fileContent);
|
|
1275
|
-
}
|
|
1276
|
-
catch (err) {
|
|
1277
|
-
// we do nothing intentionally.
|
|
1278
|
-
// Even if the building of the tree fails in the external parser,
|
|
1279
|
-
// we still pass an undefined tree and not calculated line number for those
|
|
1280
|
-
}
|
|
1281
|
-
const formattedIssues = scanResult.violatedPolicies.map((policy) => {
|
|
1282
|
-
const cloudConfigPath = scanResult.docId !== undefined
|
|
1283
|
-
? [`[DocId: ${scanResult.docId}]`].concat(cloud_config_parser_1.parsePath(policy.msg))
|
|
1284
|
-
: policy.msg.split('.');
|
|
1285
|
-
const lineNumber = treeByDocId
|
|
1286
|
-
? extract_line_number_1.extractLineNumber(cloudConfigPath, fileType, treeByDocId)
|
|
1287
|
-
: -1;
|
|
1288
|
-
return {
|
|
1289
|
-
...policy,
|
|
1290
|
-
id: policy.publicId,
|
|
1291
|
-
name: policy.title,
|
|
1292
|
-
cloudConfigPath,
|
|
1293
|
-
isIgnored: false,
|
|
1294
|
-
iacDescription: {
|
|
1295
|
-
issue: policy.issue,
|
|
1296
|
-
impact: policy.impact,
|
|
1297
|
-
resolve: policy.resolve,
|
|
1298
|
-
},
|
|
1299
|
-
severity: policy.severity,
|
|
1300
|
-
lineNumber,
|
|
1301
|
-
documentation: !isGeneratedByCustomRule
|
|
1302
|
-
? `https://snyk.io/security-rules/${policy.publicId}`
|
|
1303
|
-
: undefined,
|
|
1304
|
-
isGeneratedByCustomRule,
|
|
1305
|
-
};
|
|
1306
|
-
});
|
|
1307
|
-
const { targetFilePath, projectName, targetFile } = computePaths(scanResult.filePath, options.path);
|
|
1308
|
-
return {
|
|
1309
|
-
result: {
|
|
1310
|
-
cloudConfigResults: filterPoliciesBySeverity(formattedIssues, options.severityThreshold),
|
|
1311
|
-
projectType: scanResult.projectType,
|
|
1312
|
-
},
|
|
1313
|
-
meta: {
|
|
1314
|
-
...meta,
|
|
1315
|
-
projectId: '',
|
|
1316
|
-
policy: '',
|
|
1317
|
-
},
|
|
1318
|
-
filesystemPolicy: false,
|
|
1319
|
-
vulnerabilities: [],
|
|
1320
|
-
dependencyCount: 0,
|
|
1321
|
-
licensesPolicy: null,
|
|
1322
|
-
ignoreSettings: null,
|
|
1323
|
-
targetFile,
|
|
1324
|
-
projectName,
|
|
1325
|
-
org: meta.org,
|
|
1326
|
-
policy: '',
|
|
1327
|
-
isPrivate: true,
|
|
1328
|
-
targetFilePath,
|
|
1329
|
-
packageManager: engineTypeToProjectType[scanResult.engineType],
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
function filterPoliciesBySeverity(violatedPolicies, severityThreshold) {
|
|
1333
|
-
if (!severityThreshold || severityThreshold === common_1.SEVERITY.LOW) {
|
|
1334
|
-
return violatedPolicies.filter((violatedPolicy) => {
|
|
1335
|
-
return violatedPolicy.severity !== 'none';
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
const severitiesToInclude = severitiesArray.slice(severitiesArray.indexOf(severityThreshold));
|
|
1339
|
-
return violatedPolicies.filter((policy) => {
|
|
1340
|
-
return (policy.severity !== 'none' &&
|
|
1341
|
-
severitiesToInclude.includes(policy.severity));
|
|
1342
|
-
});
|
|
1343
|
-
}
|
|
1344
|
-
exports.filterPoliciesBySeverity = filterPoliciesBySeverity;
|
|
1345
|
-
class FailedToFormatResults extends errors_1.CustomError {
|
|
1346
|
-
constructor(message) {
|
|
1347
|
-
super(message || 'Failed to format results');
|
|
1348
|
-
this.code = types_1.IaCErrorCodes.FailedToFormatResults;
|
|
1349
|
-
this.strCode = error_utils_1.getErrorStringCode(this.code);
|
|
1350
|
-
this.userMessage =
|
|
1351
|
-
'We failed printing the results, please contact support@snyk.io';
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
exports.FailedToFormatResults = FailedToFormatResults;
|
|
1355
|
-
function computePaths(filePath, pathArg = '.') {
|
|
1356
|
-
const targetFilePath = path.resolve(filePath, '.');
|
|
1357
|
-
// the absolute path is needed to compute the full project path
|
|
1358
|
-
const cmdPath = path.resolve(pathArg);
|
|
1359
|
-
let projectPath;
|
|
1360
|
-
let targetFile;
|
|
1361
|
-
if (!detect_1.isLocalFolder(cmdPath)) {
|
|
1362
|
-
// if the provided path points to a file, then the project starts at the parent folder of that file
|
|
1363
|
-
// and the target file was provided as the path argument
|
|
1364
|
-
projectPath = path.dirname(cmdPath);
|
|
1365
|
-
targetFile = path.isAbsolute(pathArg)
|
|
1366
|
-
? path.relative(process.cwd(), pathArg)
|
|
1367
|
-
: pathArg;
|
|
1368
|
-
}
|
|
1369
|
-
else {
|
|
1370
|
-
// otherwise, the project starts at the provided path
|
|
1371
|
-
// and the target file must be the relative path from the project path to the path of the scanned file
|
|
1372
|
-
projectPath = cmdPath;
|
|
1373
|
-
targetFile = path.relative(projectPath, targetFilePath);
|
|
1374
|
-
}
|
|
1375
|
-
return {
|
|
1376
|
-
targetFilePath,
|
|
1377
|
-
projectName: path.basename(projectPath),
|
|
1378
|
-
targetFile,
|
|
1379
|
-
};
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
/***/ }),
|
|
1384
|
-
|
|
1385
|
-
/***/ 42564:
|
|
1386
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1387
|
-
|
|
1388
|
-
"use strict";
|
|
1389
|
-
|
|
1390
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1391
|
-
exports.formatShareResults = void 0;
|
|
1392
|
-
const path = __webpack_require__(85622);
|
|
1393
|
-
const git_1 = __webpack_require__(82421);
|
|
1394
|
-
function formatShareResults(scanResults) {
|
|
1395
|
-
const resultsGroupedByFilePath = groupByFilePath(scanResults);
|
|
1396
|
-
return resultsGroupedByFilePath.map((result) => {
|
|
1397
|
-
const { projectName, targetFile } = computePaths(result.filePath);
|
|
1398
|
-
return {
|
|
1399
|
-
projectName,
|
|
1400
|
-
targetFile,
|
|
1401
|
-
filePath: result.filePath,
|
|
1402
|
-
fileType: result.fileType,
|
|
1403
|
-
projectType: result.projectType,
|
|
1404
|
-
violatedPolicies: result.violatedPolicies,
|
|
1405
|
-
};
|
|
933
|
+
function getResourceName(index, name) {
|
|
934
|
+
return index !== undefined ? `${name}["${index}"]` : name;
|
|
935
|
+
}
|
|
936
|
+
function resourceChangeReducer(scanInput, resource, isFullScan) {
|
|
937
|
+
// TODO: investigate if we need to address also `after_unknown` field.
|
|
938
|
+
const { actions, after } = resource.change || { actions: [], after: {} };
|
|
939
|
+
if (isValidResourceActions(actions, isFullScan)) {
|
|
940
|
+
const resourceForReduction = { ...resource, values: after || {} };
|
|
941
|
+
return terraformPlanReducer(scanInput, resourceForReduction);
|
|
942
|
+
}
|
|
943
|
+
return scanInput;
|
|
944
|
+
}
|
|
945
|
+
function isValidResourceActions(action, isFullScan) {
|
|
946
|
+
const VALID_ACTIONS = isFullScan
|
|
947
|
+
? types_1.VALID_RESOURCE_ACTIONS_FOR_FULL_SCAN
|
|
948
|
+
: types_1.VALID_RESOURCE_ACTIONS_FOR_DELTA_SCAN;
|
|
949
|
+
return VALID_ACTIONS.some((validAction) => {
|
|
950
|
+
if (action.length !== validAction.length) {
|
|
951
|
+
return false;
|
|
952
|
+
}
|
|
953
|
+
return validAction.every((field, idx) => action[idx] === field);
|
|
1406
954
|
});
|
|
1407
955
|
}
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
if (
|
|
1415
|
-
|
|
956
|
+
function referencedResourcesResolver(scanInput, resources) {
|
|
957
|
+
var _a, _b;
|
|
958
|
+
// check root module for references in first depth of attributes
|
|
959
|
+
for (const resource of resources) {
|
|
960
|
+
const { type, name, mode, index, expressions } = resource;
|
|
961
|
+
// don't care about references in data sources for time being
|
|
962
|
+
if (mode == 'data') {
|
|
963
|
+
continue;
|
|
1416
964
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
965
|
+
const inputKey = 'resource';
|
|
966
|
+
// only update the references in resources that have some resolved attributes already
|
|
967
|
+
const resolvedResource = (_b = (_a = scanInput[inputKey]) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b[getResourceName(index, name)];
|
|
968
|
+
if (resolvedResource && expressions) {
|
|
969
|
+
const resourceExpressions = getExpressions(expressions);
|
|
970
|
+
for (const key of Object.keys(resourceExpressions)) {
|
|
971
|
+
// only add non existing attributes. If we already have resolved value do not overwrite it with reference
|
|
972
|
+
if (!resolvedResource[key]) {
|
|
973
|
+
resolvedResource[key] = resourceExpressions[key];
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
scanInput[inputKey][type][getResourceName(index, name)] = resolvedResource;
|
|
1419
977
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
return Object.values(groupedByFilePath);
|
|
978
|
+
}
|
|
979
|
+
return scanInput;
|
|
1423
980
|
}
|
|
1424
|
-
function
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
981
|
+
function extractResourceChanges(terraformPlanJson) {
|
|
982
|
+
return terraformPlanJson.resource_changes || [];
|
|
983
|
+
}
|
|
984
|
+
function extractReferencedResources(terraformPlanJson) {
|
|
985
|
+
var _a, _b;
|
|
986
|
+
return ((_b = (_a = terraformPlanJson.configuration) === null || _a === void 0 ? void 0 : _a.root_module) === null || _b === void 0 ? void 0 : _b.resources) || [];
|
|
987
|
+
}
|
|
988
|
+
function extractResourcesForScan(terraformPlanJson, isFullScan = false) {
|
|
989
|
+
const resourceChanges = extractResourceChanges(terraformPlanJson);
|
|
990
|
+
const scanInput = resourceChanges.reduce((memo, curr) => resourceChangeReducer(memo, curr, isFullScan), {
|
|
991
|
+
resource: {},
|
|
992
|
+
data: {},
|
|
993
|
+
});
|
|
994
|
+
const referencedResources = extractReferencedResources(terraformPlanJson);
|
|
995
|
+
return referencedResourcesResolver(scanInput, referencedResources);
|
|
996
|
+
}
|
|
997
|
+
function isTerraformPlan(terraformPlanJson) {
|
|
998
|
+
const missingRequiredFields = terraformPlanJson.resource_changes === undefined;
|
|
999
|
+
return !missingRequiredFields;
|
|
1435
1000
|
}
|
|
1436
|
-
|
|
1001
|
+
exports.isTerraformPlan = isTerraformPlan;
|
|
1002
|
+
function tryParsingTerraformPlan(terraformPlanFile, terraformPlanJson, { isFullScan } = { isFullScan: false }) {
|
|
1437
1003
|
try {
|
|
1438
|
-
return
|
|
1004
|
+
return [
|
|
1005
|
+
{
|
|
1006
|
+
...terraformPlanFile,
|
|
1007
|
+
jsonContent: extractResourcesForScan(terraformPlanJson, isFullScan),
|
|
1008
|
+
engineType: types_1.EngineType.Terraform,
|
|
1009
|
+
projectType: constants_1.IacProjectType.TERRAFORM,
|
|
1010
|
+
},
|
|
1011
|
+
];
|
|
1439
1012
|
}
|
|
1440
|
-
catch (
|
|
1441
|
-
|
|
1013
|
+
catch (err) {
|
|
1014
|
+
throw new FailedToExtractResourcesInTerraformPlanError();
|
|
1442
1015
|
}
|
|
1443
1016
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1454
|
-
exports.formatAndShareResults = void 0;
|
|
1455
|
-
const feature_flags_1 = __webpack_require__(63011);
|
|
1456
|
-
const cli_share_results_1 = __webpack_require__(24016);
|
|
1457
|
-
const assert_iac_options_flag_1 = __webpack_require__(33111);
|
|
1458
|
-
const share_results_formatter_1 = __webpack_require__(42564);
|
|
1459
|
-
async function formatAndShareResults({ results, options, orgPublicId, policy, tags, attributes, pathToScan, }) {
|
|
1460
|
-
const isCliReportEnabled = await feature_flags_1.isFeatureFlagSupportedForOrg('iacCliShareResults', orgPublicId);
|
|
1461
|
-
if (!isCliReportEnabled.ok) {
|
|
1462
|
-
throw new assert_iac_options_flag_1.FeatureFlagError('report', 'iacCliShareResults');
|
|
1017
|
+
exports.tryParsingTerraformPlan = tryParsingTerraformPlan;
|
|
1018
|
+
// This error is due to the complex reduction logic, so it catches scenarios we might have not covered.
|
|
1019
|
+
class FailedToExtractResourcesInTerraformPlanError extends errors_1.CustomError {
|
|
1020
|
+
constructor(message) {
|
|
1021
|
+
super(message || 'Failed to extract resources from Terraform plan JSON file');
|
|
1022
|
+
this.code = types_1.IaCErrorCodes.FailedToExtractResourcesInTerraformPlanError;
|
|
1023
|
+
this.strCode = error_utils_1.getErrorStringCode(this.code);
|
|
1024
|
+
this.userMessage =
|
|
1025
|
+
'We failed to extract resource changes from the Terraform plan file, please contact support@snyk.io, if possible with a redacted version of the file';
|
|
1463
1026
|
}
|
|
1464
|
-
const formattedResults = share_results_formatter_1.formatShareResults(results);
|
|
1465
|
-
return await cli_share_results_1.shareResults({
|
|
1466
|
-
results: formattedResults,
|
|
1467
|
-
policy,
|
|
1468
|
-
tags,
|
|
1469
|
-
attributes,
|
|
1470
|
-
options,
|
|
1471
|
-
pathToScan,
|
|
1472
|
-
});
|
|
1473
1027
|
}
|
|
1474
|
-
exports.
|
|
1028
|
+
exports.FailedToExtractResourcesInTerraformPlanError = FailedToExtractResourcesInTerraformPlanError;
|
|
1475
1029
|
|
|
1476
1030
|
|
|
1477
1031
|
/***/ }),
|
|
1478
1032
|
|
|
1479
|
-
/***/
|
|
1033
|
+
/***/ 40008:
|
|
1480
1034
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1481
1035
|
|
|
1482
1036
|
"use strict";
|
|
@@ -1557,7 +1111,7 @@ async function readGitInfoForProjectRoot(projectRoot) {
|
|
|
1557
1111
|
|
|
1558
1112
|
/***/ }),
|
|
1559
1113
|
|
|
1560
|
-
/***/
|
|
1114
|
+
/***/ 30537:
|
|
1561
1115
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1562
1116
|
|
|
1563
1117
|
"use strict";
|
|
@@ -1610,39 +1164,31 @@ class FailedToExtractLineNumberError extends errors_1.CustomError {
|
|
|
1610
1164
|
|
|
1611
1165
|
/***/ }),
|
|
1612
1166
|
|
|
1613
|
-
/***/
|
|
1167
|
+
/***/ 1229:
|
|
1614
1168
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1615
1169
|
|
|
1616
1170
|
"use strict";
|
|
1617
1171
|
|
|
1618
1172
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1619
|
-
exports.
|
|
1620
|
-
const
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
orgPublicId,
|
|
1631
|
-
policy,
|
|
1632
|
-
tags,
|
|
1633
|
-
attributes,
|
|
1634
|
-
projectRoot,
|
|
1635
|
-
}));
|
|
1173
|
+
exports.SingleGroupResultsProcessor = void 0;
|
|
1174
|
+
const process_results_1 = __webpack_require__(78744);
|
|
1175
|
+
class SingleGroupResultsProcessor {
|
|
1176
|
+
constructor(projectRoot, orgPublicId, iacOrgSettings, options) {
|
|
1177
|
+
this.projectRoot = projectRoot;
|
|
1178
|
+
this.orgPublicId = orgPublicId;
|
|
1179
|
+
this.iacOrgSettings = iacOrgSettings;
|
|
1180
|
+
this.options = options;
|
|
1181
|
+
}
|
|
1182
|
+
processResults(resultsWithCustomSeverities, policy, tags, attributes) {
|
|
1183
|
+
return process_results_1.processResults(resultsWithCustomSeverities, this.orgPublicId, this.iacOrgSettings, policy, tags, attributes, this.options, this.projectRoot);
|
|
1636
1184
|
}
|
|
1637
|
-
const formattedResults = measurable_methods_1.formatScanResultsV2(resultsWithCustomSeverities, options, iacOrgSettings.meta, projectPublicIds, projectRoot, gitRemoteUrl);
|
|
1638
|
-
return policy_1.filterIgnoredIssues(policy, formattedResults);
|
|
1639
1185
|
}
|
|
1640
|
-
exports.
|
|
1186
|
+
exports.SingleGroupResultsProcessor = SingleGroupResultsProcessor;
|
|
1641
1187
|
|
|
1642
1188
|
|
|
1643
1189
|
/***/ }),
|
|
1644
1190
|
|
|
1645
|
-
/***/
|
|
1191
|
+
/***/ 91434:
|
|
1646
1192
|
/***/ ((__unused_webpack_module, exports) => {
|
|
1647
1193
|
|
|
1648
1194
|
"use strict";
|
|
@@ -1708,7 +1254,39 @@ function toFormattedResult(adapter) {
|
|
|
1708
1254
|
|
|
1709
1255
|
/***/ }),
|
|
1710
1256
|
|
|
1711
|
-
/***/
|
|
1257
|
+
/***/ 78744:
|
|
1258
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1259
|
+
|
|
1260
|
+
"use strict";
|
|
1261
|
+
|
|
1262
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1263
|
+
exports.processResults = void 0;
|
|
1264
|
+
const policy_1 = __webpack_require__(91434);
|
|
1265
|
+
const share_results_1 = __webpack_require__(68971);
|
|
1266
|
+
const measurable_methods_1 = __webpack_require__(5687);
|
|
1267
|
+
async function processResults(resultsWithCustomSeverities, orgPublicId, iacOrgSettings, policy, tags, attributes, options, projectRoot) {
|
|
1268
|
+
let projectPublicIds = {};
|
|
1269
|
+
let gitRemoteUrl;
|
|
1270
|
+
if (options.report) {
|
|
1271
|
+
({ projectPublicIds, gitRemoteUrl } = await share_results_1.formatAndShareResults({
|
|
1272
|
+
results: resultsWithCustomSeverities,
|
|
1273
|
+
options,
|
|
1274
|
+
orgPublicId,
|
|
1275
|
+
policy,
|
|
1276
|
+
tags,
|
|
1277
|
+
attributes,
|
|
1278
|
+
projectRoot,
|
|
1279
|
+
}));
|
|
1280
|
+
}
|
|
1281
|
+
const formattedResults = measurable_methods_1.formatScanResultsV2(resultsWithCustomSeverities, options, iacOrgSettings.meta, projectPublicIds, projectRoot, gitRemoteUrl);
|
|
1282
|
+
return policy_1.filterIgnoredIssues(policy, formattedResults);
|
|
1283
|
+
}
|
|
1284
|
+
exports.processResults = processResults;
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
/***/ }),
|
|
1288
|
+
|
|
1289
|
+
/***/ 11059:
|
|
1712
1290
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1713
1291
|
|
|
1714
1292
|
"use strict";
|
|
@@ -1719,7 +1297,7 @@ const types_1 = __webpack_require__(94820);
|
|
|
1719
1297
|
const common_1 = __webpack_require__(53110);
|
|
1720
1298
|
const constants_1 = __webpack_require__(68620);
|
|
1721
1299
|
const errors_1 = __webpack_require__(55191);
|
|
1722
|
-
const extract_line_number_1 = __webpack_require__(
|
|
1300
|
+
const extract_line_number_1 = __webpack_require__(30537);
|
|
1723
1301
|
const error_utils_1 = __webpack_require__(36401);
|
|
1724
1302
|
const cloud_config_parser_1 = __webpack_require__(98611);
|
|
1725
1303
|
const path = __webpack_require__(85622);
|
|
@@ -1869,7 +1447,7 @@ function computePaths(projectRoot, filePath, pathArg = '.') {
|
|
|
1869
1447
|
|
|
1870
1448
|
/***/ }),
|
|
1871
1449
|
|
|
1872
|
-
/***/
|
|
1450
|
+
/***/ 97153:
|
|
1873
1451
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1874
1452
|
|
|
1875
1453
|
"use strict";
|
|
@@ -1923,7 +1501,7 @@ function computePaths(projectRoot, filePath) {
|
|
|
1923
1501
|
|
|
1924
1502
|
/***/ }),
|
|
1925
1503
|
|
|
1926
|
-
/***/
|
|
1504
|
+
/***/ 68971:
|
|
1927
1505
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1928
1506
|
|
|
1929
1507
|
"use strict";
|
|
@@ -1931,9 +1509,9 @@ function computePaths(projectRoot, filePath) {
|
|
|
1931
1509
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1932
1510
|
exports.formatAndShareResults = void 0;
|
|
1933
1511
|
const feature_flags_1 = __webpack_require__(63011);
|
|
1934
|
-
const cli_share_results_1 = __webpack_require__(
|
|
1512
|
+
const cli_share_results_1 = __webpack_require__(40008);
|
|
1935
1513
|
const assert_iac_options_flag_1 = __webpack_require__(33111);
|
|
1936
|
-
const share_results_formatter_1 = __webpack_require__(
|
|
1514
|
+
const share_results_formatter_1 = __webpack_require__(97153);
|
|
1937
1515
|
async function formatAndShareResults({ results, options, orgPublicId, policy, tags, attributes, projectRoot, }) {
|
|
1938
1516
|
const isCliReportEnabled = await feature_flags_1.isFeatureFlagSupportedForOrg('iacCliShareResults', orgPublicId);
|
|
1939
1517
|
if (!isCliReportEnabled.ok) {
|
|
@@ -2287,7 +1865,6 @@ const display_result_1 = __webpack_require__(89667);
|
|
|
2287
1865
|
const assert_iac_options_flag_1 = __webpack_require__(33111);
|
|
2288
1866
|
const ora = __webpack_require__(63395);
|
|
2289
1867
|
const errors_1 = __webpack_require__(55191);
|
|
2290
|
-
const path = __webpack_require__(85622);
|
|
2291
1868
|
const v2_1 = __webpack_require__(49041);
|
|
2292
1869
|
const iac_output_2 = __webpack_require__(68145);
|
|
2293
1870
|
const debug = Debug('snyk-test');
|
|
@@ -2298,12 +1875,9 @@ function buildSpinner({ options, isNewIacOutputSupported, }) {
|
|
|
2298
1875
|
}
|
|
2299
1876
|
}
|
|
2300
1877
|
exports.buildSpinner = buildSpinner;
|
|
2301
|
-
function printHeader({
|
|
1878
|
+
function printHeader({ options, isNewIacOutputSupported, }) {
|
|
2302
1879
|
if (iac_output_1.shouldLogUserMessages(options, isNewIacOutputSupported)) {
|
|
2303
1880
|
console.log(os_1.EOL + iac_output_1.iacTestTitle + os_1.EOL);
|
|
2304
|
-
if (paths.some(isOutsideCurrentWorkingDirectory)) {
|
|
2305
|
-
printCurrentWorkingDirectoryTraversalWarning();
|
|
2306
|
-
}
|
|
2307
1881
|
}
|
|
2308
1882
|
}
|
|
2309
1883
|
exports.printHeader = printHeader;
|
|
@@ -2481,23 +2055,6 @@ function buildOutput({ results, options, isNewIacOutputSupported, isIacShareCliR
|
|
|
2481
2055
|
return types_1.TestCommandResult.createHumanReadableTestCommandResult(response, stringifiedJsonData, stringifiedSarifData);
|
|
2482
2056
|
}
|
|
2483
2057
|
exports.buildOutput = buildOutput;
|
|
2484
|
-
function isOutsideCurrentWorkingDirectory(p) {
|
|
2485
|
-
return path.relative(process.cwd(), p).includes('..');
|
|
2486
|
-
}
|
|
2487
|
-
function printCurrentWorkingDirectoryTraversalWarning() {
|
|
2488
|
-
let msg = '';
|
|
2489
|
-
msg +=
|
|
2490
|
-
'Warning: Scanning paths outside the current working directory is deprecated and' +
|
|
2491
|
-
os_1.EOL;
|
|
2492
|
-
msg +=
|
|
2493
|
-
'will be removed in the future. Please see the documentation for further details:' +
|
|
2494
|
-
os_1.EOL +
|
|
2495
|
-
os_1.EOL;
|
|
2496
|
-
msg +=
|
|
2497
|
-
' https://docs.snyk.io/products/snyk-infrastructure-as-code/snyk-cli-for-infrastructure-as-code/test-your-configuration-files' +
|
|
2498
|
-
os_1.EOL;
|
|
2499
|
-
console.log(chalk_1.default.yellow(msg));
|
|
2500
|
-
}
|
|
2501
2058
|
function buildShareResultsSummary({ iacOutputMeta, options, isIacCustomRulesEntitlementEnabled, isNewIacOutputSupported, isIacShareCliResultsCustomRulesSupported, }) {
|
|
2502
2059
|
let response = '';
|
|
2503
2060
|
response += SEPARATOR + os_1.EOL + iac_output_1.formatShareResultsOutput(iacOutputMeta);
|
|
@@ -2559,16 +2116,10 @@ async function scan(iacOrgSettings, options, testSpinner, paths, orgPublicId, bu
|
|
|
2559
2116
|
let res;
|
|
2560
2117
|
try {
|
|
2561
2118
|
assert_iac_options_flag_1.assertIaCOptionsFlags(process.argv);
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
if (pathLib.relative(projectRoot, path).includes('..')) {
|
|
2565
|
-
throw new CurrentWorkingDirectoryTraversalError();
|
|
2566
|
-
}
|
|
2567
|
-
resultsProcessor = new process_results_1.SingleGroupResultsProcessor(projectRoot, orgPublicId, iacOrgSettings, testOpts);
|
|
2568
|
-
}
|
|
2569
|
-
else {
|
|
2570
|
-
resultsProcessor = new process_results_1.MultipleGroupsResultsProcessor(path, orgPublicId, iacOrgSettings, testOpts);
|
|
2119
|
+
if (pathLib.relative(projectRoot, path).includes('..')) {
|
|
2120
|
+
throw new CurrentWorkingDirectoryTraversalError(path);
|
|
2571
2121
|
}
|
|
2122
|
+
const resultsProcessor = new process_results_1.SingleGroupResultsProcessor(projectRoot, orgPublicId, iacOrgSettings, testOpts);
|
|
2572
2123
|
const { results, failures, ignoreCount } = await local_execution_1.test(resultsProcessor, path, testOpts, iacOrgSettings, rulesOrigin);
|
|
2573
2124
|
iacOutputMeta = {
|
|
2574
2125
|
orgName: (_a = results[0]) === null || _a === void 0 ? void 0 : _a.org,
|
|
@@ -2639,11 +2190,12 @@ function formatTestError(error) {
|
|
|
2639
2190
|
return errorResponse;
|
|
2640
2191
|
}
|
|
2641
2192
|
class CurrentWorkingDirectoryTraversalError extends errors_1.CustomError {
|
|
2642
|
-
constructor() {
|
|
2193
|
+
constructor(path) {
|
|
2643
2194
|
super('Path is outside the current working directory');
|
|
2644
2195
|
this.code = types_1.IaCErrorCodes.CurrentWorkingDirectoryTraversalError;
|
|
2645
2196
|
this.strCode = error_utils_1.getErrorStringCode(this.code);
|
|
2646
2197
|
this.userMessage = `Path is outside the current working directory`;
|
|
2198
|
+
this.filename = path;
|
|
2647
2199
|
}
|
|
2648
2200
|
}
|
|
2649
2201
|
|
|
@@ -2673,7 +2225,6 @@ async function test(paths, options) {
|
|
|
2673
2225
|
isNewIacOutputSupported: true,
|
|
2674
2226
|
});
|
|
2675
2227
|
output_1.printHeader({
|
|
2676
|
-
paths,
|
|
2677
2228
|
options,
|
|
2678
2229
|
isNewIacOutputSupported: true,
|
|
2679
2230
|
});
|
|
@@ -3670,73 +3221,6 @@ function metadataForVuln(vuln) {
|
|
|
3670
3221
|
}
|
|
3671
3222
|
|
|
3672
3223
|
|
|
3673
|
-
/***/ }),
|
|
3674
|
-
|
|
3675
|
-
/***/ 24016:
|
|
3676
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
3677
|
-
|
|
3678
|
-
"use strict";
|
|
3679
|
-
|
|
3680
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3681
|
-
exports.shareResults = void 0;
|
|
3682
|
-
const config_1 = __webpack_require__(25425);
|
|
3683
|
-
const request_1 = __webpack_require__(52050);
|
|
3684
|
-
const api_token_1 = __webpack_require__(95181);
|
|
3685
|
-
const envelope_formatters_1 = __webpack_require__(88784);
|
|
3686
|
-
const git_1 = __webpack_require__(24850);
|
|
3687
|
-
const analytics = __webpack_require__(82744);
|
|
3688
|
-
const dev_count_analysis_1 = __webpack_require__(73898);
|
|
3689
|
-
const Debug = __webpack_require__(15158);
|
|
3690
|
-
const errors_1 = __webpack_require__(55191);
|
|
3691
|
-
const debug = Debug('iac-cli-share-results');
|
|
3692
|
-
const usage_tracking_1 = __webpack_require__(70413);
|
|
3693
|
-
const git_2 = __webpack_require__(82421);
|
|
3694
|
-
async function shareResults({ results, policy, tags, attributes, options, pathToScan, }) {
|
|
3695
|
-
var _a, _b;
|
|
3696
|
-
const gitTarget = (await git_1.getInfo({
|
|
3697
|
-
isFromContainer: false,
|
|
3698
|
-
cwd: git_2.getWorkingDirectoryForPath(pathToScan),
|
|
3699
|
-
}));
|
|
3700
|
-
const scanResults = results.map((result) => envelope_formatters_1.convertIacResultToScanResult(result, policy, gitTarget, options));
|
|
3701
|
-
let contributors = [];
|
|
3702
|
-
if (gitTarget.remoteUrl) {
|
|
3703
|
-
if (analytics.allowAnalytics()) {
|
|
3704
|
-
try {
|
|
3705
|
-
contributors = await dev_count_analysis_1.getContributors();
|
|
3706
|
-
}
|
|
3707
|
-
catch (err) {
|
|
3708
|
-
debug('error getting repo contributors', err);
|
|
3709
|
-
}
|
|
3710
|
-
}
|
|
3711
|
-
}
|
|
3712
|
-
const { res, body } = await request_1.makeRequest({
|
|
3713
|
-
method: 'POST',
|
|
3714
|
-
url: `${config_1.default.API}/iac-cli-share-results`,
|
|
3715
|
-
json: true,
|
|
3716
|
-
qs: { org: (_a = options === null || options === void 0 ? void 0 : options.org) !== null && _a !== void 0 ? _a : config_1.default.org },
|
|
3717
|
-
headers: {
|
|
3718
|
-
authorization: api_token_1.getAuthHeader(),
|
|
3719
|
-
},
|
|
3720
|
-
body: {
|
|
3721
|
-
scanResults,
|
|
3722
|
-
contributors,
|
|
3723
|
-
tags,
|
|
3724
|
-
attributes,
|
|
3725
|
-
},
|
|
3726
|
-
});
|
|
3727
|
-
switch (res.statusCode) {
|
|
3728
|
-
case 401:
|
|
3729
|
-
throw errors_1.AuthFailedError();
|
|
3730
|
-
case 422:
|
|
3731
|
-
throw new errors_1.ValidationError((_b = res.body.error) !== null && _b !== void 0 ? _b : 'An error occurred, please contact Snyk support');
|
|
3732
|
-
case 429:
|
|
3733
|
-
throw new usage_tracking_1.TestLimitReachedError();
|
|
3734
|
-
}
|
|
3735
|
-
return { projectPublicIds: body, gitRemoteUrl: gitTarget === null || gitTarget === void 0 ? void 0 : gitTarget.remoteUrl };
|
|
3736
|
-
}
|
|
3737
|
-
exports.shareResults = shareResults;
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
3224
|
/***/ }),
|
|
3741
3225
|
|
|
3742
3226
|
/***/ 88784:
|