@lenne.tech/nest-server 12.4.0 → 12.6.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 +5 -4
- package/CLAUDE.md +4 -0
- 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/interfaces/server-options.interface.d.ts +1 -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/common/services/rate-limit-store.d.ts +1 -0
- package/dist/core/common/services/rate-limit-store.js +3 -3
- package/dist/core/common/services/rate-limit-store.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-api.middleware.d.ts +1 -0
- package/dist/core/modules/better-auth/core-better-auth-api.middleware.js +23 -0
- package/dist/core/modules/better-auth/core-better-auth-api.middleware.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.d.ts +31 -1
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js +96 -14
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-openapi.helper.js +8 -1
- package/dist/core/modules/better-auth/core-better-auth-openapi.helper.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-verification-link.helper.d.ts +3 -0
- package/dist/core/modules/better-auth/core-better-auth-verification-link.helper.js +29 -0
- package/dist/core/modules/better-auth/core-better-auth-verification-link.helper.js.map +1 -0
- package/dist/core/modules/better-auth/core-better-auth.controller.d.ts +8 -0
- package/dist/core/modules/better-auth/core-better-auth.controller.js +51 -0
- package/dist/core/modules/better-auth/core-better-auth.controller.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.module.d.ts +1 -0
- package/dist/core/modules/better-auth/core-better-auth.module.js +10 -1
- package/dist/core/modules/better-auth/core-better-auth.module.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.service.d.ts +59 -2
- package/dist/core/modules/system-setup/core-system-setup.service.js +157 -28
- package/dist/core/modules/system-setup/core-system-setup.service.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- 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/12.4.x-to-12.5.x.md +136 -0
- package/migration-guides/12.5.x-to-12.6.x.md +213 -0
- package/package.json +5 -4
- 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/interfaces/server-options.interface.ts +26 -5
- package/src/core/common/services/config.service.ts +41 -3
- package/src/core/common/services/rate-limit-store.ts +9 -3
- package/src/core/modules/better-auth/README.md +27 -0
- package/src/core/modules/better-auth/core-better-auth-api.middleware.ts +33 -0
- package/src/core/modules/better-auth/core-better-auth-email-verification.service.ts +218 -35
- package/src/core/modules/better-auth/core-better-auth-openapi.helper.ts +8 -1
- package/src/core/modules/better-auth/core-better-auth-verification-link.helper.ts +53 -0
- package/src/core/modules/better-auth/core-better-auth.controller.ts +61 -0
- package/src/core/modules/better-auth/core-better-auth.module.ts +18 -2
- 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/README.md +20 -4
- package/src/core/modules/system-setup/core-system-setup.service.ts +290 -45
- package/src/index.ts +2 -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
|
+
}
|
|
@@ -551,11 +551,12 @@ export interface IBetterAuthEmailVerificationConfig {
|
|
|
551
551
|
* When not set, the verification link points directly to the backend
|
|
552
552
|
* endpoint which handles verification and redirects.
|
|
553
553
|
*
|
|
554
|
-
* Since
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
554
|
+
* Since 12.6.0 the link carries the token only, and sealed — `{callbackURL}?token=<sealed>`: no `email`
|
|
555
|
+
* parameter, and the token is encrypted, because Better-Auth's own token is a readable JWT with the
|
|
556
|
+
* address in it. Pass the token on unchanged: `GET /iam/verify-email?token=…` opens it, and for an expired
|
|
557
|
+
* link `POST /iam/resend-verification-email` with `{ token }` sends a new mail and answers the address
|
|
558
|
+
* masked (`GET /iam/features` → `resendVerificationByToken`). From 11.38.0 to 12.5.x the link carried
|
|
559
|
+
* `&email=<address>`.
|
|
559
560
|
*
|
|
560
561
|
* @default undefined (backend-handled verification)
|
|
561
562
|
* @since 11.13.0
|
|
@@ -2603,6 +2604,26 @@ export interface IServerOptions {
|
|
|
2603
2604
|
*/
|
|
2604
2605
|
compression?: boolean | compression.CompressionOptions;
|
|
2605
2606
|
|
|
2607
|
+
/**
|
|
2608
|
+
* Whether a project's `GET /config` may answer (12.5.0+). The route lives in project code (the starter's
|
|
2609
|
+
* `ServerController`) and asks `configEndpointResponse()`, which decides with `isConfigEndpointEnabled()`.
|
|
2610
|
+
*
|
|
2611
|
+
* | Value | `local` / `ci` / `e2e` | every other environment (`develop`, `test`, `production`, …) |
|
|
2612
|
+
* |-------|------------------------|---------------------------------------------------------------|
|
|
2613
|
+
* | not set | answers | **404** |
|
|
2614
|
+
* | `true` | answers | answers |
|
|
2615
|
+
* | `false` | 404 | 404 |
|
|
2616
|
+
*
|
|
2617
|
+
* The answer is ALWAYS the redacted configuration (`ConfigService.getRedactedConfig()`): before 12.5.0 the
|
|
2618
|
+
* starter's endpoint returned the database URI, the auth secrets and the mail password to every administrator,
|
|
2619
|
+
* and a project created before the starter redacted kept doing so. A value that is not a boolean counts as not
|
|
2620
|
+
* set. Environment variable: `NSC__CONFIG_ENDPOINT=true`.
|
|
2621
|
+
*
|
|
2622
|
+
* @default undefined (answers only in `local`, `ci` and `e2e`)
|
|
2623
|
+
* @since 12.5.0
|
|
2624
|
+
*/
|
|
2625
|
+
configEndpoint?: boolean;
|
|
2626
|
+
|
|
2606
2627
|
/**
|
|
2607
2628
|
* Cookie configuration for authentication handling.
|
|
2608
2629
|
*
|
|
@@ -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
|
|
|
@@ -59,6 +59,12 @@ export interface RateLimitStoreHit {
|
|
|
59
59
|
count: number;
|
|
60
60
|
/** Seconds until the window resets */
|
|
61
61
|
resetIn: number;
|
|
62
|
+
/**
|
|
63
|
+
* `true` when the key did not fit into the store and {@link count} is that of a shared overflow bucket — i.e. it
|
|
64
|
+
* counts other clients too. A caller for whom refusing a stranger's share is worse than not counting may let such a
|
|
65
|
+
* hit through; most limiters must not, or filling the keyspace would switch them off.
|
|
66
|
+
*/
|
|
67
|
+
overflow?: boolean;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
/**
|
|
@@ -198,11 +204,11 @@ export class InMemoryRateLimitStore implements RateLimitStore {
|
|
|
198
204
|
|
|
199
205
|
if (!entry || now >= entry.resetTime) {
|
|
200
206
|
this.overflow.set(slot, { count: 1, resetTime: now + windowSeconds * 1000 });
|
|
201
|
-
return { count: 1, resetIn: windowSeconds };
|
|
207
|
+
return { count: 1, overflow: true, resetIn: windowSeconds };
|
|
202
208
|
}
|
|
203
209
|
|
|
204
210
|
entry.count++;
|
|
205
|
-
return { count: entry.count, resetIn: Math.ceil((entry.resetTime - now) / 1000) };
|
|
211
|
+
return { count: entry.count, overflow: true, resetIn: Math.ceil((entry.resetTime - now) / 1000) };
|
|
206
212
|
}
|
|
207
213
|
|
|
208
214
|
size(): number {
|
|
@@ -382,7 +388,7 @@ export class RedisRateLimitStore implements RateLimitStore {
|
|
|
382
388
|
'over, so they may be limited earlier than their own traffic warrants. Existing limits are unaffected.',
|
|
383
389
|
);
|
|
384
390
|
}
|
|
385
|
-
return { count, resetIn: ttl };
|
|
391
|
+
return overflow ? { count, overflow: true, resetIn: ttl } : { count, resetIn: ttl };
|
|
386
392
|
},
|
|
387
393
|
() => this.fallback.hit(key, windowSeconds),
|
|
388
394
|
);
|
|
@@ -557,6 +557,33 @@ in to their account, and what the recipient enters there lands with them (login
|
|
|
557
557
|
signs in once, as in Better-Auth's own default. Switch it on (`emailVerification: { autoSignInAfterVerification: true }`)
|
|
558
558
|
only where a verification link reaches nobody but its owner.
|
|
559
559
|
|
|
560
|
+
**The link carries the token only, sealed, and an expired link is recovered with it (12.6.0).** The verification link
|
|
561
|
+
ends in `?token=…`. Until then it also carried the address (`&email=`), so the page could offer "send a new email", and
|
|
562
|
+
the address stood in the mail, the browser history and the access logs. Better-Auth's own token is a signed but
|
|
563
|
+
readable JWT with the address and the user id in it, so the link carries it encrypted (compact JWE, key derived from
|
|
564
|
+
Better-Auth's secret, `core-better-auth-verification-link.helper.ts`): the API middleware opens it for
|
|
565
|
+
`GET /iam/verify-email`, and Better-Auth verifies the token it signed. A plain token from a mail sent before the update
|
|
566
|
+
still works. A page passes the token on unchanged, and for an expired link sends it to
|
|
567
|
+
`POST /iam/resend-verification-email` (`{ "token": "…" }`):
|
|
568
|
+
|
|
569
|
+
- the server checks Better-Auth's signature (an expired token is fine, a forged one sends nothing) and has
|
|
570
|
+
Better-Auth's own `sendVerificationEmail` send a new mail to the address in the token, which goes out only to an
|
|
571
|
+
existing, unverified account; the resend cooldown applies on top, and the token of an address change sends nothing;
|
|
572
|
+
- the answer is always `200 { "email": "k***@example.com", "success": true }` — the masked address of the token, or
|
|
573
|
+
`null` for an invalid token — whether the account exists, is verified, or a mail went out;
|
|
574
|
+
- it never verifies, signs in or creates a session;
|
|
575
|
+
- 3 requests an hour with valid links for one address (sealed or plain, older or newer, they count together), and 10
|
|
576
|
+
invalid tokens per client address an hour; past either `429 LTNS_0020`. The token is checked first: an invalid one
|
|
577
|
+
is counted only per client address, a valid one only per address it names, each in a counter store of its own. Junk
|
|
578
|
+
therefore never reaches the counters of real tokens, and behind a proxy without `trustProxy`, where every client
|
|
579
|
+
shares the proxy's address, it can only lock out more junk. Once the store of valid-token counters is full (someone
|
|
580
|
+
signed up thousands of addresses and replays their links), a valid token is answered rather than refused for
|
|
581
|
+
traffic that is not its own; the per-address cooldown of the verification mail still bounds what goes out. Shared
|
|
582
|
+
across replicas through Redis when `redis` is configured.
|
|
583
|
+
|
|
584
|
+
`GET /iam/features` reports `resendVerificationByToken: true` while email verification is enabled, so a page can fall
|
|
585
|
+
back to asking for the address against an older server.
|
|
586
|
+
|
|
560
587
|
### Sign-Up Checks (v11.13.0+)
|
|
561
588
|
|
|
562
589
|
Sign-up validation is **enabled by default** requiring `termsAndPrivacyAccepted: true`.
|
|
@@ -11,6 +11,7 @@ import { runWithResetPassword } from './core-better-auth-password-reset.registry
|
|
|
11
11
|
import { CoreBetterAuthUserMapper } from './core-better-auth-user.mapper.js';
|
|
12
12
|
import { extractSessionToken, sendWebResponse, signCookieValue, toWebRequest } from './core-better-auth-web.helper.js';
|
|
13
13
|
import { CoreBetterAuthService } from './core-better-auth.service.js';
|
|
14
|
+
import { openVerificationToken } from './core-better-auth-verification-link.helper.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Native Better-Auth routes that set a NEW password from a token or OTP, with the body
|
|
@@ -355,6 +356,10 @@ export class CoreBetterAuthApiMiddleware implements NestMiddleware {
|
|
|
355
356
|
}
|
|
356
357
|
}
|
|
357
358
|
|
|
359
|
+
// The verification link carries Better-Auth's token sealed (it is a readable JWT with the address in it);
|
|
360
|
+
// Better-Auth verifies the token it signed, so open it before the request is built.
|
|
361
|
+
await this.openVerificationLinkToken(req, relativePath);
|
|
362
|
+
|
|
358
363
|
// Put a reset password into the shape sign-in expects BEFORE the body is
|
|
359
364
|
// serialized, and keep the value for the legacy mirror below.
|
|
360
365
|
const resetPassword = this.normalizeResetPassword(req, relativePath);
|
|
@@ -559,4 +564,32 @@ export class CoreBetterAuthApiMiddleware implements NestMiddleware {
|
|
|
559
564
|
}
|
|
560
565
|
}
|
|
561
566
|
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Replace the sealed token of a verification link (`GET /verify-email?token=…`) by the token Better-Auth signed, so
|
|
570
|
+
* Better-Auth verifies it unchanged (core-better-auth-verification-link.helper.ts). A plain token (a link mailed
|
|
571
|
+
* before the seal) and a value that does not open go on as they are: Better-Auth answers the latter like any
|
|
572
|
+
* invalid token.
|
|
573
|
+
*/
|
|
574
|
+
protected async openVerificationLinkToken(req: Request, relativePath: string): Promise<void> {
|
|
575
|
+
if (relativePath !== '/verify-email') {
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const sealed = new URL(req.originalUrl || req.url, 'http://local').searchParams.get('token');
|
|
579
|
+
if (!sealed) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const secret = (await this.betterAuthService.getInstance()?.$context)?.secret;
|
|
583
|
+
const opened = secret ? await openVerificationToken(secret, sealed) : undefined;
|
|
584
|
+
if (!opened || opened === sealed) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const withToken = (url: string): string => {
|
|
588
|
+
const parsed = new URL(url, 'http://local');
|
|
589
|
+
parsed.searchParams.set('token', opened);
|
|
590
|
+
return `${parsed.pathname}${parsed.search}`;
|
|
591
|
+
};
|
|
592
|
+
req.originalUrl = withToken(req.originalUrl || req.url);
|
|
593
|
+
req.url = withToken(req.url);
|
|
594
|
+
}
|
|
562
595
|
}
|