@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.
Files changed (247) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/built/algorithms/dataStructures/graph/Graph.js +53 -62
  3. package/built/algorithms/dataStructures/graph/GraphEdge.js +13 -16
  4. package/built/algorithms/dataStructures/graph/GraphVertex.js +37 -42
  5. package/built/algorithms/dataStructures/linked-list/LinkedList.js +33 -38
  6. package/built/algorithms/dataStructures/linked-list/LinkedListNode.js +6 -10
  7. package/built/algorithms/graph/depth-first-search/index.js +7 -8
  8. package/built/algorithms/graph/detect-cycle/index.js +15 -16
  9. package/built/algorithms/utils/Comparator.js +19 -21
  10. package/built/analyzer/recordSecrets.js +7 -30
  11. package/built/analyzer/secretsRegexes.js +8 -9
  12. package/built/appMapIndex.js +19 -21
  13. package/built/check.js +17 -21
  14. package/built/checkInstance.js +26 -48
  15. package/built/cli/ci/command.js +61 -156
  16. package/built/cli/ci/options.js +0 -1
  17. package/built/cli/codeVersionArgs.js +0 -1
  18. package/built/cli/exitCode.js +0 -1
  19. package/built/cli/fail.js +2 -3
  20. package/built/cli/merge/command.js +21 -63
  21. package/built/cli/merge/options.js +0 -1
  22. package/built/cli/reportUploadURL.js +2 -3
  23. package/built/cli/resolveAppId.js +34 -85
  24. package/built/cli/scan/command.js +52 -94
  25. package/built/cli/scan/formatReport.js +16 -89
  26. package/built/cli/scan/options.js +0 -1
  27. package/built/cli/scan/scanner.js +38 -117
  28. package/built/cli/scan/singleScan.js +61 -109
  29. package/built/cli/scan/watchScan.js +53 -85
  30. package/built/cli/scan.js +39 -132
  31. package/built/cli/scanArgs.js +0 -1
  32. package/built/cli/scanOptions.js +0 -1
  33. package/built/cli/updateCommitStatus.js +10 -47
  34. package/built/cli/upload/command.js +20 -64
  35. package/built/cli/upload/options.js +0 -1
  36. package/built/cli/upload/pruneAppMap.js +20 -0
  37. package/built/cli/upload.js +93 -172
  38. package/built/cli/validateFile.js +13 -52
  39. package/built/cli.js +34 -21
  40. package/built/configuration/configurationProvider.js +151 -233
  41. package/built/configuration/schema/options.json +76 -76
  42. package/built/configuration/types/checkConfig.js +0 -1
  43. package/built/configuration/types/configuration.js +0 -1
  44. package/built/configuration/types/matchEventConfig.js +0 -1
  45. package/built/configuration/types/matchPatternConfig.js +0 -1
  46. package/built/database/index.js +35 -128
  47. package/built/database/visit.js +20 -68
  48. package/built/errors.js +4 -30
  49. package/built/eventUtil.js +10 -35
  50. package/built/findings.js +3 -4
  51. package/built/integration/appland/app/exists.js +33 -76
  52. package/built/integration/appland/app/listFindingStatus.js +3 -36
  53. package/built/integration/appland/appMap/create.js +38 -89
  54. package/built/integration/appland/location.js +0 -1
  55. package/built/integration/appland/mapset/create.js +34 -85
  56. package/built/integration/appland/retry.js +10 -11
  57. package/built/integration/appland/retryOptions.js +0 -1
  58. package/built/integration/appland/scannerJob/create.js +34 -84
  59. package/built/integration/appland/scannerJob/merge.js +28 -74
  60. package/built/integration/appland/scannerJob.js +0 -1
  61. package/built/integration/github/commitStatus.js +3 -4
  62. package/built/integration/vars.js +1 -2
  63. package/built/openapi/index.js +39 -83
  64. package/built/report/appMapMetadata.js +0 -1
  65. package/built/report/findingSummary.js +0 -1
  66. package/built/report/findingsReport.js +14 -16
  67. package/built/report/scanResults.js +50 -72
  68. package/built/report/scanSummary.js +0 -1
  69. package/built/report/summaryReport.js +12 -13
  70. package/built/ruleChecker.js +146 -297
  71. package/built/rules/authzBeforeAuthn.js +25 -59
  72. package/built/rules/circularDependency.js +69 -101
  73. package/built/rules/deserializationOfUntrustedData.js +29 -63
  74. package/built/rules/execOfUntrustedCommand.js +28 -62
  75. package/built/rules/http-500/metadata.js +0 -1
  76. package/built/rules/http-500/rule.js +2 -3
  77. package/built/rules/illegalPackageDependency.js +16 -18
  78. package/built/rules/incompatibleHttpClientRequest.js +30 -69
  79. package/built/rules/insecureCompare.js +12 -13
  80. package/built/rules/jobNotCancelled.js +13 -45
  81. package/built/rules/lib/hasParameterOrReceiver.js +4 -7
  82. package/built/rules/lib/matchEvent.js +12 -13
  83. package/built/rules/lib/matchPattern.js +6 -7
  84. package/built/rules/lib/metadata.js +0 -1
  85. package/built/rules/lib/parseRuleDescription.js +5 -6
  86. package/built/rules/lib/precedingEvents.js +7 -75
  87. package/built/rules/lib/rpcWithoutProtection.js +5 -28
  88. package/built/rules/lib/sanitizesData.js +0 -1
  89. package/built/rules/lib/util.js +34 -73
  90. package/built/rules/logoutWithoutSessionReset.js +24 -58
  91. package/built/rules/missingAuthentication.js +28 -28
  92. package/built/rules/missingContentType.js +8 -9
  93. package/built/rules/nPlusOneQuery.js +35 -87
  94. package/built/rules/queryFromInvalidPackage.js +17 -19
  95. package/built/rules/queryFromView.js +13 -16
  96. package/built/rules/rpcWithoutCircuitBreaker.js +14 -84
  97. package/built/rules/saveWithoutValidation.js +8 -9
  98. package/built/rules/secretInLog.js +29 -92
  99. package/built/rules/slowFunctionCall.js +16 -20
  100. package/built/rules/slowHttpServerRequest.js +9 -11
  101. package/built/rules/slowQuery.js +9 -12
  102. package/built/rules/tooManyJoins.js +26 -51
  103. package/built/rules/tooManyUpdates.js +25 -105
  104. package/built/rules/unbatchedMaterializedQuery.js +26 -30
  105. package/built/rules/updateInGetRequest.js +30 -45
  106. package/built/scope/commandScope.js +24 -144
  107. package/built/scope/httpClientRequestScope.js +11 -98
  108. package/built/scope/httpServerRequestScope.js +11 -98
  109. package/built/scope/rootScope.js +11 -98
  110. package/built/scope/scopeImpl.js +10 -82
  111. package/built/scope/scopeIterator.js +6 -10
  112. package/built/scope/sqlTransactionScope.js +24 -122
  113. package/built/sqlWarning.js +9 -35
  114. package/built/telemetry.js +215 -0
  115. package/built/wellKnownLabels.js +0 -1
  116. package/package.json +7 -3
  117. package/built/algorithms/dataStructures/graph/Graph.js.map +0 -1
  118. package/built/algorithms/dataStructures/graph/GraphEdge.js.map +0 -1
  119. package/built/algorithms/dataStructures/graph/GraphVertex.js.map +0 -1
  120. package/built/algorithms/dataStructures/linked-list/LinkedList.js.map +0 -1
  121. package/built/algorithms/dataStructures/linked-list/LinkedListNode.js.map +0 -1
  122. package/built/algorithms/graph/depth-first-search/index.js.map +0 -1
  123. package/built/algorithms/graph/detect-cycle/index.js.map +0 -1
  124. package/built/algorithms/utils/Comparator.js.map +0 -1
  125. package/built/analyzer/recordSecrets.js.map +0 -1
  126. package/built/analyzer/secretsRegexes.js.map +0 -1
  127. package/built/appMapIndex.js.map +0 -1
  128. package/built/check.js.map +0 -1
  129. package/built/checkInstance.js.map +0 -1
  130. package/built/cli/ci/command.js.map +0 -1
  131. package/built/cli/ci/options.js.map +0 -1
  132. package/built/cli/codeVersionArgs.js.map +0 -1
  133. package/built/cli/exitCode.js.map +0 -1
  134. package/built/cli/fail.js.map +0 -1
  135. package/built/cli/merge/command.js.map +0 -1
  136. package/built/cli/merge/options.js.map +0 -1
  137. package/built/cli/reportUploadURL.js.map +0 -1
  138. package/built/cli/resolveAppId.js.map +0 -1
  139. package/built/cli/scan/command.js.map +0 -1
  140. package/built/cli/scan/formatReport.js.map +0 -1
  141. package/built/cli/scan/options.js.map +0 -1
  142. package/built/cli/scan/scanner.js.map +0 -1
  143. package/built/cli/scan/singleScan.js.map +0 -1
  144. package/built/cli/scan/watchScan.js.map +0 -1
  145. package/built/cli/scan.js.map +0 -1
  146. package/built/cli/scanArgs.js.map +0 -1
  147. package/built/cli/scanOptions.js.map +0 -1
  148. package/built/cli/updateCommitStatus.js.map +0 -1
  149. package/built/cli/upload/command.js.map +0 -1
  150. package/built/cli/upload/options.js.map +0 -1
  151. package/built/cli/upload.js.map +0 -1
  152. package/built/cli/validateFile.js.map +0 -1
  153. package/built/cli.js.map +0 -1
  154. package/built/configuration/configurationProvider.js.map +0 -1
  155. package/built/configuration/types/checkConfig.js.map +0 -1
  156. package/built/configuration/types/configuration.js.map +0 -1
  157. package/built/configuration/types/matchEventConfig.js.map +0 -1
  158. package/built/configuration/types/matchPatternConfig.js.map +0 -1
  159. package/built/database/index.js.map +0 -1
  160. package/built/database/visit.js.map +0 -1
  161. package/built/errors.js.map +0 -1
  162. package/built/eventUtil.js.map +0 -1
  163. package/built/findings.js.map +0 -1
  164. package/built/integration/appland/app/exists.js.map +0 -1
  165. package/built/integration/appland/app/listFindingStatus.js.map +0 -1
  166. package/built/integration/appland/appMap/create.js.map +0 -1
  167. package/built/integration/appland/location.js.map +0 -1
  168. package/built/integration/appland/mapset/create.js.map +0 -1
  169. package/built/integration/appland/retry.js.map +0 -1
  170. package/built/integration/appland/retryOptions.js.map +0 -1
  171. package/built/integration/appland/scannerJob/create.js.map +0 -1
  172. package/built/integration/appland/scannerJob/merge.js.map +0 -1
  173. package/built/integration/appland/scannerJob.js.map +0 -1
  174. package/built/integration/github/commitStatus.js.map +0 -1
  175. package/built/integration/vars.js.map +0 -1
  176. package/built/openapi/index.js.map +0 -1
  177. package/built/openapi/method.js +0 -120
  178. package/built/openapi/method.js.map +0 -1
  179. package/built/openapi/model.js +0 -49
  180. package/built/openapi/model.js.map +0 -1
  181. package/built/openapi/path.js +0 -36
  182. package/built/openapi/path.js.map +0 -1
  183. package/built/openapi/provider.js +0 -133
  184. package/built/openapi/provider.js.map +0 -1
  185. package/built/openapi/response.js +0 -59
  186. package/built/openapi/response.js.map +0 -1
  187. package/built/openapi/rpcRequest.js +0 -130
  188. package/built/openapi/rpcRequest.js.map +0 -1
  189. package/built/openapi/schema.js +0 -42
  190. package/built/openapi/schema.js.map +0 -1
  191. package/built/openapi/securitySchemes.js +0 -32
  192. package/built/openapi/securitySchemes.js.map +0 -1
  193. package/built/openapi/statusCodes.js +0 -68
  194. package/built/openapi/statusCodes.js.map +0 -1
  195. package/built/openapi/util.js +0 -91
  196. package/built/openapi/util.js.map +0 -1
  197. package/built/report/appMapMetadata.js.map +0 -1
  198. package/built/report/findingSummary.js.map +0 -1
  199. package/built/report/findingsReport.js.map +0 -1
  200. package/built/report/scanResults.js.map +0 -1
  201. package/built/report/scanSummary.js.map +0 -1
  202. package/built/report/summaryReport.js.map +0 -1
  203. package/built/ruleChecker.js.map +0 -1
  204. package/built/rules/authzBeforeAuthn.js.map +0 -1
  205. package/built/rules/circularDependency.js.map +0 -1
  206. package/built/rules/deserializationOfUntrustedData.js.map +0 -1
  207. package/built/rules/execOfUntrustedCommand.js.map +0 -1
  208. package/built/rules/http-500/metadata.js.map +0 -1
  209. package/built/rules/http-500/rule.js.map +0 -1
  210. package/built/rules/illegalPackageDependency.js.map +0 -1
  211. package/built/rules/incompatibleHttpClientRequest.js.map +0 -1
  212. package/built/rules/insecureCompare.js.map +0 -1
  213. package/built/rules/jobNotCancelled.js.map +0 -1
  214. package/built/rules/lib/hasParameterOrReceiver.js.map +0 -1
  215. package/built/rules/lib/matchEvent.js.map +0 -1
  216. package/built/rules/lib/matchPattern.js.map +0 -1
  217. package/built/rules/lib/metadata.js.map +0 -1
  218. package/built/rules/lib/parseRuleDescription.js.map +0 -1
  219. package/built/rules/lib/precedingEvents.js.map +0 -1
  220. package/built/rules/lib/rpcWithoutProtection.js.map +0 -1
  221. package/built/rules/lib/sanitizesData.js.map +0 -1
  222. package/built/rules/lib/util.js.map +0 -1
  223. package/built/rules/logoutWithoutSessionReset.js.map +0 -1
  224. package/built/rules/missingAuthentication.js.map +0 -1
  225. package/built/rules/missingContentType.js.map +0 -1
  226. package/built/rules/nPlusOneQuery.js.map +0 -1
  227. package/built/rules/queryFromInvalidPackage.js.map +0 -1
  228. package/built/rules/queryFromView.js.map +0 -1
  229. package/built/rules/rpcWithoutCircuitBreaker.js.map +0 -1
  230. package/built/rules/saveWithoutValidation.js.map +0 -1
  231. package/built/rules/secretInLog.js.map +0 -1
  232. package/built/rules/slowFunctionCall.js.map +0 -1
  233. package/built/rules/slowHttpServerRequest.js.map +0 -1
  234. package/built/rules/slowQuery.js.map +0 -1
  235. package/built/rules/tooManyJoins.js.map +0 -1
  236. package/built/rules/tooManyUpdates.js.map +0 -1
  237. package/built/rules/unbatchedMaterializedQuery.js.map +0 -1
  238. package/built/rules/updateInGetRequest.js.map +0 -1
  239. package/built/scope/commandScope.js.map +0 -1
  240. package/built/scope/httpClientRequestScope.js.map +0 -1
  241. package/built/scope/httpServerRequestScope.js.map +0 -1
  242. package/built/scope/rootScope.js.map +0 -1
  243. package/built/scope/scopeImpl.js.map +0 -1
  244. package/built/scope/scopeIterator.js.map +0 -1
  245. package/built/scope/sqlTransactionScope.js.map +0 -1
  246. package/built/sqlWarning.js.map +0 -1
  247. package/built/wellKnownLabels.js.map +0 -1
@@ -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
- var errors_1 = require("./errors");
79
- var util_1 = require("./rules/lib/util");
80
- var rootScope_1 = __importDefault(require("./scope/rootScope"));
81
- var httpServerRequestScope_1 = __importDefault(require("./scope/httpServerRequestScope"));
82
- var httpClientRequestScope_1 = __importDefault(require("./scope/httpClientRequestScope"));
83
- var commandScope_1 = __importDefault(require("./scope/commandScope"));
84
- var sqlTransactionScope_1 = __importDefault(require("./scope/sqlTransactionScope"));
85
- var checkInstance_1 = __importDefault(require("./checkInstance"));
86
- var crypto_1 = require("crypto");
87
- var eventUtil_1 = require("./eventUtil");
88
- var RuleChecker = /** @class */ (function () {
89
- function RuleChecker() {
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
- RuleChecker.prototype.check = function (appMapFile, appMapIndex, check, findings) {
99
- return __awaiter(this, void 0, void 0, function () {
100
- var numScopesChecked;
101
- return __generator(this, function (_a) {
102
- switch (_a.label) {
103
- case 0: return [4 /*yield*/, this.checkScope(appMapFile, appMapIndex, check, check.scope, findings)];
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
- RuleChecker.prototype.checkScope = function (appMapFile, appMapIndex, check, scope, findings) {
117
- return __awaiter(this, void 0, void 0, function () {
118
- var scopeIterator, callEvents, numScopes, _a, _b, scope_1, checkInstance, _c, _d, event, e_1_1, e_2_1;
119
- var e_2, _e, e_1, _f;
120
- return __generator(this, function (_g) {
121
- switch (_g.label) {
122
- case 0:
123
- if ((0, util_1.verbose)()) {
124
- console.warn("Checking AppMap ".concat(appMapIndex.appMap.name, " with scope ").concat(scope));
125
- }
126
- scopeIterator = this.scopes[scope];
127
- if (!scopeIterator) {
128
- throw new errors_1.AbortError("Invalid scope name \"".concat(scope, "\""));
129
- }
130
- callEvents = function () {
131
- var events, i;
132
- return __generator(this, function (_a) {
133
- switch (_a.label) {
134
- case 0:
135
- events = appMapIndex.appMap.events;
136
- i = 0;
137
- _a.label = 1;
138
- case 1:
139
- if (!(i < events.length)) return [3 /*break*/, 4];
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
- RuleChecker.prototype.checkEvent = function (event, scope, appMapFile, appMapIndex, checkInstance, findings) {
220
- return __awaiter(this, void 0, void 0, function () {
221
- var buildFinding, matchResult, numFindings, finding, message, finding;
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0:
225
- if (!event.isCall()) {
226
- return [2 /*return*/];
227
- }
228
- if ((0, util_1.verbose)()) {
229
- console.warn("Asserting ".concat(checkInstance.ruleId, " on ").concat(event.codeObject.fqid, " event ").concat(event.toString()));
230
- }
231
- if (!event.returnEvent) {
232
- if ((0, util_1.verbose)()) {
233
- console.warn("\tEvent has no returnEvent. Skipping.");
234
- }
235
- return [2 /*return*/];
236
- }
237
- if (!checkInstance.filterEvent(event, appMapIndex)) {
238
- return [2 /*return*/];
239
- }
240
- buildFinding = function (matchEvent, message, groupMessage, occurranceCount,
241
- // matchEvent will be added to additionalEvents to create the relatedEvents array
242
- additionalEvents) {
243
- var findingEvent = matchEvent || event;
244
- // Fixes:
245
- // TypeError: Cannot read property 'forEach' of undefined
246
- // at hashHttp (/Users/kgilpin/source/appland/scanner/node_modules/@appland/models/dist/index.cjs:1663:11)
247
- // at hashEvent (/Users/kgilpin/source/appland/scanner/node_modules/@appland/models/dist/index.cjs:1714:14)
248
- // at Event.get hash [as hash] (/Users/kgilpin/source/appland/scanner/node_modules/@appland/models/dist/index.cjs:3325:27)
249
- findingEvent.message || (findingEvent.message = []);
250
- var stack = __spreadArray([
251
- findingEvent.codeObject.location
252
- ], __read(findingEvent.ancestors().map(function (ancestor) { return ancestor.codeObject.location; })), false).filter(Boolean);
253
- var hash = (0, crypto_1.createHash)('sha256');
254
- hash.update(findingEvent.hash);
255
- hash.update(checkInstance.ruleId);
256
- var uniqueEvents = new Set();
257
- var relatedEvents = [];
258
- [findingEvent].concat((additionalEvents || []).map(eventUtil_1.cloneEvent)).forEach(function (event) {
259
- if (uniqueEvents.has(event.id)) {
260
- return;
261
- }
262
- uniqueEvents.add(event.id);
263
- relatedEvents.push(event);
264
- });
265
- // Update event hash with unique hashes of related events
266
- new Set(relatedEvents.map(function (e) { return e.hash; })).forEach(function (eventHash) {
267
- hash.update(eventHash);
268
- });
269
- return {
270
- appMapFile: appMapFile,
271
- checkId: checkInstance.checkId,
272
- ruleId: checkInstance.ruleId,
273
- ruleTitle: checkInstance.title,
274
- event: (0, eventUtil_1.cloneEvent)(findingEvent),
275
- hash: hash.digest('hex'),
276
- stack: stack,
277
- scope: (0, eventUtil_1.cloneEvent)(scope),
278
- message: message || checkInstance.title,
279
- groupMessage: groupMessage,
280
- occurranceCount: occurranceCount,
281
- relatedEvents: relatedEvents.sort(function (event) { return event.id; }),
282
- };
283
- };
284
- return [4 /*yield*/, checkInstance.ruleLogic.matcher(event, appMapIndex, checkInstance.filterEvent.bind(checkInstance))];
285
- case 1:
286
- matchResult = _a.sent();
287
- numFindings = findings.length;
288
- if (matchResult === true) {
289
- finding = void 0;
290
- if (checkInstance.ruleLogic.message) {
291
- message = checkInstance.ruleLogic.message(scope, event);
292
- finding = buildFinding(event, message);
293
- }
294
- else {
295
- finding = buildFinding(event);
296
- }
297
- findings.push(finding);
298
- }
299
- else if (typeof matchResult === 'string') {
300
- finding = buildFinding(event, matchResult);
301
- finding.message = matchResult;
302
- findings.push(finding);
303
- }
304
- else if (matchResult) {
305
- matchResult.forEach(function (mr) {
306
- var finding = buildFinding(mr.event, mr.message, mr.groupMessage, mr.occurranceCount, mr.relatedEvents);
307
- findings.push(finding);
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
- return RuleChecker;
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
- var models_1 = require("@appland/models");
18
- var util_1 = require("./lib/util");
19
- var url_1 = require("url");
20
- var parseRuleDescription_1 = __importDefault(require("./lib/parseRuleDescription"));
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
- var e_1, _a;
23
- try {
24
- for (var events_1 = __values(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
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
- var e_2, _a;
43
- try {
44
- for (var _b = __values(new models_1.EventNavigator(rootEvent).descendants()), _c = _b.next(); !_c.done; _c = _b.next()) {
45
- var event = _c.value;
46
- if ((0, util_1.providesAuthentication)(event.event, SecurityAuthentication)) {
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
- if (event.event.labels.has(SecurityAuthorization) && (0, util_1.isTruthy)(event.event.returnValue)) {
50
- // If the authorization event has a successful authentication descendant, allow this as well.
51
- if (containsAuthentication(event.descendants())) {
52
- return;
53
- }
54
- else {
55
- return [
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: matcher };
40
+ return { matcher };
74
41
  }
75
- var SecurityAuthentication = 'security.authentication';
76
- var SecurityAuthorization = 'security.authorization';
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: build,
56
+ build,
90
57
  };
91
- //# sourceMappingURL=authzBeforeAuthn.js.map