@lenne.tech/nest-server 12.3.2 → 12.5.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/.claude/rules/configurable-features.md +2 -1
- package/.claude/rules/testing.md +4 -4
- package/FRAMEWORK-API.md +2 -1
- package/dist/core/common/helpers/config-endpoint.helper.d.ts +3 -0
- package/dist/core/common/helpers/config-endpoint.helper.js +17 -0
- package/dist/core/common/helpers/config-endpoint.helper.js.map +1 -0
- package/dist/core/common/helpers/redact-secrets.helper.d.ts +3 -0
- package/dist/core/common/helpers/redact-secrets.helper.js +72 -0
- package/dist/core/common/helpers/redact-secrets.helper.js.map +1 -0
- package/dist/core/common/helpers/swagger.helper.js +6 -0
- package/dist/core/common/helpers/swagger.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +6 -0
- package/dist/core/common/services/config.service.d.ts +3 -0
- package/dist/core/common/services/config.service.js +17 -3
- package/dist/core/common/services/config.service.js.map +1 -1
- package/dist/core/modules/error-code/error-codes.d.ts +18 -0
- package/dist/core/modules/error-code/error-codes.js +16 -0
- package/dist/core/modules/error-code/error-codes.js.map +1 -1
- package/dist/core/modules/hub/core-hub.service.js +1 -13
- package/dist/core/modules/hub/core-hub.service.js.map +1 -1
- package/dist/core/modules/hub/helpers/hub-mask.helper.d.ts +1 -1
- package/dist/core/modules/hub/helpers/hub-mask.helper.js +1 -42
- package/dist/core/modules/hub/helpers/hub-mask.helper.js.map +1 -1
- package/dist/core/modules/system-setup/core-system-setup.controller.d.ts +2 -2
- package/dist/core/modules/system-setup/core-system-setup.controller.js +17 -7
- package/dist/core/modules/system-setup/core-system-setup.controller.js.map +1 -1
- package/dist/core/modules/system-setup/core-system-setup.service.d.ts +18 -0
- package/dist/core/modules/system-setup/core-system-setup.service.js +118 -15
- package/dist/core/modules/system-setup/core-system-setup.service.js.map +1 -1
- package/dist/core/modules/system-setup/system-setup-http-init.helper.d.ts +11 -0
- package/dist/core/modules/system-setup/system-setup-http-init.helper.js +45 -0
- package/dist/core/modules/system-setup/system-setup-http-init.helper.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/server/modules/error-code/error-codes.d.ts +2 -0
- package/dist/server/server.controller.d.ts +1 -1
- package/dist/server/server.controller.js +2 -2
- package/dist/server/server.controller.js.map +1 -1
- package/migration-guides/11.13.x-to-11.14.0.md +5 -5
- package/migration-guides/12.3.x-to-12.4.x.md +169 -0
- package/migration-guides/12.4.x-to-12.5.x.md +136 -0
- package/package.json +1 -1
- package/src/core/common/helpers/config-endpoint.helper.ts +56 -0
- package/src/core/common/helpers/redact-secrets.helper.ts +175 -0
- package/src/core/common/helpers/swagger.helper.ts +7 -0
- package/src/core/common/interfaces/server-options.interface.ts +79 -5
- package/src/core/common/services/config.service.ts +41 -3
- package/src/core/modules/error-code/error-codes.ts +27 -0
- package/src/core/modules/hub/README.md +3 -1
- package/src/core/modules/hub/core-hub.service.ts +4 -20
- package/src/core/modules/hub/helpers/hub-mask.helper.ts +4 -92
- package/src/core/modules/system-setup/INTEGRATION-CHECKLIST.md +51 -16
- package/src/core/modules/system-setup/README.md +144 -28
- package/src/core/modules/system-setup/core-system-setup.controller.ts +30 -8
- package/src/core/modules/system-setup/core-system-setup.service.ts +246 -23
- package/src/core/modules/system-setup/system-setup-http-init.helper.ts +130 -0
- package/src/index.ts +3 -0
- package/src/server/server.controller.ts +7 -2
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive, non-mutating secret redaction for configuration objects and anything shaped like them.
|
|
3
|
+
*
|
|
4
|
+
* The framework's ONE masker: `GET /config` (`configEndpointResponse()`), the Hub config panel and the
|
|
5
|
+
* `ConfigService` debug output all go through it, so they cannot drift apart. It moved here from the Hub
|
|
6
|
+
* (`hub-mask.helper.ts`, which re-exports it as `maskConfigDeep`) in 12.5.0.
|
|
7
|
+
*
|
|
8
|
+
* CRITICAL: this deep-clones before masking. A response must never be handed a live, service-owned object —
|
|
9
|
+
* `CheckSecurityInterceptor` deletes secret-named keys IN PLACE, which would corrupt the running server config.
|
|
10
|
+
* Cloning here is the guarantee.
|
|
11
|
+
*
|
|
12
|
+
* It errs towards masking: a value that only looks secret costs an operator a look into the environment, a
|
|
13
|
+
* missed secret costs the platform.
|
|
14
|
+
*
|
|
15
|
+
* @since 12.5.0 (as `maskConfigDeep` in the Hub since 11.x)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Key-name heuristics that mark a value as secret. Matched case-insensitively against each key.
|
|
20
|
+
*
|
|
21
|
+
* A SUPERSET of the pattern the nest-server-starter used before 12.5.0 (`token`, `pass$`, `key$`, `salt`, `dsn`, …), so
|
|
22
|
+
* a project that swaps its own masker for this one loses nothing. Compound names are what makes that matter:
|
|
23
|
+
* `\btoken\b` misses `botToken` and `GITHUB_TOKEN` (letters and `_` are both word characters, so there is no boundary
|
|
24
|
+
* inside them), `\bpass\b` misses `smtpPass`, and `(^|[^a-z])key…` misses `signingKey` (the `i` flag makes `[^a-z]`
|
|
25
|
+
* reject the uppercase `K`). Hence the unanchored `token`, `pass$` and `key$`.
|
|
26
|
+
*
|
|
27
|
+
* `access[-_]?key` covers `accessKeyId`, which neither `key$` nor the bounded `key` alternative reaches. The cost of
|
|
28
|
+
* the broad forms is a few masked non-secrets (`passkey`, `tokenExpiresInMinutes`): the module errs towards masking,
|
|
29
|
+
* and booleans below such a key stay visible.
|
|
30
|
+
*/
|
|
31
|
+
const SECRET_KEY_PATTERN =
|
|
32
|
+
/secret|passwd|password|passphrase|credential|api[-_]?key|access[-_]?key|private[-_]?key|encryption|token|\bpass\b|pass$|dsn|salt|key$|(^|[^a-z])key([^a-z]|$)/i;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Keys whose value is an address that can carry a secret in its PATH (a Slack or Teams webhook,
|
|
36
|
+
* `https://hooks.slack.com/services/T…/B…/<secret>`) or anywhere in its query. Such a value keeps scheme, host and port —
|
|
37
|
+
* what an operator needs to tell where it points — and loses the rest.
|
|
38
|
+
*/
|
|
39
|
+
const URL_KEY_PATTERN = /(url|uri|endpoint|webhook)$/i;
|
|
40
|
+
|
|
41
|
+
/** `scheme://authority` and whatever follows (path, query, fragment). The authority may hold spaces (a password can) */
|
|
42
|
+
const URI_PARTS_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/[^/?#]*)(.*)$/is;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The whole user info of an authority, up to its LAST `@`: under a URL-named key a token is often the user itself
|
|
46
|
+
* (`https://<pat>@github.com`, `https://<key>@o0.ingest.sentry.io`), so not only a password goes.
|
|
47
|
+
*/
|
|
48
|
+
const URI_USERINFO_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/).*@/is;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Value-shape heuristic: a connection URI carrying `scheme://user:password@host`.
|
|
52
|
+
*
|
|
53
|
+
* The user part is `*`, not `+`, so the PASSWORD-ONLY form is matched too:
|
|
54
|
+
* `redis://:password@host` is the canonical Redis URL (Redis < 6 has no username, and
|
|
55
|
+
* `redis-cli -u`, Heroku Redis and ElastiCache AUTH all emit it).
|
|
56
|
+
*
|
|
57
|
+
* The user may contain `@` (a mail login is an e-mail address: `smtps://noreply@example.com:pw@smtp.example.com`) and
|
|
58
|
+
* the password `@` or spaces (`pg`, ioredis and the MongoDB driver accept them unencoded): the password runs to the LAST
|
|
59
|
+
* `@` before the path, query or end. Still safe against false positives: `http://host:8080/x@y`,
|
|
60
|
+
* `https://user@host:443/p` and `https://host/?a=b@c` do not match — the `@` must sit inside the authority.
|
|
61
|
+
*/
|
|
62
|
+
const URI_CREDENTIAL_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/[^/?#:]*:)([^/?#]*)(@[^@/?#]*)(?=[/?#]|$)/i;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A query parameter of a URI-shaped value (`?password=…`, `&sslpassword=…`, `&token=…`). Its value is masked when
|
|
66
|
+
* the parameter name is secret by {@link SECRET_KEY_PATTERN}: a PostgreSQL or MongoDB URL can carry a password there
|
|
67
|
+
* instead of in the user info.
|
|
68
|
+
*/
|
|
69
|
+
const URI_QUERY_PARAM_PATTERN = /([?&])([^=&#\s]+)=([^&#\s]*)/g;
|
|
70
|
+
|
|
71
|
+
/** What a masked value reads as */
|
|
72
|
+
export const REDACTED_VALUE = '***';
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Field names the framework treats as secret wherever they appear, whatever the key pattern says (the defaults of
|
|
76
|
+
* `security.secretFields`, see `CheckSecurityInterceptor`).
|
|
77
|
+
*
|
|
78
|
+
* @since 12.5.0
|
|
79
|
+
*/
|
|
80
|
+
export const FRAMEWORK_SECRET_FIELDS: readonly string[] = [
|
|
81
|
+
'password',
|
|
82
|
+
'verificationToken',
|
|
83
|
+
'passwordResetToken',
|
|
84
|
+
'passwordResetTokenExpiresAt',
|
|
85
|
+
'refreshTokens',
|
|
86
|
+
'tempTokens',
|
|
87
|
+
'apiKeyEncrypted',
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Deep-clone `value` and mask every secret it contains.
|
|
92
|
+
*
|
|
93
|
+
* - A value whose key matches {@link SECRET_KEY_PATTERN} or appears in `extraSecretKeys` is masked. Below such a key
|
|
94
|
+
* EVERYTHING is masked — a nested object is never a way around it — except booleans, which carry no secret and
|
|
95
|
+
* keep flags such as `emailAndPassword.disableSignUp` readable.
|
|
96
|
+
* - A string shaped like a connection URI has the password of its user info masked, and every secret-named query
|
|
97
|
+
* parameter, whatever its key is called.
|
|
98
|
+
* - `null` and `undefined` pass through; a `Date` or `Buffer` is kept as it is (masked under a secret key).
|
|
99
|
+
*
|
|
100
|
+
* @param value - the object or value to mask (never mutated)
|
|
101
|
+
* @param extraSecretKeys - additional exact key names to always mask (e.g. `security.secretFields`)
|
|
102
|
+
* @since 12.5.0
|
|
103
|
+
*/
|
|
104
|
+
export function redactSecrets<T>(value: T, extraSecretKeys: readonly string[] = []): T {
|
|
105
|
+
const extra = new Set(extraSecretKeys.filter((key) => typeof key === 'string').map((key) => key.toLowerCase()));
|
|
106
|
+
return redactValue(value, false, extra, '') as T;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isSecretKey(key: string, extra: Set<string>): boolean {
|
|
110
|
+
return extra.has(key.toLowerCase()) || SECRET_KEY_PATTERN.test(key);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A URI-shaped value of a URL-named key: scheme, host and port stay; the whole user info and everything after the
|
|
115
|
+
* authority are replaced
|
|
116
|
+
*/
|
|
117
|
+
function redactUrl(value: string): string {
|
|
118
|
+
const parts = value.match(URI_PARTS_PATTERN);
|
|
119
|
+
if (!parts) {
|
|
120
|
+
return redactString(value);
|
|
121
|
+
}
|
|
122
|
+
const authority = parts[1].replace(URI_USERINFO_PATTERN, `$1${REDACTED_VALUE}@`);
|
|
123
|
+
return parts[2] && parts[2] !== '/' ? `${authority}/${REDACTED_VALUE}` : `${authority}${parts[2]}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function redactString(value: string): string {
|
|
127
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
const withoutUserPassword = value.replace(URI_CREDENTIAL_PATTERN, `$1${REDACTED_VALUE}$3`);
|
|
131
|
+
return withoutUserPassword.replace(URI_QUERY_PARAM_PATTERN, (match, separator: string, name: string) =>
|
|
132
|
+
SECRET_KEY_PATTERN.test(safeDecode(name)) ? `${separator}${name}=${REDACTED_VALUE}` : match,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function safeDecode(value: string): string {
|
|
137
|
+
try {
|
|
138
|
+
return decodeURIComponent(value);
|
|
139
|
+
} catch {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function redactValue(value: unknown, underSecretKey: boolean, extra: Set<string>, key: string): unknown {
|
|
145
|
+
if (value === null || value === undefined) {
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Primitives
|
|
150
|
+
if (typeof value !== 'object') {
|
|
151
|
+
if (underSecretKey) {
|
|
152
|
+
return typeof value === 'boolean' ? value : REDACTED_VALUE;
|
|
153
|
+
}
|
|
154
|
+
if (typeof value !== 'string') {
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
return URL_KEY_PATTERN.test(key) ? redactUrl(value) : redactString(value);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Non-plain objects (Date, Buffer) are kept as they are — cloning would lose their type, and they carry no framework
|
|
161
|
+
// secret — unless they sit below a secret key
|
|
162
|
+
if (value instanceof Date || Buffer.isBuffer(value)) {
|
|
163
|
+
return underSecretKey ? REDACTED_VALUE : value;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (Array.isArray(value)) {
|
|
167
|
+
return value.map((item) => redactValue(item, underSecretKey, extra, key));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const out: Record<string, unknown> = {};
|
|
171
|
+
for (const [childKey, item] of Object.entries(value as Record<string, unknown>)) {
|
|
172
|
+
out[childKey] = redactValue(item, underSecretKey || isSecretKey(childKey, extra), extra, childKey);
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
@@ -22,6 +22,8 @@ import { CoreBetterAuthService } from '../../modules/better-auth/core-better-aut
|
|
|
22
22
|
import { CoreHubActionsController } from '../../modules/hub/core-hub-actions.controller.js';
|
|
23
23
|
import { CoreHubController } from '../../modules/hub/core-hub.controller.js';
|
|
24
24
|
import { isHubEnabled, normalizeHubConfig } from '../../modules/hub/hub-config.helper.js';
|
|
25
|
+
import { CoreSystemSetupController } from '../../modules/system-setup/core-system-setup.controller.js';
|
|
26
|
+
import { resolveSystemSetupHttpInit } from '../../modules/system-setup/system-setup-http-init.helper.js';
|
|
25
27
|
import { SKIP_TENANT_CHECK_KEY } from '../../modules/tenant/core-tenant.decorators.js';
|
|
26
28
|
import { API_METHODS_KEY } from '../decorators/api-methods.decorator.js';
|
|
27
29
|
import { mergeRolesMetadata } from '../../modules/tenant/core-tenant.helpers.js';
|
|
@@ -419,6 +421,11 @@ function isSwitchedOffOperation(reference: IHandlerReference, method: string, av
|
|
|
419
421
|
) {
|
|
420
422
|
return !HUB_AVAILABILITY[handlerName](availability, availability.hub);
|
|
421
423
|
}
|
|
424
|
+
// The anonymous init answers LTNS_0053 to everybody where `systemSetup.httpInit` keeps it closed (12.4.0+)
|
|
425
|
+
if (extendsClass(controller, CoreSystemSetupController) && handlerName === 'createInitialAdmin') {
|
|
426
|
+
const { env, systemSetup } = availability.config;
|
|
427
|
+
return !resolveSystemSetupHttpInit(systemSetup?.httpInit, env ?? process.env.NODE_ENV).enabled;
|
|
428
|
+
}
|
|
422
429
|
return false;
|
|
423
430
|
}
|
|
424
431
|
|
|
@@ -2603,6 +2603,26 @@ export interface IServerOptions {
|
|
|
2603
2603
|
*/
|
|
2604
2604
|
compression?: boolean | compression.CompressionOptions;
|
|
2605
2605
|
|
|
2606
|
+
/**
|
|
2607
|
+
* Whether a project's `GET /config` may answer (12.5.0+). The route lives in project code (the starter's
|
|
2608
|
+
* `ServerController`) and asks `configEndpointResponse()`, which decides with `isConfigEndpointEnabled()`.
|
|
2609
|
+
*
|
|
2610
|
+
* | Value | `local` / `ci` / `e2e` | every other environment (`develop`, `test`, `production`, …) |
|
|
2611
|
+
* |-------|------------------------|---------------------------------------------------------------|
|
|
2612
|
+
* | not set | answers | **404** |
|
|
2613
|
+
* | `true` | answers | answers |
|
|
2614
|
+
* | `false` | 404 | 404 |
|
|
2615
|
+
*
|
|
2616
|
+
* The answer is ALWAYS the redacted configuration (`ConfigService.getRedactedConfig()`): before 12.5.0 the
|
|
2617
|
+
* starter's endpoint returned the database URI, the auth secrets and the mail password to every administrator,
|
|
2618
|
+
* and a project created before the starter redacted kept doing so. A value that is not a boolean counts as not
|
|
2619
|
+
* set. Environment variable: `NSC__CONFIG_ENDPOINT=true`.
|
|
2620
|
+
*
|
|
2621
|
+
* @default undefined (answers only in `local`, `ci` and `e2e`)
|
|
2622
|
+
* @since 12.5.0
|
|
2623
|
+
*/
|
|
2624
|
+
configEndpoint?: boolean;
|
|
2625
|
+
|
|
2606
2626
|
/**
|
|
2607
2627
|
* Cookie configuration for authentication handling.
|
|
2608
2628
|
*
|
|
@@ -3611,7 +3631,10 @@ export interface IServerOptions {
|
|
|
3611
3631
|
*
|
|
3612
3632
|
* Auto-creation via config/ENV (no REST call needed):
|
|
3613
3633
|
* - `{ initialAdmin: { email: '...', password: '...' } }`
|
|
3614
|
-
* - `
|
|
3634
|
+
* - `NSC__SYSTEM_SETUP__INITIAL_ADMIN__EMAIL` + `NSC__SYSTEM_SETUP__INITIAL_ADMIN__PASSWORD`
|
|
3635
|
+
*
|
|
3636
|
+
* The anonymous `POST /system-setup/init` is open only in `local`, `ci` and `e2e` unless `httpInit` opens it
|
|
3637
|
+
* (12.4.0+, see {@link ISystemSetup.httpInit}).
|
|
3615
3638
|
*
|
|
3616
3639
|
* @since 11.14.0
|
|
3617
3640
|
*
|
|
@@ -4048,23 +4071,74 @@ export interface ISystemSetup {
|
|
|
4048
4071
|
*/
|
|
4049
4072
|
enabled?: boolean;
|
|
4050
4073
|
|
|
4074
|
+
/**
|
|
4075
|
+
* Whether the anonymous `POST /system-setup/init` may create the first administrator.
|
|
4076
|
+
*
|
|
4077
|
+
* Fail-closed outside the local environments: whoever reaches an API without users through that route becomes its
|
|
4078
|
+
* administrator, so a deployment provisions the first admin through {@link initialAdmin} and opens the HTTP route
|
|
4079
|
+
* only on purpose.
|
|
4080
|
+
*
|
|
4081
|
+
* | Value | `local` / `ci` / `e2e` | every other environment (`develop`, `test`, `production`, …) |
|
|
4082
|
+
* |-------|------------------------|---------------------------------------------------------------|
|
|
4083
|
+
* | not set | open | **closed** (403 `LTNS_0053`) |
|
|
4084
|
+
* | `true` | open | open, without a token |
|
|
4085
|
+
* | `{ token: '<at least 16 characters>' }` | open, token required | open, token required |
|
|
4086
|
+
* | `false` / `{ enabled: false, … }` | closed | closed |
|
|
4087
|
+
*
|
|
4088
|
+
* The token is sent in the `X-System-Setup-Token` header; a missing or wrong one answers 403 `LTNS_0054`. An object
|
|
4089
|
+
* whose token is missing, empty, shorter than 16 characters or not a string keeps the route CLOSED and logs an
|
|
4090
|
+
* error at boot — `{ token: process.env.SETUP_TOKEN }` with the variable unset must not open it. A value that is
|
|
4091
|
+
* neither a boolean nor an object (the string `'true'` from `NEST_SERVER_CONFIG`) counts as not set.
|
|
4092
|
+
*
|
|
4093
|
+
* Environment variables: `NSC__SYSTEM_SETUP__HTTP_INIT=true`, or `NSC__SYSTEM_SETUP__HTTP_INIT__TOKEN=<secret>` (a
|
|
4094
|
+
* token of digits only is converted to a number by the environment reader and refused; set one of the two, not
|
|
4095
|
+
* both).
|
|
4096
|
+
*
|
|
4097
|
+
* `GET /system-setup/status` reports the result as `httpInitEnabled` / `httpInitTokenRequired`.
|
|
4098
|
+
*
|
|
4099
|
+
* @default undefined (open only in `local`, `ci` and `e2e`)
|
|
4100
|
+
* @since 12.4.0
|
|
4101
|
+
*/
|
|
4102
|
+
httpInit?: boolean | ISystemSetupHttpInit;
|
|
4103
|
+
|
|
4051
4104
|
/**
|
|
4052
4105
|
* Pre-configured initial admin credentials for automatic creation on server start.
|
|
4053
4106
|
*
|
|
4054
4107
|
* When set, the service will automatically create the initial admin user
|
|
4055
4108
|
* during application bootstrap if zero users exist. This is useful for
|
|
4056
4109
|
* automated deployments (Docker, CI/CD) where no manual REST call is possible.
|
|
4110
|
+
* It is not affected by {@link httpInit}.
|
|
4057
4111
|
*
|
|
4058
|
-
* Can be provided via environment variables
|
|
4059
|
-
*
|
|
4060
|
-
* - `
|
|
4061
|
-
* - `
|
|
4112
|
+
* Can be provided via environment variables (SCREAMING_SNAKE segments — a camelCase segment such as
|
|
4113
|
+
* `NSC__systemSetup__…` is NOT read, the boot warns about it):
|
|
4114
|
+
* - `NSC__SYSTEM_SETUP__INITIAL_ADMIN__EMAIL`
|
|
4115
|
+
* - `NSC__SYSTEM_SETUP__INITIAL_ADMIN__PASSWORD`
|
|
4116
|
+
* - `NSC__SYSTEM_SETUP__INITIAL_ADMIN__NAME` (optional)
|
|
4062
4117
|
*
|
|
4063
4118
|
* Security: Same zero-user guard applies - only works when no users exist.
|
|
4064
4119
|
*/
|
|
4065
4120
|
initialAdmin?: ISystemSetupInitialAdmin;
|
|
4066
4121
|
}
|
|
4067
4122
|
|
|
4123
|
+
/**
|
|
4124
|
+
* Object form of {@link ISystemSetup.httpInit}: the HTTP init, protected by a setup token
|
|
4125
|
+
*
|
|
4126
|
+
* @since 12.4.0
|
|
4127
|
+
*/
|
|
4128
|
+
export interface ISystemSetupHttpInit {
|
|
4129
|
+
/**
|
|
4130
|
+
* `false` keeps the HTTP init closed while the token stays configured
|
|
4131
|
+
* @default true
|
|
4132
|
+
*/
|
|
4133
|
+
enabled?: boolean;
|
|
4134
|
+
|
|
4135
|
+
/**
|
|
4136
|
+
* The secret `POST /system-setup/init` must carry in the `X-System-Setup-Token` header. At least 16 characters;
|
|
4137
|
+
* a missing, shorter or non-string value keeps the HTTP init closed.
|
|
4138
|
+
*/
|
|
4139
|
+
token?: string;
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4068
4142
|
/**
|
|
4069
4143
|
* System setup configuration interface
|
|
4070
4144
|
*
|
|
@@ -7,6 +7,7 @@ import { merge } from '../helpers/config.helper.js';
|
|
|
7
7
|
// restricted.decorator, which reaches back here via core-tenant.helpers — that cycle is what the
|
|
8
8
|
// extraction removed. See clone.helper's docblock.
|
|
9
9
|
import { clone, deepFreeze } from '../helpers/clone.helper.js';
|
|
10
|
+
import { FRAMEWORK_SECRET_FIELDS, redactSecrets } from '../helpers/redact-secrets.helper.js';
|
|
10
11
|
import { IServerOptions } from '../interfaces/server-options.interface.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -65,6 +66,7 @@ export class ConfigService {
|
|
|
65
66
|
* aid, and an opt-in since 12.0.0 like it always was for `setConfig()` / `mergeConfig()`. As the default it
|
|
66
67
|
* wrote every secret in the config (JWT and Better-Auth secrets, database and Redis URIs, API keys) to
|
|
67
68
|
* stdout whenever `CoreModule.forRoot()` ran a second time in one process: tests, scripts, a second app.
|
|
69
|
+
* Since 12.5.0 the printed configuration is redacted (`redactSecrets()`).
|
|
68
70
|
*/
|
|
69
71
|
constructor(
|
|
70
72
|
configObject?: Partial<IServerOptions> & { [key: string]: any },
|
|
@@ -140,6 +142,40 @@ export class ConfigService {
|
|
|
140
142
|
return ConfigService._frozenConfigSubject$.getValue();
|
|
141
143
|
}
|
|
142
144
|
|
|
145
|
+
/**
|
|
146
|
+
* The configuration with every secret masked — the view to show anybody, an administrator included
|
|
147
|
+
* (`GET /config` via `configEndpointResponse()`, the Hub config panel).
|
|
148
|
+
*
|
|
149
|
+
* A deep copy, masked by {@link redactSecrets}: key patterns, credentials in connection URIs, nested values,
|
|
150
|
+
* plus the framework's secret fields and the project's `security.secretFields`. The live configuration is never
|
|
151
|
+
* touched.
|
|
152
|
+
*
|
|
153
|
+
* @since 12.5.0
|
|
154
|
+
*/
|
|
155
|
+
getRedactedConfig(): Record<string, unknown> {
|
|
156
|
+
return ConfigService.getRedactedConfig();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The configuration with every secret masked (see the instance method)
|
|
161
|
+
*
|
|
162
|
+
* @since 12.5.0
|
|
163
|
+
*/
|
|
164
|
+
static getRedactedConfig(): Record<string, unknown> {
|
|
165
|
+
return ConfigService.redact(ConfigService.configFastButReadOnly ?? {});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Mask a configuration object with the framework's rules and the project's `security.secretFields`
|
|
170
|
+
*/
|
|
171
|
+
protected static redact(config: Record<string, any>): Record<string, unknown> {
|
|
172
|
+
const projectSecretFields = config?.security?.secretFields;
|
|
173
|
+
return redactSecrets(config, [
|
|
174
|
+
...FRAMEWORK_SECRET_FIELDS,
|
|
175
|
+
...(Array.isArray(projectSecretFields) ? projectSecretFields : []),
|
|
176
|
+
]) as Record<string, unknown>;
|
|
177
|
+
}
|
|
178
|
+
|
|
143
179
|
/**
|
|
144
180
|
* Get readable and writable deep-cloned property from configuration
|
|
145
181
|
*/
|
|
@@ -280,7 +316,8 @@ export class ConfigService {
|
|
|
280
316
|
|
|
281
317
|
// Warn if requested
|
|
282
318
|
if (config.warn) {
|
|
283
|
-
|
|
319
|
+
// Redacted: this goes to stdout, and the merged configuration holds every secret of the deployment
|
|
320
|
+
console.warn(`ConfigService ${activity}`, JSON.stringify(ConfigService.redact(merged), null, 2));
|
|
284
321
|
}
|
|
285
322
|
|
|
286
323
|
// Return configuration
|
|
@@ -291,7 +328,7 @@ export class ConfigService {
|
|
|
291
328
|
* Merge config property and set in ConfigService
|
|
292
329
|
*/
|
|
293
330
|
mergeProperty(key: string, value: any, options?: { warn?: boolean }) {
|
|
294
|
-
return ConfigService.mergeProperty(key, options);
|
|
331
|
+
return ConfigService.mergeProperty(key, value, options);
|
|
295
332
|
}
|
|
296
333
|
|
|
297
334
|
/**
|
|
@@ -372,7 +409,8 @@ export class ConfigService {
|
|
|
372
409
|
|
|
373
410
|
// Warn if requested
|
|
374
411
|
if (config.warn && !firstInitialization) {
|
|
375
|
-
|
|
412
|
+
// Redacted: this goes to stdout, and the configuration holds every secret of the deployment
|
|
413
|
+
console.warn('ConfigService reinitialized', JSON.stringify(ConfigService.redact(configObject || {}), null, 2));
|
|
376
414
|
}
|
|
377
415
|
}
|
|
378
416
|
|
|
@@ -637,6 +637,33 @@ export const LtnsErrors = {
|
|
|
637
637
|
},
|
|
638
638
|
},
|
|
639
639
|
|
|
640
|
+
/**
|
|
641
|
+
* `POST /system-setup/init` is closed in this environment (12.4.0+): by default it is open only in `local`, `ci`
|
|
642
|
+
* and `e2e`. A deployment provisions its first admin through `systemSetup.initialAdmin`, or opens the HTTP init
|
|
643
|
+
* explicitly with `systemSetup.httpInit`.
|
|
644
|
+
*/
|
|
645
|
+
SYSTEM_SETUP_HTTP_INIT_DISABLED: {
|
|
646
|
+
code: 'LTNS_0053',
|
|
647
|
+
message: 'Initial admin setup over HTTP is not enabled in this environment',
|
|
648
|
+
translations: {
|
|
649
|
+
de: 'Die Ersteinrichtung über die Oberfläche ist in dieser Umgebung nicht freigegeben.',
|
|
650
|
+
en: 'Initial admin setup over HTTP is not enabled in this environment.',
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* `POST /system-setup/init` requires the setup token (`systemSetup.httpInit.token`) in the `X-System-Setup-Token`
|
|
656
|
+
* header, and the request sent none or a different one (12.4.0+).
|
|
657
|
+
*/
|
|
658
|
+
SYSTEM_SETUP_TOKEN_INVALID: {
|
|
659
|
+
code: 'LTNS_0054',
|
|
660
|
+
message: 'Missing or invalid system setup token',
|
|
661
|
+
translations: {
|
|
662
|
+
de: 'Der Einrichtungs-Token fehlt oder ist falsch.',
|
|
663
|
+
en: 'The system setup token is missing or invalid.',
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
|
|
640
667
|
// =====================================================
|
|
641
668
|
// AI Errors (LTNS_0600-LTNS_0699)
|
|
642
669
|
// =====================================================
|
|
@@ -123,7 +123,9 @@ Every action writes an audit line: `[HUB-ACTION] <action> by user <id>`.
|
|
|
123
123
|
The messages are centralized in `hub-action-messages.ts` (`HubActionMessage`) so the wording stays
|
|
124
124
|
consistent and reviewable in one place.
|
|
125
125
|
- **CSP**: strict per-request nonce; no `unsafe-inline`; `X-Frame-Options: DENY`; `no-store`.
|
|
126
|
-
- **Secrets**: the config viewer deep-clones and masks by key pattern + `security.secretFields
|
|
126
|
+
- **Secrets**: the config viewer deep-clones and masks by key pattern + `security.secretFields` — since 12.5.0
|
|
127
|
+
through the framework-wide `redactSecrets()` / `ConfigService.getRedactedConfig()`, the same view `GET /config`
|
|
128
|
+
serves (`configEndpointResponse()`).
|
|
127
129
|
- **Interceptor safety**: sidecars return pre-serialized JSON strings, so the global response
|
|
128
130
|
interceptors never walk/mutate live config.
|
|
129
131
|
- **Mailbox guard**: `mode: 'capture'` throws at startup in any **reachable** environment (anything
|
|
@@ -7,25 +7,10 @@ import { ConfigService } from '../../common/services/config.service.js';
|
|
|
7
7
|
|
|
8
8
|
import { HUB_CONFIG } from './hub.constants.js';
|
|
9
9
|
import { HUB_PANEL_GROUPS, HUB_PANELS } from './hub-nav.js';
|
|
10
|
-
import { maskConfigDeep } from './helpers/hub-mask.helper.js';
|
|
11
10
|
import { CoreHubSourcesService } from './services/core-hub-sources.service.js';
|
|
12
11
|
import { HubDashboardData, HubDiagnosticsData, HubSessionData } from './interfaces/hub-panels.interface.js';
|
|
13
12
|
import type { ResolvedHubConfig } from './interfaces/hub-config.interface.js';
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
* Framework-default secret field names (see CheckSecurityInterceptor). Union with the pattern-based
|
|
17
|
-
* masking in {@link maskConfigDeep} and the project's `security.secretFields`.
|
|
18
|
-
*/
|
|
19
|
-
const FRAMEWORK_SECRET_FIELDS = [
|
|
20
|
-
'password',
|
|
21
|
-
'verificationToken',
|
|
22
|
-
'passwordResetToken',
|
|
23
|
-
'passwordResetTokenExpiresAt',
|
|
24
|
-
'refreshTokens',
|
|
25
|
-
'tempTokens',
|
|
26
|
-
'apiKeyEncrypted',
|
|
27
|
-
];
|
|
28
|
-
|
|
29
14
|
const MONGO_STATES: Record<number, string> = {
|
|
30
15
|
0: 'disconnected',
|
|
31
16
|
1: 'connected',
|
|
@@ -92,13 +77,12 @@ export class CoreHubService {
|
|
|
92
77
|
}
|
|
93
78
|
|
|
94
79
|
/**
|
|
95
|
-
* The full server config with all secrets masked
|
|
96
|
-
* then masked by key heuristics + the framework/project
|
|
80
|
+
* The full server config with all secrets masked — the same view `GET /config` serves
|
|
81
|
+
* (`ConfigService.getRedactedConfig()`): deep-cloned first, then masked by key heuristics + the framework/project
|
|
82
|
+
* secret-field lists.
|
|
97
83
|
*/
|
|
98
84
|
getConfigMasked(): Record<string, unknown> {
|
|
99
|
-
|
|
100
|
-
const projectSecretFields = this.configService.get<string[]>('security.secretFields', []) ?? [];
|
|
101
|
-
return maskConfigDeep(raw, [...FRAMEWORK_SECRET_FIELDS, ...projectSecretFields]);
|
|
85
|
+
return this.configService.getRedactedConfig();
|
|
102
86
|
}
|
|
103
87
|
|
|
104
88
|
/** The resolved Hub config (for controller/actions/gating decisions). */
|
|
@@ -1,95 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The Hub config viewer's masker — since 12.5.0 the framework-wide `redactSecrets()`
|
|
3
|
+
* (`common/helpers/redact-secrets.helper.ts`), which `GET /config` and the `ConfigService` debug output use too.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* service-owned object to the response pipeline — `CheckSecurityInterceptor` deletes secret-named
|
|
6
|
-
* keys IN PLACE, which would corrupt the running server config. Cloning here is the guarantee.
|
|
5
|
+
* Kept under its old name so no import path broke.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Key-name heuristics that mark a value as secret. Matched case-insensitively against each key.
|
|
11
|
-
*
|
|
12
|
-
* `access[-_]?key` also covers `accessKeyId`: the trailing `(^|[^a-z])key([^a-z]|$)` alternative
|
|
13
|
-
* does NOT, because the `i` flag makes `[^a-z]` reject an uppercase letter, so `…sKeyI…` fails it.
|
|
14
|
-
* `s3.secretAccessKey` was already caught by `secret`; the ID was not.
|
|
15
|
-
*/
|
|
16
|
-
const SECRET_KEY_PATTERN =
|
|
17
|
-
/secret|passwd|password|passphrase|credential|api[-_]?key|access[-_]?key|access[-_]?token|refresh[-_]?token|private[-_]?key|encryption|\btoken\b|\bpass\b|(^|[^a-z])key([^a-z]|$)/i;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Value-shape heuristic: a connection URI carrying `scheme://user:password@host`.
|
|
21
|
-
*
|
|
22
|
-
* The user part is `*`, not `+`, so the PASSWORD-ONLY form is matched too:
|
|
23
|
-
* `redis://:password@host` is the canonical Redis URL (Redis < 6 has no username, and
|
|
24
|
-
* `redis-cli -u`, Heroku Redis and ElastiCache AUTH all emit it). Requiring a non-empty
|
|
25
|
-
* user printed that shape verbatim in the Hub config panel. `redis.url` became a
|
|
26
|
-
* first-class option in 11.33.0, so the shape is newly reachable here.
|
|
27
|
-
*
|
|
28
|
-
* Still safe against false positives: the password group cannot contain `/`, and the `@`
|
|
29
|
-
* must follow it immediately — so `http://host:8080/x@y` does not match.
|
|
30
|
-
*/
|
|
31
|
-
const URI_CREDENTIAL_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/[^/@:\s]*:)([^@/\s]+)(@)/i;
|
|
32
|
-
|
|
33
|
-
const MASK = '***';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Deep-clone `value` and mask every secret it contains.
|
|
37
|
-
*
|
|
38
|
-
* A value is masked when its key matches {@link SECRET_KEY_PATTERN} or appears in `extraSecretKeys`.
|
|
39
|
-
* Additionally, any string that looks like a credentialed connection URI has its password segment
|
|
40
|
-
* masked regardless of key name.
|
|
41
|
-
*
|
|
42
|
-
* @param value - the object/value to mask (not mutated)
|
|
43
|
-
* @param extraSecretKeys - additional exact key names to always mask (e.g. `security.secretFields`)
|
|
44
|
-
*/
|
|
45
|
-
export function maskConfigDeep<T>(value: T, extraSecretKeys: string[] = []): T {
|
|
46
|
-
const extra = new Set(extraSecretKeys.map((k) => k.toLowerCase()));
|
|
47
|
-
return maskValue(value, false, extra) as T;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function isSecretKey(key: string, extra: Set<string>): boolean {
|
|
51
|
-
return extra.has(key.toLowerCase()) || SECRET_KEY_PATTERN.test(key);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function maskString(value: string): string {
|
|
55
|
-
const uriMatch = value.match(URI_CREDENTIAL_PATTERN);
|
|
56
|
-
if (uriMatch) {
|
|
57
|
-
return value.replace(URI_CREDENTIAL_PATTERN, `$1${MASK}$3`);
|
|
58
|
-
}
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function maskValue(value: unknown, keyIsSecret: boolean, extra: Set<string>): unknown {
|
|
63
|
-
if (value === null || value === undefined) {
|
|
64
|
-
return value;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Primitives.
|
|
68
|
-
if (typeof value !== 'object') {
|
|
69
|
-
if (keyIsSecret) {
|
|
70
|
-
return MASK;
|
|
71
|
-
}
|
|
72
|
-
return typeof value === 'string' ? maskString(value) : value;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// A whole secret-keyed object/array is collapsed to the mask (never leak its interior).
|
|
76
|
-
if (keyIsSecret) {
|
|
77
|
-
return MASK;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Preserve non-plain objects verbatim (Date, Buffer, etc.) — cloning would lose their type and
|
|
81
|
-
// they never carry framework secrets.
|
|
82
|
-
if (value instanceof Date || Buffer.isBuffer(value)) {
|
|
83
|
-
return value;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (Array.isArray(value)) {
|
|
87
|
-
return value.map((item) => maskValue(item, false, extra));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const out: Record<string, unknown> = {};
|
|
91
|
-
for (const [key, val] of Object.entries(value as Record<string, unknown>)) {
|
|
92
|
-
out[key] = maskValue(val, isSecretKey(key, extra), extra);
|
|
93
|
-
}
|
|
94
|
-
return out;
|
|
95
|
-
}
|
|
7
|
+
export { redactSecrets as maskConfigDeep } from '../../../common/helpers/redact-secrets.helper.js';
|