@appland/scanner 1.54.1 → 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 +31 -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 -147
- 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 +58 -233
- package/built/cli/scan/formatReport.js +44 -0
- package/built/cli/scan/options.js +0 -1
- package/built/cli/scan/scanner.js +38 -117
- package/built/cli/scan/singleScan.js +80 -0
- package/built/cli/scan/watchScan.js +84 -0
- package/built/cli/scan.js +39 -132
- package/built/cli/scanArgs.js +2 -4
- package/built/cli/scanOptions.js +0 -1
- package/built/cli/updateCommitStatus.js +10 -47
- package/built/cli/upload/command.js +21 -65
- 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 -48
- package/built/cli.js +34 -21
- package/built/configuration/configurationProvider.js +148 -227
- 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 +5 -38
- 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 +48 -25
- 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 +30 -93
- 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 +10 -4
- 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/options.js.map +0 -1
- package/built/cli/scan/scanner.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
|
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const util_1 = require("../rules/lib/util");
|
|
8
8
|
function summarizeFindings(findings) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const result = findings.reduce((memo, finding) => {
|
|
10
|
+
let findingSummary = memo[finding.ruleId];
|
|
11
11
|
if (findingSummary) {
|
|
12
12
|
findingSummary.findingTotal += 1;
|
|
13
13
|
if (!findingSummary.findingHashes.has(finding.hash)) {
|
|
@@ -27,24 +27,23 @@ function summarizeFindings(findings) {
|
|
|
27
27
|
}
|
|
28
28
|
return memo;
|
|
29
29
|
}, {});
|
|
30
|
-
Object.values(result).forEach(
|
|
30
|
+
Object.values(result).forEach((findingSummary) => (findingSummary.messages = findingSummary.messages.sort()));
|
|
31
31
|
return Object.values(result);
|
|
32
32
|
}
|
|
33
33
|
function default_1(summary, colorize) {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const matchedStr = `${summary.summary.numFindings} ${(0, util_1.pluralize)('finding', summary.summary.numFindings)} (${new Set(summary.findings.map((finding) => finding.hash)).size} unique)`;
|
|
35
|
+
const colouredMatchedStr = colorize ? chalk_1.default.stderr.magenta(matchedStr) : matchedStr;
|
|
36
36
|
console.log();
|
|
37
37
|
console.log(colouredMatchedStr);
|
|
38
38
|
summarizeFindings(summary.findings)
|
|
39
|
-
.sort(
|
|
40
|
-
.forEach(
|
|
41
|
-
|
|
39
|
+
.sort((a, b) => a.ruleTitle.localeCompare(b.ruleTitle))
|
|
40
|
+
.forEach((finding) => {
|
|
41
|
+
const casesStr = `\t- ${finding.ruleTitle} (${finding.ruleId}) : ${finding.findingTotal} ${(0, util_1.pluralize)('case', finding.findingTotal)} (${finding.findingHashes.size} unique)`;
|
|
42
42
|
console.log(colorize ? chalk_1.default.stderr.magenta(casesStr) : casesStr);
|
|
43
|
-
finding.messages.forEach(
|
|
44
|
-
|
|
43
|
+
finding.messages.forEach((message) => {
|
|
44
|
+
const messageStr = `\t\t${message}`;
|
|
45
45
|
console.log(colorize ? chalk_1.default.stderr.magenta(messageStr) : messageStr);
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
exports.default = default_1;
|
|
50
|
-
//# sourceMappingURL=summaryReport.js.map
|
package/built/ruleChecker.js
CHANGED
|
@@ -8,85 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __values = (this && this.__values) || function(o) {
|
|
39
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
-
if (m) return m.call(o);
|
|
41
|
-
if (o && typeof o.length === "number") return {
|
|
42
|
-
next: function () {
|
|
43
|
-
if (o && i >= o.length) o = void 0;
|
|
44
|
-
return { value: o && o[i++], done: !o };
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
};
|
|
74
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
13
|
};
|
|
77
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
const util_1 = require("./rules/lib/util");
|
|
17
|
+
const rootScope_1 = __importDefault(require("./scope/rootScope"));
|
|
18
|
+
const httpServerRequestScope_1 = __importDefault(require("./scope/httpServerRequestScope"));
|
|
19
|
+
const httpClientRequestScope_1 = __importDefault(require("./scope/httpClientRequestScope"));
|
|
20
|
+
const commandScope_1 = __importDefault(require("./scope/commandScope"));
|
|
21
|
+
const sqlTransactionScope_1 = __importDefault(require("./scope/sqlTransactionScope"));
|
|
22
|
+
const checkInstance_1 = __importDefault(require("./checkInstance"));
|
|
23
|
+
const crypto_1 = require("crypto");
|
|
24
|
+
const eventUtil_1 = require("./eventUtil");
|
|
25
|
+
class RuleChecker {
|
|
26
|
+
constructor() {
|
|
90
27
|
this.scopes = {
|
|
91
28
|
root: new rootScope_1.default(),
|
|
92
29
|
command: new commandScope_1.default(),
|
|
@@ -95,231 +32,143 @@ var RuleChecker = /** @class */ (function () {
|
|
|
95
32
|
transaction: new sqlTransactionScope_1.default(),
|
|
96
33
|
};
|
|
97
34
|
}
|
|
98
|
-
|
|
99
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
case 1:
|
|
105
|
-
numScopesChecked = _a.sent();
|
|
106
|
-
if (!(numScopesChecked === 0 && check.scope === 'command')) return [3 /*break*/, 3];
|
|
107
|
-
return [4 /*yield*/, this.checkScope(appMapFile, appMapIndex, check, 'root', findings)];
|
|
108
|
-
case 2:
|
|
109
|
-
_a.sent();
|
|
110
|
-
_a.label = 3;
|
|
111
|
-
case 3: return [2 /*return*/];
|
|
112
|
-
}
|
|
113
|
-
});
|
|
35
|
+
check(appMapFile, appMapIndex, check, findings) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const numScopesChecked = yield this.checkScope(appMapFile, appMapIndex, check, check.scope, findings);
|
|
38
|
+
if (numScopesChecked === 0 && check.scope === 'command') {
|
|
39
|
+
yield this.checkScope(appMapFile, appMapIndex, check, 'root', findings);
|
|
40
|
+
}
|
|
114
41
|
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return [4 /*yield*/, events[i]];
|
|
141
|
-
case 2:
|
|
142
|
-
_a.sent();
|
|
143
|
-
_a.label = 3;
|
|
144
|
-
case 3:
|
|
145
|
-
i++;
|
|
146
|
-
return [3 /*break*/, 1];
|
|
147
|
-
case 4: return [2 /*return*/];
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
numScopes = 0;
|
|
152
|
-
_g.label = 1;
|
|
153
|
-
case 1:
|
|
154
|
-
_g.trys.push([1, 15, 16, 17]);
|
|
155
|
-
_a = __values(scopeIterator.scopes(callEvents())), _b = _a.next();
|
|
156
|
-
_g.label = 2;
|
|
157
|
-
case 2:
|
|
158
|
-
if (!!_b.done) return [3 /*break*/, 14];
|
|
159
|
-
scope_1 = _b.value;
|
|
160
|
-
numScopes += 1;
|
|
161
|
-
if ((0, util_1.verbose)()) {
|
|
162
|
-
console.warn("Scope ".concat(scope_1.scope));
|
|
163
|
-
}
|
|
164
|
-
checkInstance = new checkInstance_1.default(check);
|
|
165
|
-
if (!check.filterScope(scope_1.scope, appMapIndex)) {
|
|
166
|
-
return [3 /*break*/, 13];
|
|
167
|
-
}
|
|
168
|
-
if (!checkInstance.enumerateScope) return [3 /*break*/, 11];
|
|
169
|
-
_g.label = 3;
|
|
170
|
-
case 3:
|
|
171
|
-
_g.trys.push([3, 8, 9, 10]);
|
|
172
|
-
_c = (e_1 = void 0, __values(scope_1.events())), _d = _c.next();
|
|
173
|
-
_g.label = 4;
|
|
174
|
-
case 4:
|
|
175
|
-
if (!!_d.done) return [3 /*break*/, 7];
|
|
176
|
-
event = _d.value;
|
|
177
|
-
return [4 /*yield*/, this.checkEvent(event, scope_1.scope, appMapFile, appMapIndex, checkInstance, findings)];
|
|
178
|
-
case 5:
|
|
179
|
-
_g.sent();
|
|
180
|
-
_g.label = 6;
|
|
181
|
-
case 6:
|
|
182
|
-
_d = _c.next();
|
|
183
|
-
return [3 /*break*/, 4];
|
|
184
|
-
case 7: return [3 /*break*/, 10];
|
|
185
|
-
case 8:
|
|
186
|
-
e_1_1 = _g.sent();
|
|
187
|
-
e_1 = { error: e_1_1 };
|
|
188
|
-
return [3 /*break*/, 10];
|
|
189
|
-
case 9:
|
|
190
|
-
try {
|
|
191
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
192
|
-
}
|
|
193
|
-
finally { if (e_1) throw e_1.error; }
|
|
194
|
-
return [7 /*endfinally*/];
|
|
195
|
-
case 10: return [3 /*break*/, 13];
|
|
196
|
-
case 11: return [4 /*yield*/, this.checkEvent(scope_1.scope, scope_1.scope, appMapFile, appMapIndex, checkInstance, findings)];
|
|
197
|
-
case 12:
|
|
198
|
-
_g.sent();
|
|
199
|
-
_g.label = 13;
|
|
200
|
-
case 13:
|
|
201
|
-
_b = _a.next();
|
|
202
|
-
return [3 /*break*/, 2];
|
|
203
|
-
case 14: return [3 /*break*/, 17];
|
|
204
|
-
case 15:
|
|
205
|
-
e_2_1 = _g.sent();
|
|
206
|
-
e_2 = { error: e_2_1 };
|
|
207
|
-
return [3 /*break*/, 17];
|
|
208
|
-
case 16:
|
|
209
|
-
try {
|
|
210
|
-
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
211
|
-
}
|
|
212
|
-
finally { if (e_2) throw e_2.error; }
|
|
213
|
-
return [7 /*endfinally*/];
|
|
214
|
-
case 17: return [2 /*return*/, numScopes];
|
|
42
|
+
}
|
|
43
|
+
checkScope(appMapFile, appMapIndex, check, scope, findings) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if ((0, util_1.verbose)()) {
|
|
46
|
+
console.warn(`Checking AppMap ${appMapIndex.appMap.name} with scope ${scope}`);
|
|
47
|
+
}
|
|
48
|
+
const scopeIterator = this.scopes[scope];
|
|
49
|
+
if (!scopeIterator) {
|
|
50
|
+
throw new errors_1.AbortError(`Invalid scope name "${scope}"`);
|
|
51
|
+
}
|
|
52
|
+
const callEvents = function* () {
|
|
53
|
+
const events = appMapIndex.appMap.events;
|
|
54
|
+
for (let i = 0; i < events.length; i++) {
|
|
55
|
+
yield events[i];
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
let numScopes = 0;
|
|
59
|
+
for (const scope of scopeIterator.scopes(callEvents())) {
|
|
60
|
+
numScopes += 1;
|
|
61
|
+
if ((0, util_1.verbose)()) {
|
|
62
|
+
console.warn(`Scope ${scope.scope}`);
|
|
63
|
+
}
|
|
64
|
+
const checkInstance = new checkInstance_1.default(check);
|
|
65
|
+
if (!check.filterScope(scope.scope, appMapIndex)) {
|
|
66
|
+
continue;
|
|
215
67
|
}
|
|
216
|
-
|
|
68
|
+
if (checkInstance.enumerateScope) {
|
|
69
|
+
for (const event of scope.events()) {
|
|
70
|
+
yield this.checkEvent(event, scope.scope, appMapFile, appMapIndex, checkInstance, findings);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
yield this.checkEvent(scope.scope, scope.scope, appMapFile, appMapIndex, checkInstance, findings);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return numScopes;
|
|
217
78
|
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
if ((0, util_1.verbose)()) {
|
|
311
|
-
if (findings.length > numFindings) {
|
|
312
|
-
findings.forEach(function (finding) {
|
|
313
|
-
return console.log("\tFinding: ".concat(finding.ruleId, " : ").concat(finding.message));
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return [2 /*return*/];
|
|
79
|
+
}
|
|
80
|
+
checkEvent(event, scope, appMapFile, appMapIndex, checkInstance, findings) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (!event.isCall()) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if ((0, util_1.verbose)()) {
|
|
86
|
+
console.warn(`Asserting ${checkInstance.ruleId} on ${event.codeObject.fqid} event ${event.toString()}`);
|
|
87
|
+
}
|
|
88
|
+
if (!event.returnEvent) {
|
|
89
|
+
if ((0, util_1.verbose)()) {
|
|
90
|
+
console.warn(`\tEvent has no returnEvent. Skipping.`);
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!checkInstance.filterEvent(event, appMapIndex)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const buildFinding = (matchEvent, message, groupMessage, occurranceCount,
|
|
98
|
+
// matchEvent will be added to additionalEvents to create the relatedEvents array
|
|
99
|
+
additionalEvents) => {
|
|
100
|
+
const findingEvent = matchEvent || event;
|
|
101
|
+
// Fixes:
|
|
102
|
+
// TypeError: Cannot read property 'forEach' of undefined
|
|
103
|
+
// at hashHttp (/Users/kgilpin/source/appland/scanner/node_modules/@appland/models/dist/index.cjs:1663:11)
|
|
104
|
+
// at hashEvent (/Users/kgilpin/source/appland/scanner/node_modules/@appland/models/dist/index.cjs:1714:14)
|
|
105
|
+
// at Event.get hash [as hash] (/Users/kgilpin/source/appland/scanner/node_modules/@appland/models/dist/index.cjs:3325:27)
|
|
106
|
+
findingEvent.message || (findingEvent.message = []);
|
|
107
|
+
const stack = [
|
|
108
|
+
findingEvent.codeObject.location,
|
|
109
|
+
...findingEvent.ancestors().map((ancestor) => ancestor.codeObject.location),
|
|
110
|
+
].filter(Boolean);
|
|
111
|
+
const hash = (0, crypto_1.createHash)('sha256');
|
|
112
|
+
hash.update(findingEvent.hash);
|
|
113
|
+
hash.update(checkInstance.ruleId);
|
|
114
|
+
const uniqueEvents = new Set();
|
|
115
|
+
const relatedEvents = [];
|
|
116
|
+
[findingEvent].concat((additionalEvents || []).map(eventUtil_1.cloneEvent)).forEach((event) => {
|
|
117
|
+
if (uniqueEvents.has(event.id)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
uniqueEvents.add(event.id);
|
|
121
|
+
relatedEvents.push(event);
|
|
122
|
+
});
|
|
123
|
+
// Update event hash with unique hashes of related events
|
|
124
|
+
new Set(relatedEvents.map((e) => e.hash)).forEach((eventHash) => {
|
|
125
|
+
hash.update(eventHash);
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
appMapFile,
|
|
129
|
+
checkId: checkInstance.checkId,
|
|
130
|
+
ruleId: checkInstance.ruleId,
|
|
131
|
+
ruleTitle: checkInstance.title,
|
|
132
|
+
event: (0, eventUtil_1.cloneEvent)(findingEvent),
|
|
133
|
+
hash: hash.digest('hex'),
|
|
134
|
+
stack,
|
|
135
|
+
scope: (0, eventUtil_1.cloneEvent)(scope),
|
|
136
|
+
message: message || checkInstance.title,
|
|
137
|
+
groupMessage,
|
|
138
|
+
occurranceCount,
|
|
139
|
+
relatedEvents: relatedEvents.sort((event) => event.id),
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
const matchResult = yield checkInstance.ruleLogic.matcher(event, appMapIndex, checkInstance.filterEvent.bind(checkInstance));
|
|
143
|
+
const numFindings = findings.length;
|
|
144
|
+
if (matchResult === true) {
|
|
145
|
+
let finding;
|
|
146
|
+
if (checkInstance.ruleLogic.message) {
|
|
147
|
+
const message = checkInstance.ruleLogic.message(scope, event);
|
|
148
|
+
finding = buildFinding(event, message);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
finding = buildFinding(event);
|
|
152
|
+
}
|
|
153
|
+
findings.push(finding);
|
|
154
|
+
}
|
|
155
|
+
else if (typeof matchResult === 'string') {
|
|
156
|
+
const finding = buildFinding(event, matchResult);
|
|
157
|
+
finding.message = matchResult;
|
|
158
|
+
findings.push(finding);
|
|
159
|
+
}
|
|
160
|
+
else if (matchResult) {
|
|
161
|
+
matchResult.forEach((mr) => {
|
|
162
|
+
const finding = buildFinding(mr.event, mr.message, mr.groupMessage, mr.occurranceCount, mr.relatedEvents);
|
|
163
|
+
findings.push(finding);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if ((0, util_1.verbose)()) {
|
|
167
|
+
if (findings.length > numFindings) {
|
|
168
|
+
findings.forEach((finding) => console.log(`\tFinding: ${finding.ruleId} : ${finding.message}`));
|
|
318
169
|
}
|
|
319
|
-
}
|
|
170
|
+
}
|
|
320
171
|
});
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
}());
|
|
172
|
+
}
|
|
173
|
+
}
|
|
324
174
|
exports.default = RuleChecker;
|
|
325
|
-
//# sourceMappingURL=ruleChecker.js.map
|
|
@@ -1,79 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
const models_1 = require("@appland/models");
|
|
7
|
+
const util_1 = require("./lib/util");
|
|
8
|
+
const url_1 = require("url");
|
|
9
|
+
const parseRuleDescription_1 = __importDefault(require("./lib/parseRuleDescription"));
|
|
21
10
|
function containsAuthentication(events) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var iter = events_1_1.value;
|
|
26
|
-
if ((0, util_1.providesAuthentication)(iter.event, SecurityAuthentication)) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
|
|
11
|
+
for (const iter of events) {
|
|
12
|
+
if ((0, util_1.providesAuthentication)(iter.event, SecurityAuthentication)) {
|
|
13
|
+
return true;
|
|
35
14
|
}
|
|
36
|
-
finally { if (e_1) throw e_1.error; }
|
|
37
15
|
}
|
|
38
16
|
return false;
|
|
39
17
|
}
|
|
40
18
|
function build() {
|
|
41
19
|
function matcher(rootEvent) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
20
|
+
for (const event of new models_1.EventNavigator(rootEvent).descendants()) {
|
|
21
|
+
if ((0, util_1.providesAuthentication)(event.event, SecurityAuthentication)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (event.event.labels.has(SecurityAuthorization) && (0, util_1.isTruthy)(event.event.returnValue)) {
|
|
25
|
+
// If the authorization event has a successful authentication descendant, allow this as well.
|
|
26
|
+
if (containsAuthentication(event.descendants())) {
|
|
47
27
|
return;
|
|
48
28
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
event: event.event,
|
|
58
|
-
message: "".concat(event.event, " provides authorization, but the request is not authenticated"),
|
|
59
|
-
},
|
|
60
|
-
];
|
|
61
|
-
}
|
|
29
|
+
else {
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
event: event.event,
|
|
33
|
+
message: `${event.event} provides authorization, but the request is not authenticated`,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
62
36
|
}
|
|
63
37
|
}
|
|
64
38
|
}
|
|
65
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
66
|
-
finally {
|
|
67
|
-
try {
|
|
68
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
69
|
-
}
|
|
70
|
-
finally { if (e_2) throw e_2.error; }
|
|
71
|
-
}
|
|
72
39
|
}
|
|
73
|
-
return { matcher
|
|
40
|
+
return { matcher };
|
|
74
41
|
}
|
|
75
|
-
|
|
76
|
-
|
|
42
|
+
const SecurityAuthentication = 'security.authentication';
|
|
43
|
+
const SecurityAuthorization = 'security.authorization';
|
|
77
44
|
exports.default = {
|
|
78
45
|
id: 'authz-before-authn',
|
|
79
46
|
title: 'Authorization performed before authentication',
|
|
@@ -86,6 +53,5 @@ exports.default = {
|
|
|
86
53
|
},
|
|
87
54
|
description: (0, parseRuleDescription_1.default)('authzBeforeAuthn'),
|
|
88
55
|
url: 'https://appland.com/docs/analysis/rules-reference.html#authz-before-authn',
|
|
89
|
-
build
|
|
56
|
+
build,
|
|
90
57
|
};
|
|
91
|
-
//# sourceMappingURL=authzBeforeAuthn.js.map
|