@appland/scanner 1.56.0 → 1.59.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 +29 -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 +19 -21
- package/built/check.js +17 -21
- 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 +53 -85
- 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 +20 -0
- package/built/cli/upload.js +93 -172
- package/built/cli/validateFile.js +13 -52
- package/built/cli.js +34 -21
- package/built/configuration/configurationProvider.js +151 -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 +35 -128
- package/built/database/visit.js +20 -68
- 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 +50 -72
- 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 +34 -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
|
@@ -1,65 +1,41 @@
|
|
|
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
|
-
|
|
21
|
-
|
|
6
|
+
const database_1 = require("../database");
|
|
7
|
+
const url_1 = require("url");
|
|
8
|
+
const parseRuleDescription_1 = __importDefault(require("./lib/parseRuleDescription"));
|
|
9
|
+
class Options {
|
|
10
|
+
constructor() {
|
|
22
11
|
this.warningLimit = 5;
|
|
23
12
|
}
|
|
24
|
-
|
|
25
|
-
}());
|
|
13
|
+
}
|
|
26
14
|
// TODO: clean up (https://github.com/applandinc/scanner/issues/43)
|
|
27
|
-
function build(options) {
|
|
28
|
-
|
|
29
|
-
var joinCount = {};
|
|
15
|
+
function build(options = new Options()) {
|
|
16
|
+
const joinCount = {};
|
|
30
17
|
function matcher(command, appMapIndex, eventFilter) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
events: [sqlEvent.event],
|
|
41
|
-
};
|
|
42
|
-
joinCount[sqlEvent.sql] = occurrence;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
occurrence.count += 1;
|
|
46
|
-
occurrence.events.push(sqlEvent.event);
|
|
47
|
-
}
|
|
18
|
+
for (const sqlEvent of (0, database_1.sqlStrings)(command, appMapIndex, eventFilter)) {
|
|
19
|
+
let occurrence = joinCount[sqlEvent.sql];
|
|
20
|
+
if (!occurrence) {
|
|
21
|
+
occurrence = {
|
|
22
|
+
count: 1,
|
|
23
|
+
joins: (0, database_1.countJoins)(appMapIndex.sqlAST(sqlEvent.event)),
|
|
24
|
+
events: [sqlEvent.event],
|
|
25
|
+
};
|
|
26
|
+
joinCount[sqlEvent.sql] = occurrence;
|
|
48
27
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
28
|
+
else {
|
|
29
|
+
occurrence.count += 1;
|
|
30
|
+
occurrence.events.push(sqlEvent.event);
|
|
54
31
|
}
|
|
55
|
-
finally { if (e_1) throw e_1.error; }
|
|
56
32
|
}
|
|
57
|
-
return Object.keys(joinCount).reduce(
|
|
58
|
-
|
|
33
|
+
return Object.keys(joinCount).reduce((matchResults, sql) => {
|
|
34
|
+
const occurrence = joinCount[sql];
|
|
59
35
|
if (occurrence.joins >= options.warningLimit) {
|
|
60
36
|
matchResults.push({
|
|
61
37
|
event: occurrence.events[0],
|
|
62
|
-
message:
|
|
38
|
+
message: `${occurrence.joins} join${occurrence.joins > 1 ? 's' : ''} in SQL "${sql}"`,
|
|
63
39
|
relatedEvents: occurrence.events,
|
|
64
40
|
});
|
|
65
41
|
}
|
|
@@ -67,7 +43,7 @@ function build(options) {
|
|
|
67
43
|
}, []);
|
|
68
44
|
}
|
|
69
45
|
return {
|
|
70
|
-
matcher
|
|
46
|
+
matcher,
|
|
71
47
|
};
|
|
72
48
|
}
|
|
73
49
|
exports.default = {
|
|
@@ -80,7 +56,6 @@ exports.default = {
|
|
|
80
56
|
},
|
|
81
57
|
description: (0, parseRuleDescription_1.default)('tooManyJoins'),
|
|
82
58
|
url: 'https://appland.com/docs/analysis/rules-reference.html#too-many-joins',
|
|
83
|
-
Options
|
|
84
|
-
build
|
|
59
|
+
Options,
|
|
60
|
+
build,
|
|
85
61
|
};
|
|
86
|
-
//# sourceMappingURL=tooManyJoins.js.map
|
|
@@ -1,67 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (_) try {
|
|
9
|
-
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;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var __values = (this && this.__values) || function(o) {
|
|
30
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
31
|
-
if (m) return m.call(o);
|
|
32
|
-
if (o && typeof o.length === "number") return {
|
|
33
|
-
next: function () {
|
|
34
|
-
if (o && i >= o.length) o = void 0;
|
|
35
|
-
return { value: o && o[i++], done: !o };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
39
|
-
};
|
|
40
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
4
|
};
|
|
43
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
6
|
+
const models_1 = require("@appland/models");
|
|
7
|
+
const url_1 = require("url");
|
|
8
|
+
const parseRuleDescription_1 = __importDefault(require("./lib/parseRuleDescription"));
|
|
47
9
|
// TODO: Use the Query AST for this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
10
|
+
const QueryIncludes = [/\bINSERT\b/i, /\bUPDATE\b/i];
|
|
11
|
+
const UpdateMethods = ['put', 'post', 'patch'];
|
|
12
|
+
class Options {
|
|
13
|
+
constructor() {
|
|
52
14
|
this.warningLimit = 20;
|
|
53
15
|
}
|
|
54
|
-
|
|
55
|
-
}());
|
|
16
|
+
}
|
|
56
17
|
function build(options) {
|
|
57
|
-
|
|
58
|
-
|
|
18
|
+
const isUpdate = (event) => {
|
|
19
|
+
const isSQLUpdate = () => {
|
|
59
20
|
if (!event.sqlQuery) {
|
|
60
21
|
return false;
|
|
61
22
|
}
|
|
62
|
-
return QueryIncludes.some(
|
|
23
|
+
return QueryIncludes.some((pattern) => pattern.test(event.sqlQuery));
|
|
63
24
|
};
|
|
64
|
-
|
|
25
|
+
const isRPCUpdate = () => {
|
|
65
26
|
if (!event.httpClientRequest) {
|
|
66
27
|
return false;
|
|
67
28
|
}
|
|
@@ -69,63 +30,23 @@ function build(options) {
|
|
|
69
30
|
};
|
|
70
31
|
return isSQLUpdate() || isRPCUpdate();
|
|
71
32
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
switch (_d.label) {
|
|
77
|
-
case 0:
|
|
78
|
-
_d.trys.push([0, 5, 6, 7]);
|
|
79
|
-
_a = __values(new models_1.EventNavigator(event).descendants()), _b = _a.next();
|
|
80
|
-
_d.label = 1;
|
|
81
|
-
case 1:
|
|
82
|
-
if (!!_b.done) return [3 /*break*/, 4];
|
|
83
|
-
e = _b.value;
|
|
84
|
-
if (!isUpdate(e.event)) {
|
|
85
|
-
return [3 /*break*/, 3];
|
|
86
|
-
}
|
|
87
|
-
return [4 /*yield*/, e.event];
|
|
88
|
-
case 2:
|
|
89
|
-
_d.sent();
|
|
90
|
-
_d.label = 3;
|
|
91
|
-
case 3:
|
|
92
|
-
_b = _a.next();
|
|
93
|
-
return [3 /*break*/, 1];
|
|
94
|
-
case 4: return [3 /*break*/, 7];
|
|
95
|
-
case 5:
|
|
96
|
-
e_1_1 = _d.sent();
|
|
97
|
-
e_1 = { error: e_1_1 };
|
|
98
|
-
return [3 /*break*/, 7];
|
|
99
|
-
case 6:
|
|
100
|
-
try {
|
|
101
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
102
|
-
}
|
|
103
|
-
finally { if (e_1) throw e_1.error; }
|
|
104
|
-
return [7 /*endfinally*/];
|
|
105
|
-
case 7: return [2 /*return*/];
|
|
33
|
+
const updateEvents = function* (event) {
|
|
34
|
+
for (const e of new models_1.EventNavigator(event).descendants()) {
|
|
35
|
+
if (!isUpdate(e.event)) {
|
|
36
|
+
continue;
|
|
106
37
|
}
|
|
107
|
-
|
|
38
|
+
yield e.event;
|
|
39
|
+
}
|
|
108
40
|
};
|
|
109
41
|
function matcher(command) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
for (var _b = __values(updateEvents(command)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
114
|
-
var updateEvent = _c.value;
|
|
115
|
-
events.push(updateEvent);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
119
|
-
finally {
|
|
120
|
-
try {
|
|
121
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
122
|
-
}
|
|
123
|
-
finally { if (e_2) throw e_2.error; }
|
|
42
|
+
const events = [];
|
|
43
|
+
for (const updateEvent of updateEvents(command)) {
|
|
44
|
+
events.push(updateEvent);
|
|
124
45
|
}
|
|
125
46
|
if (events.length > options.warningLimit) {
|
|
126
47
|
return [
|
|
127
48
|
{
|
|
128
|
-
message:
|
|
49
|
+
message: `Command performs ${events.length} SQL and RPC updates`,
|
|
129
50
|
event: events[0],
|
|
130
51
|
relatedEvents: events,
|
|
131
52
|
},
|
|
@@ -133,7 +54,7 @@ function build(options) {
|
|
|
133
54
|
}
|
|
134
55
|
}
|
|
135
56
|
return {
|
|
136
|
-
matcher
|
|
57
|
+
matcher,
|
|
137
58
|
};
|
|
138
59
|
}
|
|
139
60
|
exports.default = {
|
|
@@ -147,7 +68,6 @@ exports.default = {
|
|
|
147
68
|
},
|
|
148
69
|
description: (0, parseRuleDescription_1.default)('tooManyUpdates'),
|
|
149
70
|
url: 'https://appland.com/docs/analysis/rules-reference.html#too-many-updates',
|
|
150
|
-
Options
|
|
151
|
-
build
|
|
71
|
+
Options,
|
|
72
|
+
build,
|
|
152
73
|
};
|
|
153
|
-
//# sourceMappingURL=tooManyUpdates.js.map
|
|
@@ -3,50 +3,47 @@ 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
|
-
|
|
8
|
-
|
|
6
|
+
const visit_1 = require("../database/visit");
|
|
7
|
+
const url_1 = require("url");
|
|
8
|
+
const parseRuleDescription_1 = __importDefault(require("./lib/parseRuleDescription"));
|
|
9
9
|
function isMaterialized(e) {
|
|
10
|
-
return e.ancestors().some(
|
|
11
|
-
var labels = _a.labels;
|
|
12
|
-
return labels.has(DAOMaterialize);
|
|
13
|
-
});
|
|
10
|
+
return e.ancestors().some(({ labels }) => labels.has(DAOMaterialize));
|
|
14
11
|
}
|
|
15
12
|
function isApplicable(e, appMapIndex) {
|
|
16
13
|
try {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const ast = appMapIndex.sqlAST(e);
|
|
15
|
+
let isSelect = false;
|
|
16
|
+
let isCount = false;
|
|
17
|
+
let hasLimitClause = false;
|
|
18
|
+
let isMetadataQuery = false;
|
|
22
19
|
if (ast) {
|
|
23
|
-
|
|
20
|
+
const metadataTableNames = ['sqlite_master'];
|
|
24
21
|
(0, visit_1.visit)(ast, {
|
|
25
|
-
'statement.select':
|
|
26
|
-
|
|
22
|
+
'statement.select': (statement) => {
|
|
23
|
+
isSelect = true;
|
|
27
24
|
if (statement.result &&
|
|
28
25
|
Array.isArray(statement.result) &&
|
|
29
26
|
statement.result.length === 1 &&
|
|
30
27
|
statement.result[0].type === 'function' &&
|
|
31
28
|
statement.result[0].name.name === 'count') {
|
|
32
|
-
|
|
29
|
+
isCount = true;
|
|
33
30
|
}
|
|
34
31
|
},
|
|
35
|
-
'expression.limit':
|
|
36
|
-
|
|
32
|
+
'expression.limit': () => {
|
|
33
|
+
hasLimitClause = true;
|
|
37
34
|
},
|
|
38
|
-
'identifier.table':
|
|
39
|
-
if (
|
|
40
|
-
|
|
35
|
+
'identifier.table': (identifier) => {
|
|
36
|
+
if (metadataTableNames.includes(identifier.name)) {
|
|
37
|
+
isMetadataQuery = true;
|
|
41
38
|
}
|
|
42
39
|
},
|
|
43
40
|
});
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
return
|
|
42
|
+
const isBatched = hasLimitClause || isCount || isMetadataQuery;
|
|
43
|
+
return isSelect && !isBatched && isMaterialized(e);
|
|
47
44
|
}
|
|
48
45
|
catch (_) {
|
|
49
|
-
console.warn(
|
|
46
|
+
console.warn(`Unable to analyze query "${e.sqlQuery}"`);
|
|
50
47
|
return false;
|
|
51
48
|
}
|
|
52
49
|
}
|
|
@@ -55,19 +52,19 @@ function matcher(event, appMapIndex) {
|
|
|
55
52
|
return [
|
|
56
53
|
{
|
|
57
54
|
event: event,
|
|
58
|
-
message:
|
|
55
|
+
message: `Unbatched materialized SQL query: ${event.sqlQuery}`,
|
|
59
56
|
},
|
|
60
57
|
];
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
function build() {
|
|
64
61
|
return {
|
|
65
|
-
matcher
|
|
66
|
-
where:
|
|
62
|
+
matcher,
|
|
63
|
+
where: (e) => !!e.sqlQuery,
|
|
67
64
|
};
|
|
68
65
|
}
|
|
69
66
|
// Example: ActiveRecord::Relation#records
|
|
70
|
-
|
|
67
|
+
const DAOMaterialize = 'dao.materialize';
|
|
71
68
|
exports.default = {
|
|
72
69
|
id: 'unbatched-materialized-query',
|
|
73
70
|
title: 'Unbatched materialized SQL query',
|
|
@@ -79,6 +76,5 @@ exports.default = {
|
|
|
79
76
|
},
|
|
80
77
|
description: (0, parseRuleDescription_1.default)('unbatchedMaterializedQuery'),
|
|
81
78
|
url: 'https://appland.com/docs/analysis/rules-reference.html#unbatched-materialized-query',
|
|
82
|
-
build
|
|
79
|
+
build,
|
|
83
80
|
};
|
|
84
|
-
//# sourceMappingURL=unbatchedMaterializedQuery.js.map
|
|
@@ -3,62 +3,48 @@ 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (queryInclude === void 0) { queryInclude = [/\binsert\b/i, /\bupdate\b/i]; }
|
|
11
|
-
if (queryExclude === void 0) { queryExclude = []; }
|
|
6
|
+
const util_1 = require("./lib/util");
|
|
7
|
+
const parseRuleDescription_1 = __importDefault(require("./lib/parseRuleDescription"));
|
|
8
|
+
class Options {
|
|
9
|
+
constructor(queryInclude = [/\binsert\b/i, /\bupdate\b/i], queryExclude = []) {
|
|
12
10
|
this._queryInclude = queryInclude;
|
|
13
11
|
this._queryExclude = queryExclude;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
set: function (value) {
|
|
30
|
-
this._queryExclude = (0, util_1.toRegExpArray)(value);
|
|
31
|
-
},
|
|
32
|
-
enumerable: false,
|
|
33
|
-
configurable: true
|
|
34
|
-
});
|
|
35
|
-
return Options;
|
|
36
|
-
}());
|
|
37
|
-
function build(options) {
|
|
38
|
-
if (options === void 0) { options = new Options(); }
|
|
13
|
+
get queryInclude() {
|
|
14
|
+
return this._queryInclude;
|
|
15
|
+
}
|
|
16
|
+
set queryInclude(value) {
|
|
17
|
+
this._queryInclude = (0, util_1.toRegExpArray)(value);
|
|
18
|
+
}
|
|
19
|
+
get queryExclude() {
|
|
20
|
+
return this._queryExclude;
|
|
21
|
+
}
|
|
22
|
+
set queryExclude(value) {
|
|
23
|
+
this._queryExclude = (0, util_1.toRegExpArray)(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function build(options = new Options()) {
|
|
39
27
|
return {
|
|
40
|
-
matcher:
|
|
41
|
-
|
|
28
|
+
matcher: (e) => {
|
|
29
|
+
let httpServerRequest;
|
|
42
30
|
function hasHttpServerRequest() {
|
|
43
31
|
httpServerRequest = e
|
|
44
32
|
.ancestors()
|
|
45
|
-
.find(
|
|
46
|
-
|
|
47
|
-
['head', 'get'].includes(ancestor.httpServerRequest.request_method.toLowerCase());
|
|
48
|
-
});
|
|
33
|
+
.find((ancestor) => ancestor.httpServerRequest &&
|
|
34
|
+
['head', 'get'].includes(ancestor.httpServerRequest.request_method.toLowerCase()));
|
|
49
35
|
return httpServerRequest !== undefined;
|
|
50
36
|
}
|
|
51
|
-
if (options.queryInclude.some(
|
|
52
|
-
!options.queryExclude.some(
|
|
53
|
-
!e.ancestors().some(
|
|
37
|
+
if (options.queryInclude.some((pattern) => e.sqlQuery.match(pattern)) &&
|
|
38
|
+
!options.queryExclude.some((pattern) => e.sqlQuery.match(pattern)) &&
|
|
39
|
+
!e.ancestors().some((ancestor) => ancestor.codeObject.labels.has(Audit)) &&
|
|
54
40
|
hasHttpServerRequest()) {
|
|
55
|
-
return
|
|
41
|
+
return `Data update performed in ${httpServerRequest.route}: ${e.sqlQuery}`;
|
|
56
42
|
}
|
|
57
43
|
},
|
|
58
|
-
where:
|
|
44
|
+
where: (e) => !!e.sqlQuery,
|
|
59
45
|
};
|
|
60
46
|
}
|
|
61
|
-
|
|
47
|
+
const Audit = 'audit';
|
|
62
48
|
exports.default = {
|
|
63
49
|
id: 'update-in-get-request',
|
|
64
50
|
title: 'Data update performed in GET or HEAD request',
|
|
@@ -67,7 +53,6 @@ exports.default = {
|
|
|
67
53
|
impactDomain: 'Maintainability',
|
|
68
54
|
description: (0, parseRuleDescription_1.default)('updateInGetRequest'),
|
|
69
55
|
url: 'https://appland.com/docs/analysis/rules-reference.html#update-in-get-request',
|
|
70
|
-
Options
|
|
71
|
-
build
|
|
56
|
+
Options,
|
|
57
|
+
build,
|
|
72
58
|
};
|
|
73
|
-
//# sourceMappingURL=updateInGetRequest.js.map
|