@appland/scanner 1.64.0 → 1.67.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 CHANGED
@@ -1,3 +1,41 @@
1
+ # [@appland/scanner-v1.67.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.66.0...@appland/scanner-v1.67.0) (2022-08-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Fix Options loading from dir-based rules ([f58ce49](https://github.com/applandinc/appmap-js/commit/f58ce49f22ba4d649e8886d76373cf23d6614b37))
7
+
8
+
9
+ ### Features
10
+
11
+ * Ignore schema info tables in too-many-joins ([0cb387d](https://github.com/applandinc/appmap-js/commit/0cb387d74aa7e6edda5e24a88d07fa65b3900966))
12
+
13
+ # [@appland/scanner-v1.66.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.65.0...@appland/scanner-v1.66.0) (2022-08-08)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * Fix rule doc ([b99b6ae](https://github.com/applandinc/appmap-js/commit/b99b6aec90186bef312d04fb4f4c95f9b1ee62d5))
19
+
20
+
21
+ ### Features
22
+
23
+ * Add deprecated-crypto-algorithm to default rule set ([3034489](https://github.com/applandinc/appmap-js/commit/303448974a73637493a72bea7ab8cfb28ccc8b10))
24
+ * Detect deprecated crypto algorithm ([a17a537](https://github.com/applandinc/appmap-js/commit/a17a537334771a9f2cd64fa73c2396e517ff82ea))
25
+
26
+ # [@appland/scanner-v1.65.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.64.0...@appland/scanner-v1.65.0) (2022-08-08)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * Remove an inadvenant console log ([5c11fc7](https://github.com/applandinc/appmap-js/commit/5c11fc77650e105f169ca0bcc4045312578e8881))
32
+
33
+
34
+ ### Features
35
+
36
+ * Add unauthenticated-encryption to default rule set ([2e3cf92](https://github.com/applandinc/appmap-js/commit/2e3cf9298b3cfe99b489ab8b2894e913a305fdd0))
37
+ * Check for unauthenticated encryption ([d393951](https://github.com/applandinc/appmap-js/commit/d393951c73c4492f1e95b52a2580fde10b256ee4))
38
+
1
39
  # [@appland/scanner-v1.64.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.63.0...@appland/scanner-v1.64.0) (2022-08-04)
2
40
 
3
41
 
@@ -83,7 +83,7 @@ function loadFromDir(ruleName) {
83
83
  if ((0, util_1.verbose)())
84
84
  console.log(`Loaded rule ${ruleName}: ${rule}`);
85
85
  try {
86
- options = yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}/options`)));
86
+ options = (yield Promise.resolve().then(() => __importStar(require(`../rules/${ruleName}/options`)))).default;
87
87
  if ((0, util_1.verbose)())
88
88
  console.log(`Loaded rule ${ruleName} options: ${options}`);
89
89
  }
@@ -126,14 +126,27 @@ function* sqlStrings(event, appMapIndex, filter = () => true) {
126
126
  }
127
127
  }
128
128
  exports.sqlStrings = sqlStrings;
129
- function countJoins(ast) {
129
+ function countJoins(ast, filterTable) {
130
130
  if (!ast)
131
131
  return 0;
132
132
  let joins = 0;
133
133
  (0, visit_1.visit)(ast, {
134
134
  'map.join': (node) => {
135
135
  var _a;
136
- joins += ((_a = node.map) !== null && _a !== void 0 ? _a : []).length;
136
+ const map = (_a = node.map) !== null && _a !== void 0 ? _a : [];
137
+ const tableCount = filterTable
138
+ ? map.filter((entry) => {
139
+ const source = entry === null || entry === void 0 ? void 0 : entry.source;
140
+ if (!source)
141
+ return true;
142
+ if (source.type !== 'identifier')
143
+ return true;
144
+ if (source.variant !== 'table')
145
+ return true;
146
+ return filterTable(source);
147
+ }).length
148
+ : map.length;
149
+ joins += tableCount;
137
150
  },
138
151
  });
139
152
  return joins;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.labels = void 0;
4
+ exports.labels = ['crypto.encrypt', 'crypto.decrypt', 'crypto.digest'];
5
+ exports.default = {
6
+ title: 'Deprecated cryptographic algorithm',
7
+ scope: 'root',
8
+ enumerateScope: true,
9
+ impactDomain: 'Security',
10
+ references: {
11
+ 'A02:2021': 'https://owasp.org/Top10/A02_2021-Cryptographic_Failures/',
12
+ },
13
+ labels: exports.labels,
14
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deprecatedAlgorithms = void 0;
4
+ const metadata_1 = require("./metadata");
5
+ exports.deprecatedAlgorithms = [
6
+ /\bcbc\b/i,
7
+ /\becb\b/i,
8
+ /\b3?des\b/i,
9
+ /\brc\d\b/i,
10
+ /\bmd\d\b/i,
11
+ /\bsha-?1\b/i,
12
+ ];
13
+ // Also:
14
+ // https://securitymusings.com/article/1587/algorithm-and-key-length-deprecation
15
+ // http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html
16
+ // Password handling: As soon as you receive a password, hash it using scrypt or PBKDF2 and erase the plaintext password from memory.
17
+ // 1024-bit RSA or DSA
18
+ // 160-bit ECDSA (elliptic curves)
19
+ // 80/112-bit 2TDEA (two key triple DES)
20
+ // PKCS #1 v1.5
21
+ function matcher(event) {
22
+ if (!event.receiver)
23
+ return;
24
+ const receiverLabels = event.receiver.labels || [];
25
+ const deprecatedAlgorithm = receiverLabels
26
+ .filter((label) => label.startsWith('crypto.algorithm.'))
27
+ .map((label) => label.split('.').slice(2).join('.'))
28
+ .find((label) => exports.deprecatedAlgorithms.find((alg) => alg.test(label)));
29
+ if (deprecatedAlgorithm) {
30
+ return [
31
+ {
32
+ event,
33
+ message: `Deprecated crypto algorithm: ${deprecatedAlgorithm}`,
34
+ },
35
+ ];
36
+ }
37
+ }
38
+ function rule() {
39
+ return {
40
+ matcher,
41
+ where: (e) => !!metadata_1.labels.find((label) => e.labels.has(label)),
42
+ };
43
+ }
44
+ exports.default = rule;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ title: 'Too many joins',
5
+ enumerateScope: false,
6
+ impactDomain: 'Performance',
7
+ references: {
8
+ 'CWE-1049': 'https://cwe.mitre.org/data/definitions/1049.html',
9
+ },
10
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Options {
4
+ constructor() {
5
+ this.warningLimit = 5;
6
+ this.excludeTables = [
7
+ { match: /^pg_/, ignoreCase: false },
8
+ { match: /^information_schema$/, ignoreCase: true },
9
+ ];
10
+ }
11
+ }
12
+ exports.default = Options;
@@ -3,24 +3,26 @@ 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
- const database_1 = require("../database");
7
- const url_1 = require("url");
8
- const parseRuleDescription_1 = __importDefault(require("./lib/parseRuleDescription"));
9
- class Options {
10
- constructor() {
11
- this.warningLimit = 5;
6
+ const assert_1 = __importDefault(require("assert"));
7
+ const database_1 = require("../../database");
8
+ const matchPattern_1 = require("../lib/matchPattern");
9
+ function rule(options) {
10
+ const excludeTables = (0, matchPattern_1.buildFilters)(options.excludeTables);
11
+ function filterTable(table) {
12
+ (0, assert_1.default)(table.type === 'identifier');
13
+ (0, assert_1.default)(table.variant === 'table');
14
+ return !excludeTables.find((filter) => filter(table.name));
12
15
  }
13
- }
14
- // TODO: clean up (https://github.com/applandinc/scanner/issues/43)
15
- function build(options = new Options()) {
16
- const joinCount = {};
16
+ // TODO: clean up (https://github.com/applandinc/scanner/issues/43)
17
17
  function matcher(command, appMapIndex, eventFilter) {
18
+ const joinCount = {};
18
19
  for (const sqlEvent of (0, database_1.sqlStrings)(command, appMapIndex, eventFilter)) {
19
20
  let occurrence = joinCount[sqlEvent.sql];
20
21
  if (!occurrence) {
22
+ const sqlAST = appMapIndex.sqlAST(sqlEvent.event);
21
23
  occurrence = {
22
24
  count: 1,
23
- joins: (0, database_1.countJoins)(appMapIndex.sqlAST(sqlEvent.event)),
25
+ joins: (0, database_1.countJoins)(sqlAST, filterTable),
24
26
  events: [sqlEvent.event],
25
27
  };
26
28
  joinCount[sqlEvent.sql] = occurrence;
@@ -46,16 +48,4 @@ function build(options = new Options()) {
46
48
  matcher,
47
49
  };
48
50
  }
49
- exports.default = {
50
- id: 'too-many-joins',
51
- title: 'Too many joins',
52
- impactDomain: 'Performance',
53
- enumerateScope: false,
54
- references: {
55
- 'CWE-1049': new url_1.URL('https://cwe.mitre.org/data/definitions/1049.html'),
56
- },
57
- description: (0, parseRuleDescription_1.default)('tooManyJoins'),
58
- url: 'https://appland.com/docs/analysis/rules-reference.html#too-many-joins',
59
- Options,
60
- build,
61
- };
51
+ exports.default = rule;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ title: 'Unauthenticated encryption',
5
+ enumerateScope: true,
6
+ impactDomain: 'Security',
7
+ references: {
8
+ 'A02:2021': 'https://owasp.org/Top10/A02_2021-Cryptographic_Failures/',
9
+ },
10
+ labels: ['crypto.encrypt', 'crypto.set_auth_data'],
11
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function matcher(event, appMapIndex) {
4
+ if (!event.receiver)
5
+ return;
6
+ const objectId = event.receiver.object_id;
7
+ const setAuthData = appMapIndex.appMap.events
8
+ .filter((evt) => { var _a; return ((_a = evt.receiver) === null || _a === void 0 ? void 0 : _a.object_id) === objectId; })
9
+ .find((evt) => evt.labels.has('crypto.set_auth_data'));
10
+ if (!setAuthData) {
11
+ return [
12
+ {
13
+ event,
14
+ message: 'Encryption is not authenticated',
15
+ },
16
+ ];
17
+ }
18
+ }
19
+ function rule() {
20
+ return {
21
+ matcher,
22
+ where: (e) => e.labels.has('crypto.encrypt'),
23
+ };
24
+ }
25
+ exports.default = rule;
@@ -1,26 +1,28 @@
1
1
  checks:
2
- - rule: authzBeforeAuthn
3
- # - rule: circularDependency
4
- - rule: deserializationOfUntrustedData
5
- - rule: execOfUntrustedCommand
6
- - rule: http500
7
- # - rule: illegalPackageDependency
8
- # - rule: incompatibleHttpClientRequest
9
- # - rule: insecureCompare
10
- # - rule: jobNotCancelled
11
- - rule: logoutWithoutSessionReset
12
- # - rule: missingAuthentication
13
- - rule: missingContentType
14
- - rule: nPlusOneQuery
15
- # - rule: queryFromInvalidPackage
16
- # - rule: queryFromView
17
- # - rule: rpcWithoutCircuitBreaker
18
- # - rule: saveWithoutValidation
19
- - rule: secretInLog
20
- # - rule: slowFunctionCall
21
- # - rule: slowHttpServerRequest
22
- # - rule: slowQuery
23
- - rule: tooManyJoins
24
- - rule: tooManyUpdates
25
- # - rule: unbatchedMaterializedQuery
26
- - rule: updateInGetRequest
2
+ - rule: authz-before-authn
3
+ # - rule: circular-dependency
4
+ - rule: deprecated-crypto-algorithm
5
+ - rule: deserialization-of-untrusted-data
6
+ - rule: exec-of-untrusted-command
7
+ - rule: http-500
8
+ # - rule: illegal-package-dependency
9
+ # - rule: incompatible-http-client-request
10
+ # - rule: insecure-compare
11
+ # - rule: job-not-cancelled
12
+ - rule: logout-without-session-reset
13
+ # - rule: missing-authentication
14
+ - rule: missing-content-type
15
+ - rule: n-plus-one-query
16
+ # - rule: query-from-invalid-package
17
+ # - rule: query-from-view
18
+ # - rule: rpc-without-circuit-breaker
19
+ # - rule: save-without-validation
20
+ - rule: secret-in-log
21
+ # - rule: slow-function-call
22
+ # - rule: slow-httpServer-request
23
+ # - rule: slow-query
24
+ - rule: too-many-joins
25
+ - rule: too-many-updates
26
+ # - rule: unbatched-materialized-query
27
+ - rule: unauthenticated-encryption
28
+ - rule: update-in-get-request
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: crypto.decrypt
3
+ rules:
4
+ - deprecated-crypto-algorithm
5
+ ---
6
+
7
+ A function that performs decryption.
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: crypto.digest
3
+ rules:
4
+ - deprecated-crypto-algorithm
5
+ ---
6
+
7
+ A function that computes a cryptographic digest (or 'hash') of some data.
@@ -0,0 +1,8 @@
1
+ ---
2
+ name: crypto.encrypt
3
+ rules:
4
+ - deprecated-crypto-algorithm
5
+ - unauthenticated-encryption
6
+ ---
7
+
8
+ A function that performs encryption.
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: crypto.set_auth_data
3
+ rules:
4
+ - unauthenticated-encryption
5
+ ---
6
+
7
+ A function that sets authenticated data for an encryption operation.
@@ -0,0 +1,15 @@
1
+ ---
2
+ rule: deprecated-crypto-algorithm
3
+ name: Deprecated crypto algorithm
4
+ title: Deprecated cryptographic algorithm
5
+ references:
6
+ A02:2021: https://owasp.org/Top10/A02_2021-Cryptographic_Failures/
7
+ impactDomain: Security
8
+ labels:
9
+ - crypto.encrypt
10
+ - crypto.decrypt
11
+ - crypto.digest
12
+ scope: root
13
+ ---
14
+
15
+ Ensure that cryptographic operations do not use deprecated algorithms.
@@ -0,0 +1,42 @@
1
+ ---
2
+ rule: unauthenticated-encryption
3
+ name: Unauthenticated encryption
4
+ title: Unauthenticated encryption
5
+ references:
6
+ A02:2021: https://owasp.org/Top10/A02_2021-Cryptographic_Failures/
7
+ impactDomain: Security
8
+ labels:
9
+ - crypto.encrypt
10
+ - crypto.set_auth_data
11
+ ---
12
+
13
+ Ensures that encryption operations use authenticated encryption.
14
+
15
+ ### Rule logic
16
+
17
+ Finds all events labeled `crypto.encrypt`. For each of these events, there should be another event
18
+ in the same AppMap that has the same `receiver.object_id` and also has the label
19
+ `crypto.set_auth_data`.
20
+
21
+ ### Notes
22
+
23
+ [OWASP recommends against the use of unauthenticated encryption](https://owasp.org/Top10/A02_2021-Cryptographic_Failures/).
24
+
25
+ ### Resolution
26
+
27
+ Change the encryption code to use a current authenticated encryption algorithm. At the time of this
28
+ writing, an example is `aes-256-gcm`.
29
+
30
+ Examples:
31
+
32
+ - [`OpenSSL::Cipher#auth_data=` (Ruby)](https://ruby-doc.org/stdlib-3.1.1/libdoc/openssl/rdoc/OpenSSL/Cipher.html#method-i-auth_data-3D)
33
+
34
+ ### Options
35
+
36
+ None
37
+
38
+ ### Examples
39
+
40
+ ```yaml
41
+ - rule: unauthenticated-encryption
42
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appland/scanner",
3
- "version": "1.64.0",
3
+ "version": "1.67.0",
4
4
  "description": "",
5
5
  "bin": "built/cli.js",
6
6
  "files": [