@appland/scanner 1.56.0 → 1.57.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/CHANGELOG.md +15 -0
- package/built/algorithms/dataStructures/graph/Graph.js +53 -62
- package/built/algorithms/dataStructures/graph/GraphEdge.js +13 -16
- package/built/algorithms/dataStructures/graph/GraphVertex.js +37 -42
- package/built/algorithms/dataStructures/linked-list/LinkedList.js +33 -38
- package/built/algorithms/dataStructures/linked-list/LinkedListNode.js +6 -10
- package/built/algorithms/graph/depth-first-search/index.js +7 -8
- package/built/algorithms/graph/detect-cycle/index.js +15 -16
- package/built/algorithms/utils/Comparator.js +19 -21
- package/built/analyzer/recordSecrets.js +7 -30
- package/built/analyzer/secretsRegexes.js +8 -9
- package/built/appMapIndex.js +18 -20
- package/built/check.js +16 -18
- package/built/checkInstance.js +26 -48
- package/built/cli/ci/command.js +61 -156
- package/built/cli/ci/options.js +0 -1
- package/built/cli/codeVersionArgs.js +0 -1
- package/built/cli/exitCode.js +0 -1
- package/built/cli/fail.js +2 -3
- package/built/cli/merge/command.js +21 -63
- package/built/cli/merge/options.js +0 -1
- package/built/cli/reportUploadURL.js +2 -3
- package/built/cli/resolveAppId.js +34 -85
- package/built/cli/scan/command.js +52 -94
- package/built/cli/scan/formatReport.js +16 -89
- package/built/cli/scan/options.js +0 -1
- package/built/cli/scan/scanner.js +38 -117
- package/built/cli/scan/singleScan.js +61 -109
- package/built/cli/scan/watchScan.js +32 -82
- package/built/cli/scan.js +39 -132
- package/built/cli/scanArgs.js +0 -1
- package/built/cli/scanOptions.js +0 -1
- package/built/cli/updateCommitStatus.js +10 -47
- package/built/cli/upload/command.js +20 -64
- package/built/cli/upload/options.js +0 -1
- package/built/cli/upload/pruneAppMap.js +16 -0
- package/built/cli/upload.js +91 -172
- package/built/cli/validateFile.js +13 -52
- package/built/cli.js +34 -21
- package/built/configuration/configurationProvider.js +148 -233
- package/built/configuration/schema/options.json +76 -76
- package/built/configuration/types/checkConfig.js +0 -1
- package/built/configuration/types/configuration.js +0 -1
- package/built/configuration/types/matchEventConfig.js +0 -1
- package/built/configuration/types/matchPatternConfig.js +0 -1
- package/built/database/index.js +33 -127
- package/built/database/visit.js +16 -66
- package/built/errors.js +4 -30
- package/built/eventUtil.js +10 -35
- package/built/findings.js +3 -4
- package/built/integration/appland/app/exists.js +33 -76
- package/built/integration/appland/app/listFindingStatus.js +3 -36
- package/built/integration/appland/appMap/create.js +38 -89
- package/built/integration/appland/location.js +0 -1
- package/built/integration/appland/mapset/create.js +34 -85
- package/built/integration/appland/retry.js +10 -11
- package/built/integration/appland/retryOptions.js +0 -1
- package/built/integration/appland/scannerJob/create.js +34 -84
- package/built/integration/appland/scannerJob/merge.js +28 -74
- package/built/integration/appland/scannerJob.js +0 -1
- package/built/integration/github/commitStatus.js +3 -4
- package/built/integration/vars.js +1 -2
- package/built/openapi/index.js +39 -83
- package/built/report/appMapMetadata.js +0 -1
- package/built/report/findingSummary.js +0 -1
- package/built/report/findingsReport.js +14 -16
- package/built/report/scanResults.js +18 -45
- package/built/report/scanSummary.js +0 -1
- package/built/report/summaryReport.js +12 -13
- package/built/ruleChecker.js +146 -297
- package/built/rules/authzBeforeAuthn.js +25 -59
- package/built/rules/circularDependency.js +69 -101
- package/built/rules/deserializationOfUntrustedData.js +29 -63
- package/built/rules/execOfUntrustedCommand.js +28 -62
- package/built/rules/http-500/metadata.js +0 -1
- package/built/rules/http-500/rule.js +2 -3
- package/built/rules/illegalPackageDependency.js +16 -18
- package/built/rules/incompatibleHttpClientRequest.js +30 -69
- package/built/rules/insecureCompare.js +12 -13
- package/built/rules/jobNotCancelled.js +13 -45
- package/built/rules/lib/hasParameterOrReceiver.js +4 -7
- package/built/rules/lib/matchEvent.js +12 -13
- package/built/rules/lib/matchPattern.js +6 -7
- package/built/rules/lib/metadata.js +0 -1
- package/built/rules/lib/parseRuleDescription.js +5 -6
- package/built/rules/lib/precedingEvents.js +7 -75
- package/built/rules/lib/rpcWithoutProtection.js +5 -28
- package/built/rules/lib/sanitizesData.js +0 -1
- package/built/rules/lib/util.js +33 -73
- package/built/rules/logoutWithoutSessionReset.js +24 -58
- package/built/rules/missingAuthentication.js +28 -28
- package/built/rules/missingContentType.js +8 -9
- package/built/rules/nPlusOneQuery.js +35 -87
- package/built/rules/queryFromInvalidPackage.js +17 -19
- package/built/rules/queryFromView.js +13 -16
- package/built/rules/rpcWithoutCircuitBreaker.js +14 -84
- package/built/rules/saveWithoutValidation.js +8 -9
- package/built/rules/secretInLog.js +29 -92
- package/built/rules/slowFunctionCall.js +16 -20
- package/built/rules/slowHttpServerRequest.js +9 -11
- package/built/rules/slowQuery.js +9 -12
- package/built/rules/tooManyJoins.js +26 -51
- package/built/rules/tooManyUpdates.js +25 -105
- package/built/rules/unbatchedMaterializedQuery.js +26 -30
- package/built/rules/updateInGetRequest.js +30 -45
- package/built/scope/commandScope.js +24 -144
- package/built/scope/httpClientRequestScope.js +11 -98
- package/built/scope/httpServerRequestScope.js +11 -98
- package/built/scope/rootScope.js +11 -98
- package/built/scope/scopeImpl.js +10 -82
- package/built/scope/scopeIterator.js +6 -10
- package/built/scope/sqlTransactionScope.js +24 -122
- package/built/sqlWarning.js +9 -35
- package/built/telemetry.js +215 -0
- package/built/wellKnownLabels.js +0 -1
- package/package.json +7 -3
- package/built/algorithms/dataStructures/graph/Graph.js.map +0 -1
- package/built/algorithms/dataStructures/graph/GraphEdge.js.map +0 -1
- package/built/algorithms/dataStructures/graph/GraphVertex.js.map +0 -1
- package/built/algorithms/dataStructures/linked-list/LinkedList.js.map +0 -1
- package/built/algorithms/dataStructures/linked-list/LinkedListNode.js.map +0 -1
- package/built/algorithms/graph/depth-first-search/index.js.map +0 -1
- package/built/algorithms/graph/detect-cycle/index.js.map +0 -1
- package/built/algorithms/utils/Comparator.js.map +0 -1
- package/built/analyzer/recordSecrets.js.map +0 -1
- package/built/analyzer/secretsRegexes.js.map +0 -1
- package/built/appMapIndex.js.map +0 -1
- package/built/check.js.map +0 -1
- package/built/checkInstance.js.map +0 -1
- package/built/cli/ci/command.js.map +0 -1
- package/built/cli/ci/options.js.map +0 -1
- package/built/cli/codeVersionArgs.js.map +0 -1
- package/built/cli/exitCode.js.map +0 -1
- package/built/cli/fail.js.map +0 -1
- package/built/cli/merge/command.js.map +0 -1
- package/built/cli/merge/options.js.map +0 -1
- package/built/cli/reportUploadURL.js.map +0 -1
- package/built/cli/resolveAppId.js.map +0 -1
- package/built/cli/scan/command.js.map +0 -1
- package/built/cli/scan/formatReport.js.map +0 -1
- package/built/cli/scan/options.js.map +0 -1
- package/built/cli/scan/scanner.js.map +0 -1
- package/built/cli/scan/singleScan.js.map +0 -1
- package/built/cli/scan/watchScan.js.map +0 -1
- package/built/cli/scan.js.map +0 -1
- package/built/cli/scanArgs.js.map +0 -1
- package/built/cli/scanOptions.js.map +0 -1
- package/built/cli/updateCommitStatus.js.map +0 -1
- package/built/cli/upload/command.js.map +0 -1
- package/built/cli/upload/options.js.map +0 -1
- package/built/cli/upload.js.map +0 -1
- package/built/cli/validateFile.js.map +0 -1
- package/built/cli.js.map +0 -1
- package/built/configuration/configurationProvider.js.map +0 -1
- package/built/configuration/types/checkConfig.js.map +0 -1
- package/built/configuration/types/configuration.js.map +0 -1
- package/built/configuration/types/matchEventConfig.js.map +0 -1
- package/built/configuration/types/matchPatternConfig.js.map +0 -1
- package/built/database/index.js.map +0 -1
- package/built/database/visit.js.map +0 -1
- package/built/errors.js.map +0 -1
- package/built/eventUtil.js.map +0 -1
- package/built/findings.js.map +0 -1
- package/built/integration/appland/app/exists.js.map +0 -1
- package/built/integration/appland/app/listFindingStatus.js.map +0 -1
- package/built/integration/appland/appMap/create.js.map +0 -1
- package/built/integration/appland/location.js.map +0 -1
- package/built/integration/appland/mapset/create.js.map +0 -1
- package/built/integration/appland/retry.js.map +0 -1
- package/built/integration/appland/retryOptions.js.map +0 -1
- package/built/integration/appland/scannerJob/create.js.map +0 -1
- package/built/integration/appland/scannerJob/merge.js.map +0 -1
- package/built/integration/appland/scannerJob.js.map +0 -1
- package/built/integration/github/commitStatus.js.map +0 -1
- package/built/integration/vars.js.map +0 -1
- package/built/openapi/index.js.map +0 -1
- package/built/openapi/method.js +0 -120
- package/built/openapi/method.js.map +0 -1
- package/built/openapi/model.js +0 -49
- package/built/openapi/model.js.map +0 -1
- package/built/openapi/path.js +0 -36
- package/built/openapi/path.js.map +0 -1
- package/built/openapi/provider.js +0 -133
- package/built/openapi/provider.js.map +0 -1
- package/built/openapi/response.js +0 -59
- package/built/openapi/response.js.map +0 -1
- package/built/openapi/rpcRequest.js +0 -130
- package/built/openapi/rpcRequest.js.map +0 -1
- package/built/openapi/schema.js +0 -42
- package/built/openapi/schema.js.map +0 -1
- package/built/openapi/securitySchemes.js +0 -32
- package/built/openapi/securitySchemes.js.map +0 -1
- package/built/openapi/statusCodes.js +0 -68
- package/built/openapi/statusCodes.js.map +0 -1
- package/built/openapi/util.js +0 -91
- package/built/openapi/util.js.map +0 -1
- package/built/report/appMapMetadata.js.map +0 -1
- package/built/report/findingSummary.js.map +0 -1
- package/built/report/findingsReport.js.map +0 -1
- package/built/report/scanResults.js.map +0 -1
- package/built/report/scanSummary.js.map +0 -1
- package/built/report/summaryReport.js.map +0 -1
- package/built/ruleChecker.js.map +0 -1
- package/built/rules/authzBeforeAuthn.js.map +0 -1
- package/built/rules/circularDependency.js.map +0 -1
- package/built/rules/deserializationOfUntrustedData.js.map +0 -1
- package/built/rules/execOfUntrustedCommand.js.map +0 -1
- package/built/rules/http-500/metadata.js.map +0 -1
- package/built/rules/http-500/rule.js.map +0 -1
- package/built/rules/illegalPackageDependency.js.map +0 -1
- package/built/rules/incompatibleHttpClientRequest.js.map +0 -1
- package/built/rules/insecureCompare.js.map +0 -1
- package/built/rules/jobNotCancelled.js.map +0 -1
- package/built/rules/lib/hasParameterOrReceiver.js.map +0 -1
- package/built/rules/lib/matchEvent.js.map +0 -1
- package/built/rules/lib/matchPattern.js.map +0 -1
- package/built/rules/lib/metadata.js.map +0 -1
- package/built/rules/lib/parseRuleDescription.js.map +0 -1
- package/built/rules/lib/precedingEvents.js.map +0 -1
- package/built/rules/lib/rpcWithoutProtection.js.map +0 -1
- package/built/rules/lib/sanitizesData.js.map +0 -1
- package/built/rules/lib/util.js.map +0 -1
- package/built/rules/logoutWithoutSessionReset.js.map +0 -1
- package/built/rules/missingAuthentication.js.map +0 -1
- package/built/rules/missingContentType.js.map +0 -1
- package/built/rules/nPlusOneQuery.js.map +0 -1
- package/built/rules/queryFromInvalidPackage.js.map +0 -1
- package/built/rules/queryFromView.js.map +0 -1
- package/built/rules/rpcWithoutCircuitBreaker.js.map +0 -1
- package/built/rules/saveWithoutValidation.js.map +0 -1
- package/built/rules/secretInLog.js.map +0 -1
- package/built/rules/slowFunctionCall.js.map +0 -1
- package/built/rules/slowHttpServerRequest.js.map +0 -1
- package/built/rules/slowQuery.js.map +0 -1
- package/built/rules/tooManyJoins.js.map +0 -1
- package/built/rules/tooManyUpdates.js.map +0 -1
- package/built/rules/unbatchedMaterializedQuery.js.map +0 -1
- package/built/rules/updateInGetRequest.js.map +0 -1
- package/built/scope/commandScope.js.map +0 -1
- package/built/scope/httpClientRequestScope.js.map +0 -1
- package/built/scope/httpServerRequestScope.js.map +0 -1
- package/built/scope/rootScope.js.map +0 -1
- package/built/scope/scopeImpl.js.map +0 -1
- package/built/scope/scopeIterator.js.map +0 -1
- package/built/scope/sqlTransactionScope.js.map +0 -1
- package/built/sqlWarning.js.map +0 -1
- package/built/wellKnownLabels.js.map +0 -1
|
@@ -31,272 +31,187 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (_) try {
|
|
41
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
36
|
};
|
|
64
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
38
|
exports.parseConfigFile = exports.loadConfig = exports.loadRule = void 0;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
39
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
40
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
41
|
+
const fs_1 = require("fs");
|
|
42
|
+
const check_1 = __importDefault(require("../check"));
|
|
43
|
+
const util_1 = require("../rules/lib/util");
|
|
44
|
+
const matchEvent_1 = require("../rules/lib/matchEvent");
|
|
45
|
+
const parseRuleDescription_1 = __importDefault(require("../rules/lib/parseRuleDescription"));
|
|
46
|
+
const options_json_1 = __importDefault(require("./schema/options.json"));
|
|
47
|
+
const match_pattern_config_json_1 = __importDefault(require("./schema/match-pattern-config.json"));
|
|
48
|
+
const url_1 = require("url");
|
|
49
|
+
const util_2 = require("util");
|
|
50
|
+
const path_1 = require("path");
|
|
51
|
+
const ajv = new ajv_1.default();
|
|
79
52
|
ajv.addSchema(match_pattern_config_json_1.default);
|
|
80
53
|
function loadFromFile(ruleName) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return [3 /*break*/, 3];
|
|
92
|
-
case 2:
|
|
93
|
-
e_1 = _a.sent();
|
|
94
|
-
return [2 /*return*/];
|
|
95
|
-
case 3: return [2 /*return*/, ruleSpec.default];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}); };
|
|
54
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
let ruleSpec;
|
|
56
|
+
try {
|
|
57
|
+
ruleSpec = yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}`)));
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
return ruleSpec.default;
|
|
63
|
+
});
|
|
99
64
|
}
|
|
100
65
|
function loadFromDir(ruleName) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
id: (0, util_1.dasherize)(ruleName),
|
|
148
|
-
title: metadata.title,
|
|
149
|
-
description: description,
|
|
150
|
-
url: "https://appland.com/docs/analysis/rules-reference.html#".concat((0, util_1.dasherize)(ruleName)),
|
|
151
|
-
labels: metadata.labels || [],
|
|
152
|
-
scope: metadata.scope,
|
|
153
|
-
enumerateScope: metadata.enumerateScope,
|
|
154
|
-
impactDomain: metadata.impactDomain,
|
|
155
|
-
references: references,
|
|
156
|
-
Options: options,
|
|
157
|
-
build: rule,
|
|
158
|
-
}];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}); };
|
|
66
|
+
return () => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
let metadata;
|
|
68
|
+
let rule;
|
|
69
|
+
let options;
|
|
70
|
+
try {
|
|
71
|
+
metadata = (yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}/metadata`)))).default;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
rule = (yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}/rule`)))).default;
|
|
78
|
+
}
|
|
79
|
+
catch (_a) {
|
|
80
|
+
console.warn(`Rule ${ruleName} has no rule.js or rule.ts file, or the file doesn't have a default export`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if ((0, util_1.verbose)())
|
|
84
|
+
console.log(`Loaded rule ${ruleName}: ${rule}`);
|
|
85
|
+
try {
|
|
86
|
+
options = yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}/options`)));
|
|
87
|
+
if ((0, util_1.verbose)())
|
|
88
|
+
console.log(`Loaded rule ${ruleName} options: ${options}`);
|
|
89
|
+
}
|
|
90
|
+
catch (_b) {
|
|
91
|
+
// This is OK
|
|
92
|
+
}
|
|
93
|
+
const description = (0, parseRuleDescription_1.default)(ruleName);
|
|
94
|
+
const references = Object.keys(metadata.references || {}).reduce((memo, key) => {
|
|
95
|
+
memo[key] = new url_1.URL(metadata.references[key]);
|
|
96
|
+
return memo;
|
|
97
|
+
}, {});
|
|
98
|
+
return {
|
|
99
|
+
id: (0, util_1.dasherize)(ruleName),
|
|
100
|
+
title: metadata.title,
|
|
101
|
+
description,
|
|
102
|
+
url: `https://appland.com/docs/analysis/rules-reference.html#${(0, util_1.dasherize)(ruleName)}`,
|
|
103
|
+
labels: metadata.labels || [],
|
|
104
|
+
scope: metadata.scope,
|
|
105
|
+
enumerateScope: metadata.enumerateScope,
|
|
106
|
+
impactDomain: metadata.impactDomain,
|
|
107
|
+
references,
|
|
108
|
+
Options: options,
|
|
109
|
+
build: rule,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
162
112
|
}
|
|
163
113
|
function buildBuiltinCheck(config) {
|
|
164
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if ((0, util_1.verbose)()) {
|
|
198
|
-
console.log("Loaded check: ".concat(check));
|
|
199
|
-
}
|
|
200
|
-
return [2 /*return*/, check];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const rule = yield loadRule(config.rule);
|
|
116
|
+
if ((0, util_1.verbose)()) {
|
|
117
|
+
console.log(`Loaded rule: ${rule}`);
|
|
118
|
+
}
|
|
119
|
+
let options;
|
|
120
|
+
if (rule.Options) {
|
|
121
|
+
options = new rule.Options();
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
options = {};
|
|
125
|
+
}
|
|
126
|
+
if (config.properties) {
|
|
127
|
+
Object.keys(config.properties).forEach((name) => {
|
|
128
|
+
const value = config.properties[name];
|
|
129
|
+
options[name] = value;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const check = new check_1.default(rule, options);
|
|
133
|
+
if (config.scope) {
|
|
134
|
+
check.scope = config.scope;
|
|
135
|
+
}
|
|
136
|
+
if (config.id) {
|
|
137
|
+
check.id = (0, util_1.dasherize)(config.id);
|
|
138
|
+
}
|
|
139
|
+
check.includeScope = (0, matchEvent_1.buildFilters)((config.include || []).filter((item) => item.scope).map((item) => item.scope));
|
|
140
|
+
check.excludeScope = (0, matchEvent_1.buildFilters)((config.exclude || []).filter((item) => item.scope).map((item) => item.scope));
|
|
141
|
+
check.includeEvent = (0, matchEvent_1.buildFilters)((config.include || []).filter((item) => item.event).map((item) => item.event));
|
|
142
|
+
check.excludeEvent = (0, matchEvent_1.buildFilters)((config.exclude || []).filter((item) => item.event).map((item) => item.event));
|
|
143
|
+
if ((0, util_1.verbose)()) {
|
|
144
|
+
console.log(`Loaded check: ${check}`);
|
|
145
|
+
}
|
|
146
|
+
return check;
|
|
203
147
|
});
|
|
204
148
|
}
|
|
205
|
-
|
|
206
|
-
|
|
149
|
+
const validate = (validator, data, context) => {
|
|
150
|
+
const valid = validator(data);
|
|
207
151
|
if (!valid) {
|
|
208
152
|
throw new Error(validator
|
|
209
|
-
.errors.map(
|
|
210
|
-
|
|
153
|
+
.errors.map((err) => {
|
|
154
|
+
let instance = err.instancePath;
|
|
211
155
|
if (!instance || instance === '') {
|
|
212
156
|
instance = context;
|
|
213
157
|
}
|
|
214
|
-
return
|
|
158
|
+
return `${instance} ${err.message} (${err.schemaPath})`;
|
|
215
159
|
})
|
|
216
160
|
.join(', '));
|
|
217
161
|
}
|
|
218
162
|
};
|
|
219
163
|
function loadRule(ruleName) {
|
|
220
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
switch (_a.label) {
|
|
235
|
-
case 0: return [4 /*yield*/, loader()];
|
|
236
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
}); }))];
|
|
240
|
-
case 1:
|
|
241
|
-
rules = _a.sent();
|
|
242
|
-
rule = rules.find(function (rule) { return rule; });
|
|
243
|
-
if (!rule)
|
|
244
|
-
throw new Error("Rule ".concat(ruleName, " not found"));
|
|
245
|
-
return [2 /*return*/, rule];
|
|
246
|
-
}
|
|
247
|
-
});
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const ruleId = (0, util_1.dasherize)(ruleName);
|
|
166
|
+
const rules = yield Promise.all([
|
|
167
|
+
loadFromDir(ruleId),
|
|
168
|
+
loadFromFile(ruleId),
|
|
169
|
+
loadFromDir((0, util_1.camelize)(ruleId)),
|
|
170
|
+
loadFromFile((0, util_1.camelize)(ruleId)),
|
|
171
|
+
].map((loader) => __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
return yield loader();
|
|
173
|
+
})));
|
|
174
|
+
const rule = rules.find((rule) => rule);
|
|
175
|
+
if (!rule)
|
|
176
|
+
throw new Error(`Rule ${ruleName} not found`);
|
|
177
|
+
return rule;
|
|
248
178
|
});
|
|
249
179
|
}
|
|
250
180
|
exports.loadRule = loadRule;
|
|
251
181
|
function loadConfig(config) {
|
|
252
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
validate(ajv.compile(propertiesSchema), check.properties || {}, "".concat(ruleId, " properties"));
|
|
272
|
-
});
|
|
273
|
-
return [2 /*return*/, Promise.all(config.checks.map(function (c) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
274
|
-
return [2 /*return*/, buildBuiltinCheck(c)];
|
|
275
|
-
}); }); }))];
|
|
182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
config.checks
|
|
184
|
+
.filter((check) => check.properties)
|
|
185
|
+
.forEach((check) => {
|
|
186
|
+
const ruleId = check.rule;
|
|
187
|
+
const schemaKey = [(0, util_1.capitalize)(ruleId), 'Options'].join('.');
|
|
188
|
+
if ((0, util_1.verbose)()) {
|
|
189
|
+
console.warn(schemaKey);
|
|
190
|
+
}
|
|
191
|
+
const propertiesSchema = options_json_1.default.definitions[schemaKey];
|
|
192
|
+
if (!propertiesSchema) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if ((0, util_1.verbose)()) {
|
|
196
|
+
console.warn(propertiesSchema);
|
|
197
|
+
console.warn(check.properties);
|
|
198
|
+
}
|
|
199
|
+
validate(ajv.compile(propertiesSchema), check.properties || {}, `${ruleId} properties`);
|
|
276
200
|
});
|
|
201
|
+
return Promise.all(config.checks.map((c) => __awaiter(this, void 0, void 0, function* () { return buildBuiltinCheck(c); })));
|
|
277
202
|
});
|
|
278
203
|
}
|
|
279
204
|
exports.loadConfig = loadConfig;
|
|
280
205
|
function parseConfigFile(configPath) {
|
|
281
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
console.log("Using scanner configuration file ".concat(configPath));
|
|
291
|
-
return [4 /*yield*/, fs_1.promises.readFile(configPath, 'utf-8')];
|
|
292
|
-
case 2:
|
|
293
|
-
yamlConfig = _a.sent();
|
|
294
|
-
return [2 /*return*/, js_yaml_1.default.load(yamlConfig, {
|
|
295
|
-
filename: configPath,
|
|
296
|
-
})];
|
|
297
|
-
}
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
if (!(yield (0, util_2.promisify)(fs_1.exists)(configPath))) {
|
|
208
|
+
configPath = (0, path_1.join)(__dirname, '../sampleConfig/default.yml');
|
|
209
|
+
}
|
|
210
|
+
console.log(`Using scanner configuration file ${configPath}`);
|
|
211
|
+
const yamlConfig = yield fs_1.promises.readFile(configPath, 'utf-8');
|
|
212
|
+
return js_yaml_1.default.load(yamlConfig, {
|
|
213
|
+
filename: configPath,
|
|
298
214
|
});
|
|
299
215
|
});
|
|
300
216
|
}
|
|
301
217
|
exports.parseConfigFile = parseConfigFile;
|
|
302
|
-
//# sourceMappingURL=configurationProvider.js.map
|