@appland/scanner 1.63.0 → 1.66.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,36 @@
1
+ # [@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)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Fix rule doc ([b99b6ae](https://github.com/applandinc/appmap-js/commit/b99b6aec90186bef312d04fb4f4c95f9b1ee62d5))
7
+
8
+
9
+ ### Features
10
+
11
+ * Add deprecated-crypto-algorithm to default rule set ([3034489](https://github.com/applandinc/appmap-js/commit/303448974a73637493a72bea7ab8cfb28ccc8b10))
12
+ * Detect deprecated crypto algorithm ([a17a537](https://github.com/applandinc/appmap-js/commit/a17a537334771a9f2cd64fa73c2396e517ff82ea))
13
+
14
+ # [@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)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Remove an inadvenant console log ([5c11fc7](https://github.com/applandinc/appmap-js/commit/5c11fc77650e105f169ca0bcc4045312578e8881))
20
+
21
+
22
+ ### Features
23
+
24
+ * Add unauthenticated-encryption to default rule set ([2e3cf92](https://github.com/applandinc/appmap-js/commit/2e3cf9298b3cfe99b489ab8b2894e913a305fdd0))
25
+ * Check for unauthenticated encryption ([d393951](https://github.com/applandinc/appmap-js/commit/d393951c73c4492f1e95b52a2580fde10b256ee4))
26
+
27
+ # [@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)
28
+
29
+
30
+ ### Features
31
+
32
+ * Command scope falls back on root events ([3823a1f](https://github.com/applandinc/appmap-js/commit/3823a1f686212db49b87f2995baa2103a4e007d1))
33
+
1
34
  # [@appland/scanner-v1.63.0](https://github.com/applandinc/appmap-js/compare/@appland/scanner-v1.62.2...@appland/scanner-v1.63.0) (2022-07-28)
2
35
 
3
36
 
package/built/check.js CHANGED
@@ -9,7 +9,7 @@ class Check {
9
9
  }
10
10
  this.id = rule.id;
11
11
  this.options = options || makeOptions();
12
- this.scope = rule.scope || 'root';
12
+ this.scope = rule.scope || 'command';
13
13
  this.includeScope = [];
14
14
  this.excludeScope = [];
15
15
  this.includeEvent = [];
@@ -35,14 +35,7 @@ class RuleChecker {
35
35
  }
36
36
  check(appMapFile, appMapIndex, check, findings) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
- const numScopesChecked = yield this.checkScope(appMapFile, appMapIndex, check, check.scope, findings);
39
- if (numScopesChecked === 0 && check.scope === 'command') {
40
- yield this.checkScope(appMapFile, appMapIndex, check, 'root', findings);
41
- }
42
- });
43
- }
44
- checkScope(appMapFile, appMapIndex, check, scope, findings) {
45
- return __awaiter(this, void 0, void 0, function* () {
38
+ const scope = check.scope;
46
39
  if ((0, util_1.verbose)()) {
47
40
  console.warn(`Checking AppMap ${appMapIndex.appMap.name} with scope ${scope}`);
48
41
  }
@@ -56,9 +49,7 @@ class RuleChecker {
56
49
  yield events[i];
57
50
  }
58
51
  };
59
- let numScopes = 0;
60
52
  for (const scope of scopeIterator.scopes(callEvents())) {
61
- numScopes += 1;
62
53
  if ((0, util_1.verbose)()) {
63
54
  console.warn(`Scope ${scope.scope}`);
64
55
  }
@@ -75,7 +66,6 @@ class RuleChecker {
75
66
  yield this.checkEvent(scope.scope, scope.scope, appMapFile, appMapIndex, checkInstance, findings);
76
67
  }
77
68
  }
78
- return numScopes;
79
69
  });
80
70
  }
81
71
  checkEvent(event, scope, appMapFile, appMapIndex, checkInstance, findings) {
@@ -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;
@@ -101,6 +101,7 @@ exports.default = {
101
101
  id: 'secret-in-log',
102
102
  title: 'Secret in log',
103
103
  labels: [Secret, Log],
104
+ scope: 'root',
104
105
  impactDomain: 'Security',
105
106
  enumerateScope: true,
106
107
  references: {
@@ -30,7 +30,6 @@ function build(options) {
30
30
  exports.default = {
31
31
  id: 'slow-function-call',
32
32
  title: 'Slow function call',
33
- scope: 'root',
34
33
  impactDomain: 'Performance',
35
34
  enumerateScope: true,
36
35
  description: (0, parseRuleDescription_1.default)('slowFunctionCall'),
@@ -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
@@ -21,15 +21,28 @@ const Command = 'command.perform';
21
21
  const Job = 'job.perform';
22
22
  class CommandScope extends scopeIterator_1.default {
23
23
  *scopes(events) {
24
+ let found = false;
25
+ const roots = [];
24
26
  for (const event of events) {
27
+ if (event.isCall() && !event.parent) {
28
+ roots.push(event);
29
+ }
25
30
  if (event.isCall() &&
26
31
  (event.codeObject.labels.has(Command) ||
27
32
  event.codeObject.labels.has(Job) ||
28
33
  event.httpServerRequest)) {
34
+ found = true;
29
35
  yield new ScopeImpl(event);
30
36
  this.advanceToReturnEvent(event, events);
31
37
  }
32
38
  }
39
+ // If no true command is found, yield all root events.
40
+ if (!found) {
41
+ for (let index = 0; index < roots.length; index++) {
42
+ const event = roots[index];
43
+ yield new ScopeImpl(event);
44
+ }
45
+ }
33
46
  }
34
47
  }
35
48
  exports.default = CommandScope;
@@ -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.
@@ -8,6 +8,7 @@ impactDomain: Security
8
8
  labels:
9
9
  - secret
10
10
  - log
11
+ scope: root
11
12
  ---
12
13
 
13
14
  Identifies when a known or assumed secret is written to a log. Logs are often transported into other
@@ -3,7 +3,6 @@ rule: slow-function-call
3
3
  name: Slow function call
4
4
  title: Slow function call
5
5
  impactDomain: Performance
6
- scope: root
7
6
  ---
8
7
 
9
8
  Ensures that function elapsed time does not exceed a threshold.
@@ -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.63.0",
3
+ "version": "1.66.0",
4
4
  "description": "",
5
5
  "bin": "built/cli.js",
6
6
  "files": [
@@ -61,7 +61,6 @@
61
61
  "@appland/sql-parser": "^1.5.0",
62
62
  "@types/cli-progress": "^3.9.2",
63
63
  "ajv": "^8.8.2",
64
- "ansi-escapes": "^5.0.0",
65
64
  "applicationinsights": "^2.1.4",
66
65
  "async": "^3.2.3",
67
66
  "chalk": "^4.1.2",
@@ -86,16 +85,20 @@
86
85
  },
87
86
  "pkg": {
88
87
  "targets": [
89
- "node14-linux-x64",
90
- "node14-win-x64",
91
- "node14-macos-x64"
88
+ "node16-linux-x64",
89
+ "node16-win-x64",
90
+ "node16-macos-x64",
91
+ "node16-macos-arm64"
92
92
  ],
93
93
  "scripts": [
94
- "built/scanner/*.js"
94
+ "built/scanner/*.js",
95
+ "built/rules/**/*.js"
95
96
  ],
96
97
  "assets": [
97
98
  "built/sampleConfig/*.yml",
98
- "built/**/*.json"
99
+ "built/**/*.json",
100
+ "package.json",
101
+ "doc/**/*.md"
99
102
  ],
100
103
  "outputPath": "dist"
101
104
  }