kuzzle 2.60.0 → 2.60.1-beta.1

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.
@@ -60,6 +60,7 @@ const node_util_1 = require("node:util");
60
60
  const json2yaml_1 = __importDefault(require("json2yaml"));
61
61
  const package_json_1 = __importDefault(require("../../../package.json"));
62
62
  const kerror = __importStar(require("../../kerror"));
63
+ const redactSecrets_1 = require("../../util/redactSecrets");
63
64
  const baseController_1 = require("./baseController");
64
65
  /** Whatever a health probe rejected with, as an `Error`. */
65
66
  function causeOf(thrown) {
@@ -141,16 +142,9 @@ class ServerController extends baseController_1.NativeController {
141
142
  * @returns {Promise<Object>}
142
143
  */
143
144
  async getConfig() {
144
- const config = JSON.parse(JSON.stringify(global.kuzzle.config)); // NOSONAR: intentional JSON-safe deep clone (strips non-serializable config values); structuredClone would change semantics / can throw
145
- // Already and more appropriately returned by server:info
146
- config.http.routes = undefined;
147
- // Not a good idea to export Kuzzle's salt, hash algorithm
148
- // and default rights
149
- config.security = undefined;
150
- if (config.VAULT_KEY) {
151
- config.VAULT_KEY = undefined;
152
- }
153
- return config;
145
+ // Secrets are masked before the JSON clone: the clone turns a `Buffer`
146
+ // into `{ type, data }`, which would no longer be masked whole (ADR-0004).
147
+ return JSON.parse(JSON.stringify((0, redactSecrets_1.toPublicConfig)(global.kuzzle.config))); // NOSONAR: intentional JSON-safe deep clone (strips non-serializable config values); structuredClone would change semantics / can throw
154
148
  }
155
149
  /**
156
150
  * Returns the Kuzzle capabilities
@@ -31,6 +31,7 @@ const default_config_1 = __importDefault(require("./default.config"));
31
31
  const authTokenSettings_1 = require("../core/security/authTokenSettings");
32
32
  const package_json_1 = __importDefault(require("../../package.json"));
33
33
  const kerror_1 = require("../kerror");
34
+ const redactSecrets_1 = require("../util/redactSecrets");
34
35
  const safeObject_1 = require("../util/safeObject");
35
36
  const bytes_1 = __importDefault(require("../util/bytes"));
36
37
  const wrapped = (0, kerror_1.wrap)("core", "configuration");
@@ -153,6 +154,12 @@ function unstringify(cfg) {
153
154
  throw wrapped.get("cannot_parse", `the key "${k}" does not contain a valid stringified JSON (${cfg[k]})`);
154
155
  }
155
156
  }
157
+ else if ((0, redactSecrets_1.isSecretKey)(k)) {
158
+ // A secret keeps its text form: "0123" is a password, not 123
159
+ // (ADR-0004). Only the number conversion is skipped, so a boolean
160
+ // switch named like a secret (`requirePassword`) still converts.
161
+ return;
162
+ }
156
163
  else if (/^(-|\+)?([0-9]+)$/.test(cfg[k])) {
157
164
  cfg[k] = Number.parseInt(cfg[k]);
158
165
  }
@@ -65,6 +65,7 @@ const moment_1 = __importDefault(require("moment"));
65
65
  const package_json_1 = __importDefault(require("../../package.json"));
66
66
  const kerror = __importStar(require("../kerror"));
67
67
  const errors_1 = require("../kerror/errors");
68
+ const redactSecrets_1 = require("../util/redactSecrets");
68
69
  class DumpGenerator {
69
70
  constructor() {
70
71
  this._dump = false;
@@ -125,25 +126,28 @@ class DumpGenerator {
125
126
  this.logger.error(message);
126
127
  throw new Error(message, { cause: e });
127
128
  }
128
- // dump kuzzle information
129
+ // dump kuzzle information, secrets masked: dumps end up attached to
130
+ // support tickets (ADR-0004)
129
131
  this.logger.info("> dumping kuzzle configuration");
130
132
  node_fs_1.default.writeFileSync(node_path_1.default.join(dumpPath, "kuzzle.json"), JSON.stringify({
131
- config: global.kuzzle.config,
133
+ config: (0, redactSecrets_1.toPublicConfig)(global.kuzzle.config),
132
134
  version: package_json_1.default.version,
133
135
  }, null, " ").concat("\n"));
134
136
  // dump plugins configuration
135
137
  this.logger.info("> dumping plugins configuration");
136
138
  node_fs_1.default.writeFileSync(node_path_1.default.join(dumpPath, "plugins.json"), JSON.stringify(global.kuzzle.pluginsManager.getPluginsDescription(), null, " ").concat("\n"));
137
- // dump Node.js configuration
139
+ // dump Node.js configuration. The environment is masked by the same key
140
+ // rule as the configuration: a `kuzzle_…__password` variable is where a
141
+ // documented Redis password lives.
138
142
  this.logger.info("> dumping Node.js configuration");
139
- node_fs_1.default.writeFileSync(node_path_1.default.join(dumpPath, "nodejs.json"), JSON.stringify({
143
+ node_fs_1.default.writeFileSync(node_path_1.default.join(dumpPath, "nodejs.json"), JSON.stringify((0, redactSecrets_1.redactSecrets)({
140
144
  argv: process.argv,
141
145
  config: process.config,
142
146
  env: process.env,
143
147
  moduleLoadList: process.moduleLoadList,
144
148
  release: process.release,
145
149
  versions: process.versions,
146
- }, null, " ").concat("\n"));
150
+ }), null, " ").concat("\n"));
147
151
  // dump os configuration
148
152
  this.logger.info("> dumping os configuration");
149
153
  node_fs_1.default.writeFileSync(node_path_1.default.join(dumpPath, "os.json"), JSON.stringify({
@@ -0,0 +1,38 @@
1
+ import type { JSONObject } from "../types/JSONObject";
2
+ /**
3
+ * Masks configuration secrets before the configuration leaves the process
4
+ * (`server:getConfig`, `admin:dump`). The rule is driven by key names, not by
5
+ * a list of paths, so that plugin and application secrets are covered too
6
+ * (ADR-0004, Decision §3 and §4).
7
+ */
8
+ /** What a secret value is replaced with. */
9
+ export declare const REDACTED = "***";
10
+ /**
11
+ * Whether a key names a secret, case-insensitively: exactly `key`, `pfx` or
12
+ * `auth`, or a name ending with one of {@link SECRET_SUFFIXES}.
13
+ * `cookieAuthentication` does not match by construction.
14
+ */
15
+ export declare function isSecretKey(name: string): boolean;
16
+ /** Replaces the password of every `scheme://user:pass@host` in a string. */
17
+ export declare function redactUrlCredentials(text: string): string;
18
+ /**
19
+ * A copy of `value` with every secret masked: values under a secret key (see
20
+ * {@link isSecretKey}) become `"***"`, and URL credentials in every string
21
+ * become `user:***@`. `mappings` subtrees are kept as-is: they describe
22
+ * Elasticsearch fields, a field named `token` is not a secret.
23
+ *
24
+ * The input is never mutated. Plain objects and arrays are copied; any other
25
+ * object (`Buffer`, `Date`...) is passed through, so this must run **before**
26
+ * any JSON clone — a JSON clone turns a `Buffer` into `{ type, data }`, whose
27
+ * leaves would no longer be recognised as one secret.
28
+ */
29
+ export declare function redactSecrets(value: JSONObject): JSONObject;
30
+ export declare function redactSecrets(value: unknown): unknown;
31
+ /**
32
+ * The configuration as it may leave the process: without `http.routes`
33
+ * (already returned by `server:info`), `security` (salt, hash algorithm,
34
+ * default rights, token secret) and `VAULT_KEY`, then with every remaining
35
+ * secret masked. `server:getConfig` and `admin:dump` both use it, so they
36
+ * cannot drift apart.
37
+ */
38
+ export declare function toPublicConfig(config: JSONObject): JSONObject;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /*
3
+ * Kuzzle, a backend software, self-hostable and ready to use
4
+ * to power modern apps
5
+ *
6
+ * Copyright 2015-2022 Kuzzle
7
+ * mailto: support AT kuzzle.io
8
+ * website: http://kuzzle.io
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * https://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.REDACTED = void 0;
24
+ exports.isSecretKey = isSecretKey;
25
+ exports.redactUrlCredentials = redactUrlCredentials;
26
+ exports.redactSecrets = redactSecrets;
27
+ exports.toPublicConfig = toPublicConfig;
28
+ const safeObject_1 = require("./safeObject");
29
+ /**
30
+ * Masks configuration secrets before the configuration leaves the process
31
+ * (`server:getConfig`, `admin:dump`). The rule is driven by key names, not by
32
+ * a list of paths, so that plugin and application secrets are covered too
33
+ * (ADR-0004, Decision §3 and §4).
34
+ */
35
+ /** What a secret value is replaced with. */
36
+ exports.REDACTED = "***";
37
+ const SECRET_NAMES = new Set(["key", "pfx", "auth"]);
38
+ const SECRET_SUFFIXES = [
39
+ "password",
40
+ "passphrase",
41
+ "secret",
42
+ "apikey",
43
+ "token",
44
+ "credentials",
45
+ "privatekey",
46
+ "secretkey",
47
+ "signingkey",
48
+ "encryptionkey",
49
+ "accesskey",
50
+ "access_key",
51
+ "licensekey",
52
+ "license_key",
53
+ "vault_key",
54
+ ];
55
+ /**
56
+ * `user:pass@` in a URL. The password part stops at the characters a URL
57
+ * cannot hold unencoded there, so the match stays linear.
58
+ */
59
+ const URL_CREDENTIALS = /(\/\/[^\s/:@]*):[^\s/@]+@/g;
60
+ /**
61
+ * Whether a key names a secret, case-insensitively: exactly `key`, `pfx` or
62
+ * `auth`, or a name ending with one of {@link SECRET_SUFFIXES}.
63
+ * `cookieAuthentication` does not match by construction.
64
+ */
65
+ function isSecretKey(name) {
66
+ const lower = name.toLowerCase();
67
+ return (SECRET_NAMES.has(lower) ||
68
+ SECRET_SUFFIXES.some((suffix) => lower.endsWith(suffix)));
69
+ }
70
+ /** Replaces the password of every `scheme://user:pass@host` in a string. */
71
+ function redactUrlCredentials(text) {
72
+ return text.replace(URL_CREDENTIALS, `$1:${exports.REDACTED}@`);
73
+ }
74
+ /**
75
+ * The value under a secret key. `null`, `undefined` and booleans are kept, so
76
+ * one can still tell whether a secret is set; a plain object keeps its
77
+ * structure with its leaves masked; anything else — string, number, `Buffer`,
78
+ * array — is masked whole.
79
+ */
80
+ function maskSecret(value) {
81
+ if (value === null || value === undefined || typeof value === "boolean") {
82
+ return value;
83
+ }
84
+ if ((0, safeObject_1.isPlainObject)(value)) {
85
+ const masked = {};
86
+ for (const [key, child] of Object.entries(value)) {
87
+ masked[key] = maskSecret(child);
88
+ }
89
+ return masked;
90
+ }
91
+ return exports.REDACTED;
92
+ }
93
+ function redactSecrets(value) {
94
+ if (typeof value === "string") {
95
+ return redactUrlCredentials(value);
96
+ }
97
+ if (Array.isArray(value)) {
98
+ return value.map(redactSecrets);
99
+ }
100
+ if (!(0, safeObject_1.isPlainObject)(value)) {
101
+ return value;
102
+ }
103
+ const copy = {};
104
+ for (const [key, child] of Object.entries(value)) {
105
+ if (key === "mappings") {
106
+ copy[key] = child;
107
+ }
108
+ else if (isSecretKey(key)) {
109
+ copy[key] = maskSecret(child);
110
+ }
111
+ else {
112
+ copy[key] = redactSecrets(child);
113
+ }
114
+ }
115
+ return copy;
116
+ }
117
+ /**
118
+ * The configuration as it may leave the process: without `http.routes`
119
+ * (already returned by `server:info`), `security` (salt, hash algorithm,
120
+ * default rights, token secret) and `VAULT_KEY`, then with every remaining
121
+ * secret masked. `server:getConfig` and `admin:dump` both use it, so they
122
+ * cannot drift apart.
123
+ */
124
+ function toPublicConfig(config) {
125
+ const exported = { ...config };
126
+ delete exported.security;
127
+ delete exported.VAULT_KEY;
128
+ if ((0, safeObject_1.isPlainObject)(exported.http)) {
129
+ exported.http = { ...exported.http };
130
+ delete exported.http.routes;
131
+ }
132
+ return redactSecrets(exported);
133
+ }
134
+ //# sourceMappingURL=redactSecrets.js.map
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.60.0",
4
+ "version": "2.60.1-beta.1",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.60.0",
4
+ "version": "2.60.1-beta.1",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "scripts": {
7
7
  "build": "rm -Rf ./dist && tsc && node -r ts-node/register/transpile-only ./bin/copy-binaries.ts",