@bymax-one/nest-auth 1.4.2 → 1.4.4
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 +1840 -1
- package/README.md +706 -74
- package/dist/client/index.cjs +108 -35
- package/dist/client/index.d.cts +90 -15
- package/dist/client/index.d.ts +90 -15
- package/dist/client/index.mjs +109 -36
- package/dist/server/index.cjs +1832 -441
- package/dist/server/index.d.cts +1051 -136
- package/dist/server/index.d.ts +1051 -136
- package/dist/server/index.mjs +1828 -443
- package/dist/shared/index.cjs +103 -10
- package/dist/shared/index.d.cts +128 -5
- package/dist/shared/index.d.ts +128 -5
- package/dist/shared/index.mjs +100 -11
- package/package.json +12 -6
package/dist/server/index.d.cts
CHANGED
|
@@ -156,6 +156,89 @@ interface CreateWithOAuthData {
|
|
|
156
156
|
/** User's unique identifier within the OAuth provider's system. */
|
|
157
157
|
oauthProviderId: string;
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Names one account on the dashboard plane: the id, and the tenant it belongs to.
|
|
161
|
+
*
|
|
162
|
+
* The base every tenant-scoped port parameter extends. It exists because the two fields must
|
|
163
|
+
* travel together — an id without its tenant is not an account on this plane, since the library
|
|
164
|
+
* may not assume ids are unique across tenants.
|
|
165
|
+
*
|
|
166
|
+
* **Why an object and not two positional strings.** A positional pair cannot make a stale
|
|
167
|
+
* implementation fail. TypeScript's structural typing accepts an implementation with FEWER
|
|
168
|
+
* parameters, so a consumer's pre-upgrade `findById(id)` satisfied a `findById(id, tenantId)`
|
|
169
|
+
* signature and silently ignored the tenant — the scoping this port exists to require simply did
|
|
170
|
+
* not bind, on a clean build. Worse on the writes: the library called
|
|
171
|
+
* `updatePassword(id, tenantId, hash)` and a stale two-parameter implementation bound
|
|
172
|
+
* `passwordHash = tenantId`, writing the tenant id into the credential column.
|
|
173
|
+
*
|
|
174
|
+
* An object parameter is structurally INCOMPATIBLE with the old shape, so the same implementation
|
|
175
|
+
* now fails to compile. That property is the whole reason for the shape; `tenant-scoped-port`
|
|
176
|
+
* pins it with a type test, because it is invisible in the signature itself.
|
|
177
|
+
*
|
|
178
|
+
* One residual hole, stated rather than hidden, and stated narrowly: TypeScript always accepts an
|
|
179
|
+
* implementation taking NO parameters. What the object shape buys is only that a value cannot be
|
|
180
|
+
* bound into the wrong positional slot — it says nothing about what the body then does. A
|
|
181
|
+
* zero-parameter implementation still compiles and can read or write whatever it likes, unscoped,
|
|
182
|
+
* exactly as a parameterised one that ignores its argument can.
|
|
183
|
+
*
|
|
184
|
+
* This shape closes a defect the compiler can see. Whether an implementation actually filters on
|
|
185
|
+
* the tenant is a claim only that implementation can honour, and this port states it as a MUST on
|
|
186
|
+
* every method rather than pretending to enforce it.
|
|
187
|
+
*/
|
|
188
|
+
interface TenantScopedUserRef {
|
|
189
|
+
/** The user's unique identifier. */
|
|
190
|
+
id: string;
|
|
191
|
+
/** The tenant the account belongs to. Every read and write MUST be scoped to it. */
|
|
192
|
+
tenantId: string;
|
|
193
|
+
}
|
|
194
|
+
/** Locates one account by email inside a tenant. */
|
|
195
|
+
interface FindUserByEmailParams {
|
|
196
|
+
/** The user's email address (case-insensitive recommended). */
|
|
197
|
+
email: string;
|
|
198
|
+
/** Tenant scope. Prevents cross-tenant email collisions. */
|
|
199
|
+
tenantId: string;
|
|
200
|
+
}
|
|
201
|
+
/** Replaces one account's stored password hash. */
|
|
202
|
+
interface UpdatePasswordParams extends TenantScopedUserRef {
|
|
203
|
+
/** New hash generated by `PasswordService`. Never plaintext. */
|
|
204
|
+
passwordHash: string;
|
|
205
|
+
}
|
|
206
|
+
/** Rewrites one account's TOTP MFA configuration. */
|
|
207
|
+
interface UpdateMfaParams extends TenantScopedUserRef {
|
|
208
|
+
/** The MFA fields to write. See {@link UpdateMfaData}. */
|
|
209
|
+
data: UpdateMfaData;
|
|
210
|
+
}
|
|
211
|
+
/** Sets one account's authorization status. */
|
|
212
|
+
interface UpdateStatusParams extends TenantScopedUserRef {
|
|
213
|
+
/** New status value, in the host's own vocabulary. */
|
|
214
|
+
status: string;
|
|
215
|
+
}
|
|
216
|
+
/** Sets whether one account's address has been verified. */
|
|
217
|
+
interface UpdateEmailVerifiedParams extends TenantScopedUserRef {
|
|
218
|
+
/** Whether the address is now verified. */
|
|
219
|
+
verified: boolean;
|
|
220
|
+
}
|
|
221
|
+
/** Moves one account to a new address. */
|
|
222
|
+
interface UpdateEmailParams extends TenantScopedUserRef {
|
|
223
|
+
/** The new address, already normalized by the caller. */
|
|
224
|
+
email: string;
|
|
225
|
+
}
|
|
226
|
+
/** Locates one account by an external identity inside a tenant. */
|
|
227
|
+
interface FindUserByOAuthIdParams {
|
|
228
|
+
/** OAuth provider key (e.g. `'google'`). */
|
|
229
|
+
provider: string;
|
|
230
|
+
/** The provider's own subject identifier for the user. */
|
|
231
|
+
providerId: string;
|
|
232
|
+
/** Tenant scope. */
|
|
233
|
+
tenantId: string;
|
|
234
|
+
}
|
|
235
|
+
/** Attaches an external identity to an existing account. */
|
|
236
|
+
interface LinkOAuthParams extends TenantScopedUserRef {
|
|
237
|
+
/** OAuth provider key (e.g. `'google'`). */
|
|
238
|
+
provider: string;
|
|
239
|
+
/** The provider's own subject identifier for the user. */
|
|
240
|
+
providerId: string;
|
|
241
|
+
}
|
|
159
242
|
/**
|
|
160
243
|
* Repository contract for dashboard/tenant user persistence.
|
|
161
244
|
*
|
|
@@ -177,21 +260,25 @@ interface IUserRepository {
|
|
|
177
260
|
/**
|
|
178
261
|
* Finds a user by their internal unique identifier.
|
|
179
262
|
*
|
|
180
|
-
* @
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
263
|
+
* @remarks
|
|
264
|
+
* The tenant is REQUIRED, not an option the caller may skip. This library may not assume the
|
|
265
|
+
* consumer's ids are unique across tenants — a host that numbers users per tenant gives every
|
|
266
|
+
* tenant a user `1` — so a lookup by bare id can answer with another tenant's row. The optional
|
|
267
|
+
* form was worse than no scoping at all: it read as a decision the caller had made, while every
|
|
268
|
+
* one of this library's own twelve call sites omitted it, none of them a cross-tenant flow.
|
|
269
|
+
*
|
|
270
|
+
* A deployment that genuinely wants a cross-tenant read owns the repository and can write that
|
|
271
|
+
* query itself; it does not need this port to leave the door open for it.
|
|
272
|
+
*
|
|
184
273
|
* @returns The matching user record, or null if not found.
|
|
185
274
|
*/
|
|
186
|
-
findById(
|
|
275
|
+
findById(params: TenantScopedUserRef): Promise<AuthUser | null>;
|
|
187
276
|
/**
|
|
188
277
|
* Finds a user by email address within a specific tenant.
|
|
189
278
|
*
|
|
190
|
-
* @param email - The user's email address (case-insensitive recommended).
|
|
191
|
-
* @param tenantId - Tenant scope. Prevents cross-tenant email collisions.
|
|
192
279
|
* @returns The matching user record, or null if not found.
|
|
193
280
|
*/
|
|
194
|
-
findByEmail(
|
|
281
|
+
findByEmail(params: FindUserByEmailParams): Promise<AuthUser | null>;
|
|
195
282
|
/**
|
|
196
283
|
* Creates a new user record with a local (email + password) credential.
|
|
197
284
|
*
|
|
@@ -206,10 +293,16 @@ interface IUserRepository {
|
|
|
206
293
|
/**
|
|
207
294
|
* Replaces the user's stored password hash.
|
|
208
295
|
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
296
|
+
*
|
|
297
|
+
* The tenant is required for the same reason {@link findById} takes one: this library may not
|
|
298
|
+
* assume the consumer's ids are unique across tenants — `findById` takes a tenant precisely
|
|
299
|
+
* because they may not be, and a host that numbers users per tenant gives every tenant a user
|
|
300
|
+
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
301
|
+
* the update by both the id and the tenant, exactly as its read does.
|
|
302
|
+
*
|
|
303
|
+
* @param params - See {@link UpdatePasswordParams}.
|
|
211
304
|
*/
|
|
212
|
-
updatePassword(
|
|
305
|
+
updatePassword(params: UpdatePasswordParams): Promise<void>;
|
|
213
306
|
/**
|
|
214
307
|
* Updates the user's TOTP MFA configuration.
|
|
215
308
|
*
|
|
@@ -219,32 +312,48 @@ interface IUserRepository {
|
|
|
219
312
|
* spent recovery code in the account's list. An implementation MUST scope the update by both the
|
|
220
313
|
* id and the tenant, exactly as its read does.
|
|
221
314
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @param tenantId - The tenant the account belongs to; the update MUST be scoped to it, as
|
|
224
|
-
* {@link findById} scopes its read. Never omitted for a dashboard account.
|
|
225
|
-
* @param data - New MFA state. See {@link UpdateMfaData}.
|
|
315
|
+
* @param params - See {@link UpdateMfaParams}.
|
|
226
316
|
*/
|
|
227
|
-
updateMfa(
|
|
317
|
+
updateMfa(params: UpdateMfaParams): Promise<void>;
|
|
228
318
|
/**
|
|
229
319
|
* Records the current timestamp as the user's last successful login time.
|
|
230
320
|
*
|
|
231
|
-
*
|
|
321
|
+
*
|
|
322
|
+
* The tenant is required for the same reason {@link findById} takes one: this library may not
|
|
323
|
+
* assume the consumer's ids are unique across tenants — `findById` takes a tenant precisely
|
|
324
|
+
* because they may not be, and a host that numbers users per tenant gives every tenant a user
|
|
325
|
+
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
326
|
+
* the update by both the id and the tenant, exactly as its read does.
|
|
327
|
+
*
|
|
328
|
+
* @param params - See {@link TenantScopedUserRef}.
|
|
232
329
|
*/
|
|
233
|
-
updateLastLogin(
|
|
330
|
+
updateLastLogin(params: TenantScopedUserRef): Promise<void>;
|
|
234
331
|
/**
|
|
235
332
|
* Updates the user's account lifecycle status.
|
|
236
333
|
*
|
|
237
|
-
*
|
|
238
|
-
* @
|
|
334
|
+
*
|
|
335
|
+
* The tenant is required for the same reason {@link findById} takes one: this library may not
|
|
336
|
+
* assume the consumer's ids are unique across tenants — `findById` takes a tenant precisely
|
|
337
|
+
* because they may not be, and a host that numbers users per tenant gives every tenant a user
|
|
338
|
+
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
339
|
+
* the update by both the id and the tenant, exactly as its read does.
|
|
340
|
+
*
|
|
341
|
+
* @param params - See {@link UpdateStatusParams}.
|
|
239
342
|
*/
|
|
240
|
-
updateStatus(
|
|
343
|
+
updateStatus(params: UpdateStatusParams): Promise<void>;
|
|
241
344
|
/**
|
|
242
345
|
* Marks the user's email address as verified or unverified.
|
|
243
346
|
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
347
|
+
*
|
|
348
|
+
* The tenant is required for the same reason {@link findById} takes one: this library may not
|
|
349
|
+
* assume the consumer's ids are unique across tenants — `findById` takes a tenant precisely
|
|
350
|
+
* because they may not be, and a host that numbers users per tenant gives every tenant a user
|
|
351
|
+
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
352
|
+
* the update by both the id and the tenant, exactly as its read does.
|
|
353
|
+
*
|
|
354
|
+
* @param params - See {@link UpdateEmailVerifiedParams}.
|
|
246
355
|
*/
|
|
247
|
-
updateEmailVerified(
|
|
356
|
+
updateEmailVerified(params: UpdateEmailVerifiedParams): Promise<void>;
|
|
248
357
|
/**
|
|
249
358
|
* Replaces the account's email address.
|
|
250
359
|
*
|
|
@@ -258,11 +367,16 @@ interface IUserRepository {
|
|
|
258
367
|
* the check and this write are not one transaction, and the index is what makes the race
|
|
259
368
|
* a failed write instead of two accounts sharing a recovery address.
|
|
260
369
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
370
|
+
*
|
|
371
|
+
* The tenant is required for the same reason {@link findById} takes one: this library may not
|
|
372
|
+
* assume the consumer's ids are unique across tenants — `findById` takes a tenant precisely
|
|
373
|
+
* because they may not be, and a host that numbers users per tenant gives every tenant a user
|
|
374
|
+
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
375
|
+
* the update by both the id and the tenant, exactly as its read does.
|
|
376
|
+
*
|
|
263
377
|
* @throws Whatever the implementation throws when the address is taken.
|
|
264
378
|
*/
|
|
265
|
-
updateEmail(
|
|
379
|
+
updateEmail(params: UpdateEmailParams): Promise<void>;
|
|
266
380
|
/**
|
|
267
381
|
* Finds a user by their OAuth provider and external provider user ID.
|
|
268
382
|
*
|
|
@@ -271,20 +385,22 @@ interface IUserRepository {
|
|
|
271
385
|
* authenticates multiple times. Always query by both `provider` and `providerId`
|
|
272
386
|
* to avoid cross-provider ID collisions.
|
|
273
387
|
*
|
|
274
|
-
* @param provider - OAuth provider identifier (e.g. 'google', 'github').
|
|
275
|
-
* @param providerId - User's unique ID within the provider.
|
|
276
|
-
* @param tenantId - Tenant scope to enforce isolation.
|
|
277
388
|
* @returns The matching user record, or null if not found.
|
|
278
389
|
*/
|
|
279
|
-
findByOAuthId(
|
|
390
|
+
findByOAuthId(params: FindUserByOAuthIdParams): Promise<AuthUser | null>;
|
|
280
391
|
/**
|
|
281
392
|
* Links an existing user account to an OAuth provider identity.
|
|
282
393
|
*
|
|
283
|
-
*
|
|
284
|
-
* @
|
|
285
|
-
*
|
|
394
|
+
*
|
|
395
|
+
* The tenant is required for the same reason {@link findById} takes one: this library may not
|
|
396
|
+
* assume the consumer's ids are unique across tenants — `findById` takes a tenant precisely
|
|
397
|
+
* because they may not be, and a host that numbers users per tenant gives every tenant a user
|
|
398
|
+
* `1`. A write keyed by id alone can land on another tenant's row. An implementation MUST scope
|
|
399
|
+
* the update by both the id and the tenant, exactly as its read does.
|
|
400
|
+
*
|
|
401
|
+
* @param params - See {@link LinkOAuthParams}.
|
|
286
402
|
*/
|
|
287
|
-
linkOAuth(
|
|
403
|
+
linkOAuth(params: LinkOAuthParams): Promise<void>;
|
|
288
404
|
/**
|
|
289
405
|
* Creates a new user record originating from an OAuth provider.
|
|
290
406
|
*
|
|
@@ -1684,7 +1800,7 @@ declare const AUTH_THROTTLE_CONFIGS: {
|
|
|
1684
1800
|
readonly ttl: 60000;
|
|
1685
1801
|
};
|
|
1686
1802
|
};
|
|
1687
|
-
/**
|
|
1803
|
+
/** POST /auth/sessions/revoke-all — 5 requests per minute per IP. */
|
|
1688
1804
|
readonly revokeAllSessions: {
|
|
1689
1805
|
readonly default: {
|
|
1690
1806
|
readonly limit: 5;
|
|
@@ -2127,6 +2243,102 @@ declare class AuthException extends HttpException {
|
|
|
2127
2243
|
constructor(code: AuthErrorCode, details?: Record<string, unknown> | readonly unknown[]);
|
|
2128
2244
|
}
|
|
2129
2245
|
|
|
2246
|
+
/**
|
|
2247
|
+
* @fileoverview Derives this library's OpenAPI security posture from its resolved options.
|
|
2248
|
+
*
|
|
2249
|
+
* A pure function, separate from the contributor class that calls it, because everything
|
|
2250
|
+
* interesting here is a function of configuration and nothing of Nest: which schemes a
|
|
2251
|
+
* deployment can satisfy, which operations exist to describe, and what each of them requires.
|
|
2252
|
+
* The class is the adapter; this is the decision.
|
|
2253
|
+
*
|
|
2254
|
+
* **Why a library cannot state this statically.** The same build serves `/auth/login` in one
|
|
2255
|
+
* deployment and `/api/v2/identity/login` in another, with the credential in a cookie here and
|
|
2256
|
+
* in an `Authorization` header there, under cookie names the consumer chose. A static document
|
|
2257
|
+
* fragment would be wrong for every deployment but one. So the fragment is derived at the
|
|
2258
|
+
* consumer's boot, from the options that were actually resolved, and keyed by handler identity —
|
|
2259
|
+
* which survives every prefix, version and mount point.
|
|
2260
|
+
*
|
|
2261
|
+
* @layer OpenAPI
|
|
2262
|
+
*/
|
|
2263
|
+
|
|
2264
|
+
/**
|
|
2265
|
+
* The four security scheme names this library may define. A closed vocabulary.
|
|
2266
|
+
*
|
|
2267
|
+
* Each carries its transport, and that is load-bearing rather than decorative: a Security Scheme
|
|
2268
|
+
* Object has exactly one `type`, so `tokenDelivery: 'both'` cannot be one scheme — the
|
|
2269
|
+
* alternation lives in the requirement list, per OAS 3.0.3, which means the two transports need
|
|
2270
|
+
* two names. A bare `bymaxPlatformAccess` beside three suffixed names would then teach that the
|
|
2271
|
+
* suffix means "has a sibling", and a second platform transport would force either a breaking
|
|
2272
|
+
* rename or a permanent inconsistency.
|
|
2273
|
+
*
|
|
2274
|
+
* Renaming a scheme is a break a generated client feels, so these are stable identifiers. The
|
|
2275
|
+
* DEFINITIONS are derived from configuration; the names are not.
|
|
2276
|
+
*/
|
|
2277
|
+
declare const AUTH_SECURITY_SCHEMES: {
|
|
2278
|
+
readonly accessCookie: "bymaxAuthAccessCookie";
|
|
2279
|
+
readonly accessBearer: "bymaxAuthAccessBearer";
|
|
2280
|
+
readonly refreshCookie: "bymaxAuthRefreshCookie";
|
|
2281
|
+
readonly platformBearer: "bymaxPlatformAccessBearer";
|
|
2282
|
+
};
|
|
2283
|
+
|
|
2284
|
+
/**
|
|
2285
|
+
* Which of this library's guards protects the consumer's own routes.
|
|
2286
|
+
*
|
|
2287
|
+
* The two families take different credentials, and only one of them varies with delivery — which
|
|
2288
|
+
* is why a recipe phrased on `tokenDelivery` alone is wrong for half the deployments that use it.
|
|
2289
|
+
*/
|
|
2290
|
+
type AuthGuardFamily = 'dashboard' | 'platform';
|
|
2291
|
+
/** One OpenAPI Security Requirement Object: scheme name to the scopes it takes. */
|
|
2292
|
+
type OpenApiSecurityRequirement = Readonly<Record<string, readonly string[]>>;
|
|
2293
|
+
/** The two questions that decide a deployment's document-level default. */
|
|
2294
|
+
interface AuthDocumentSecurityParams {
|
|
2295
|
+
/**
|
|
2296
|
+
* The guard on the consumer's own routes: `JwtAuthGuard` is `'dashboard'`,
|
|
2297
|
+
* `JwtPlatformGuard` is `'platform'`.
|
|
2298
|
+
*/
|
|
2299
|
+
readonly guard: AuthGuardFamily;
|
|
2300
|
+
/**
|
|
2301
|
+
* The value passed to `BymaxAuthModule.forRoot({ tokenDelivery })` — **including `undefined`**.
|
|
2302
|
+
*
|
|
2303
|
+
* Optional there, so a deployment that never set it is relying on the library's default, and
|
|
2304
|
+
* this accepts the option exactly as it is written rather than making the caller narrow it. A
|
|
2305
|
+
* required parameter here would force `options.tokenDelivery ?? 'cookie'` at every call site,
|
|
2306
|
+
* which hardcodes a library decision into consumer code — the failure this whole function
|
|
2307
|
+
* exists to remove, reintroduced one line further out.
|
|
2308
|
+
*/
|
|
2309
|
+
readonly tokenDelivery: BymaxAuthModuleOptions['tokenDelivery'];
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Derives the document-level `security` default for a deployment's own routes.
|
|
2313
|
+
*
|
|
2314
|
+
* Drop the result straight into the `security` your OpenAPI document is built with. Deriving it
|
|
2315
|
+
* rather than writing a literal is what keeps the document honest when `tokenDelivery` changes:
|
|
2316
|
+
* the name follows the setting, so a mode switch cannot leave the default naming a scheme the
|
|
2317
|
+
* document no longer declares.
|
|
2318
|
+
*
|
|
2319
|
+
* Under `'both'` the result is a two-entry LIST, which OpenAPI reads as OR — a caller satisfies
|
|
2320
|
+
* the requirement with either transport. Merging the two names into a single entry would mean
|
|
2321
|
+
* AND, and would describe a server demanding the same credential twice.
|
|
2322
|
+
*
|
|
2323
|
+
* @param params - The guard family and the configured delivery mode. See
|
|
2324
|
+
* {@link AuthDocumentSecurityParams}.
|
|
2325
|
+
* @returns The security requirement list, frozen, with every entry naming exactly one scheme.
|
|
2326
|
+
*
|
|
2327
|
+
* @remarks
|
|
2328
|
+
* The scheme is *declared* only where a surface that uses it is mounted — the dashboard names
|
|
2329
|
+
* require a dashboard controller, the platform name requires the platform surface. A deployment
|
|
2330
|
+
* that mounts neither has no library scheme to name and should not set a default from this
|
|
2331
|
+
* library at all.
|
|
2332
|
+
*
|
|
2333
|
+
* @example
|
|
2334
|
+
* ```ts
|
|
2335
|
+
* BymaxCoreModule.forRoot({
|
|
2336
|
+
* openapi: { security: authDocumentSecurity({ guard: 'dashboard', tokenDelivery }) }
|
|
2337
|
+
* })
|
|
2338
|
+
* ```
|
|
2339
|
+
*/
|
|
2340
|
+
declare function authDocumentSecurity({ guard, tokenDelivery }: AuthDocumentSecurityParams): readonly OpenApiSecurityRequirement[];
|
|
2341
|
+
|
|
2130
2342
|
/**
|
|
2131
2343
|
* Email provider plugin contract for @bymax-one/nest-auth.
|
|
2132
2344
|
*
|
|
@@ -2138,9 +2350,18 @@ declare class AuthException extends HttpException {
|
|
|
2138
2350
|
* @layer Interface
|
|
2139
2351
|
*/
|
|
2140
2352
|
/**
|
|
2141
|
-
* Contextual information about a new user session sent in security
|
|
2353
|
+
* Contextual information about a new user session, as sent in security alert emails.
|
|
2354
|
+
*
|
|
2355
|
+
* Named for the alert rather than for the session, deliberately. It was `SessionInfo` until
|
|
2356
|
+
* 1.4.4 and collided with the session-listing type of the same name in `SessionService` — the
|
|
2357
|
+
* barrel exported THIS one under the plain name, so a consumer importing the obvious `SessionInfo`
|
|
2358
|
+
* to type a `GET /sessions` response got a shape with no `id` — and, worse, a `sessionHash` that
|
|
2359
|
+
* means something else. Here it is the TRUNCATED display value; on the listing it is the full
|
|
2360
|
+
* 64-hex hash. Same field name, same type, different value, and the truncated one is exactly what
|
|
2361
|
+
* `DELETE /sessions/:id` refuses. Two careful consumer sessions disagreed for a day over whether
|
|
2362
|
+
* the route returned an `id`: one read the wire and saw it, one read the type and did not.
|
|
2142
2363
|
*/
|
|
2143
|
-
interface
|
|
2364
|
+
interface SessionAlertInfo {
|
|
2144
2365
|
/** Human-readable description of the device or browser (e.g. "Chrome on macOS"). */
|
|
2145
2366
|
device: string;
|
|
2146
2367
|
/**
|
|
@@ -2303,6 +2524,22 @@ interface IEmailProvider {
|
|
|
2303
2524
|
* security alert — if the user did not initiate this change, they should be
|
|
2304
2525
|
* directed to contact support or reset their credentials.
|
|
2305
2526
|
*
|
|
2527
|
+
* **This library does NOT await these three notices** (`sendMfaEnabledNotification`,
|
|
2528
|
+
* `sendMfaDisabledNotification`, and the administrative reset that also uses the latter). By the
|
|
2529
|
+
* time one is sent the factor is already enabled or removed, every session is invalidated and
|
|
2530
|
+
* the token epoch is bumped — the change has happened — so awaiting would let a bounced notice
|
|
2531
|
+
* answer the caller with an error for an operation that succeeded, which is how a user ends up
|
|
2532
|
+
* locked out of the account they just secured.
|
|
2533
|
+
*
|
|
2534
|
+
* The consequence is yours to handle, and it is why it is documented here rather than assumed:
|
|
2535
|
+
* an implementation that sends INLINE (an awaited HTTP call to a mail API, as the README's own
|
|
2536
|
+
* example does) can lose the notice to a process shutdown or a serverless freeze that arrives
|
|
2537
|
+
* between the response and the send completing. Where these alerts matter — and the
|
|
2538
|
+
* administrative reset is the one that makes a support-desk takeover detectable — enqueue
|
|
2539
|
+
* durably and resolve, rather than sending inline. The library cannot supply that on your
|
|
2540
|
+
* behalf, and awaiting would not supply it either: a freeze mid-await loses the notice AND the
|
|
2541
|
+
* caller's response.
|
|
2542
|
+
*
|
|
2306
2543
|
* @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
|
|
2307
2544
|
* attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
|
|
2308
2545
|
* @param email - Recipient's email address.
|
|
@@ -2328,7 +2565,7 @@ interface IEmailProvider {
|
|
|
2328
2565
|
*
|
|
2329
2566
|
* **This library never calls it.** The method is optional, and it is here as a typed
|
|
2330
2567
|
* signature for you to call from the {@link IAuthHooks.onNewSession} hook — which the
|
|
2331
|
-
* library does fire, on every session it creates, with the same {@link
|
|
2568
|
+
* library does fire, on every session it creates, with the same {@link SessionAlertInfo} this
|
|
2332
2569
|
* takes.
|
|
2333
2570
|
*
|
|
2334
2571
|
* The alert deliberately does not live inside the library, because the library cannot send
|
|
@@ -2349,7 +2586,7 @@ interface IEmailProvider {
|
|
|
2349
2586
|
* @param sessionInfo - Device, IP, and session identifier details.
|
|
2350
2587
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2351
2588
|
*/
|
|
2352
|
-
sendNewSessionAlert?(tenantId: string, email: string, sessionInfo:
|
|
2589
|
+
sendNewSessionAlert?(tenantId: string, email: string, sessionInfo: SessionAlertInfo, locale?: string): Promise<void>;
|
|
2353
2590
|
/**
|
|
2354
2591
|
* Sends a tenant invitation email to a prospective member.
|
|
2355
2592
|
*
|
|
@@ -2803,7 +3040,7 @@ interface IAuthHooks {
|
|
|
2803
3040
|
* @param sessionInfo - Device, IP, and session hash for the new session.
|
|
2804
3041
|
* @param context - Request metadata (IP, user agent, sanitized headers).
|
|
2805
3042
|
*/
|
|
2806
|
-
onNewSession?(user: SafeAuthUser, sessionInfo:
|
|
3043
|
+
onNewSession?(user: SafeAuthUser, sessionInfo: SessionAlertInfo, context: HookContext): Promise<void> | void;
|
|
2807
3044
|
/**
|
|
2808
3045
|
* Called after the user's email address has been successfully verified.
|
|
2809
3046
|
*
|
|
@@ -3504,7 +3741,7 @@ declare class NoOpEmailProvider implements IEmailProvider {
|
|
|
3504
3741
|
/** @inheritdoc */
|
|
3505
3742
|
sendMfaDisabledNotification(_tenantId: string, email: string, _locale?: string): Promise<void>;
|
|
3506
3743
|
/** @inheritdoc */
|
|
3507
|
-
sendNewSessionAlert(_tenantId: string, email: string, _sessionInfo:
|
|
3744
|
+
sendNewSessionAlert(_tenantId: string, email: string, _sessionInfo: SessionAlertInfo, _locale?: string): Promise<void>;
|
|
3508
3745
|
/** @inheritdoc */
|
|
3509
3746
|
sendInvitation(_tenantId: string, email: string, _inviteData: InviteData, _locale?: string): Promise<void>;
|
|
3510
3747
|
}
|
|
@@ -3513,9 +3750,34 @@ declare class NoOpEmailProvider implements IEmailProvider {
|
|
|
3513
3750
|
* The delivery channel {@link DefaultAuthEmailProvider} sends through.
|
|
3514
3751
|
*
|
|
3515
3752
|
* Narrow by design: it names only the one call the provider makes, so the provider couples to no
|
|
3516
|
-
* concrete mailer.
|
|
3517
|
-
*
|
|
3518
|
-
*
|
|
3753
|
+
* concrete mailer. Any adapter exposing this shape satisfies it.
|
|
3754
|
+
*
|
|
3755
|
+
* **Structural fit is not enough, and a channel that merely fits will drop the one field that
|
|
3756
|
+
* matters.** `containsCredential` is this interface's own name for "publish none of this
|
|
3757
|
+
* message's content". A channel that has never heard of this library reads every other field —
|
|
3758
|
+
* `to`, `subject`, `html`, `text` — and ignores that one, because nothing tells it to look. The
|
|
3759
|
+
* result is not a missing feature: it is a relay answering `550` with the offending body quoted,
|
|
3760
|
+
* a reset code reaching an audit record, and a `send` call that looked correctly wired.
|
|
3761
|
+
*
|
|
3762
|
+
* So an implementation owes a TRANSLATION, not just a matching shape. Whatever the channel calls
|
|
3763
|
+
* "do not publish this payload", set it from `containsCredential` on every call.
|
|
3764
|
+
*
|
|
3765
|
+
* `@bymax-one/nest-notification`'s `EmailService.send` is the worked example, and it is also the
|
|
3766
|
+
* trap. It satisfies this interface structurally — its input carries these fields and more, all
|
|
3767
|
+
* the extras optional — so it can be passed in directly and will compile. Do not. Its own switch
|
|
3768
|
+
* is spelled `publishProviderText`, so a direct pass hands it a `containsCredential` it does not
|
|
3769
|
+
* read while its own flag stays at the default. Wire an adapter instead:
|
|
3770
|
+
*
|
|
3771
|
+
* ```ts
|
|
3772
|
+
* const sink: AuthEmailSink = {
|
|
3773
|
+
* send: ({ containsCredential, ...message }) =>
|
|
3774
|
+
* mailer.send({ ...message, publishProviderText: !containsCredential })
|
|
3775
|
+
* }
|
|
3776
|
+
* ```
|
|
3777
|
+
*
|
|
3778
|
+
* Named rather than left general because the direct pass is what a reader reaches for once they
|
|
3779
|
+
* know the shapes line up, and this paragraph is the only thing standing between that instinct
|
|
3780
|
+
* and a published credential. The field name is that library's to change; the obligation is not.
|
|
3519
3781
|
*/
|
|
3520
3782
|
interface AuthEmailSink {
|
|
3521
3783
|
/**
|
|
@@ -3535,6 +3797,43 @@ interface AuthEmailSink {
|
|
|
3535
3797
|
html: string;
|
|
3536
3798
|
/** Plain-text body. */
|
|
3537
3799
|
text: string;
|
|
3800
|
+
/** Which message this is, so a sink can act per flow. Always one of {@link AUTH_EMAIL_KINDS}. */
|
|
3801
|
+
kind: AuthEmailKind;
|
|
3802
|
+
/**
|
|
3803
|
+
* `true` when the rendered message carries a live credential — a reset code, a verification
|
|
3804
|
+
* code, a reset or invitation token.
|
|
3805
|
+
*
|
|
3806
|
+
* **The whole message, not only the bodies.** `subject`, `html` and `text` are all rendered by
|
|
3807
|
+
* the same renderer and all handed to the sink, so a credential in the subject is exactly as
|
|
3808
|
+
* published as one in the body. Scoping this to "the body" would have a renderer that puts a
|
|
3809
|
+
* code in its subject line correctly leave the flag unset by the contract's own words, which
|
|
3810
|
+
* is the flag being wrong by construction rather than by mistake. (The built-in copy states
|
|
3811
|
+
* every code in the body and none in a subject; this is about what an override may do.)
|
|
3812
|
+
*
|
|
3813
|
+
* Two sources, combined so that neither can weaken the other. The message KIND supplies the
|
|
3814
|
+
* baseline, which is what the built-in copy carries. A rendering may additionally declare
|
|
3815
|
+
* itself credential-bearing through {@link AuthEmailMessage.containsCredential}, because
|
|
3816
|
+
* `messages` replaces a renderer outright and a product's own copy for a normally harmless
|
|
3817
|
+
* kind can put a live secret in the body — the kind alone cannot see that, and would state
|
|
3818
|
+
* `false` about it.
|
|
3819
|
+
*
|
|
3820
|
+
* **What a sink must do with it: do not publish this message's content anywhere.** Not in an
|
|
3821
|
+
* error it throws, not in a log line, not in an audit record that outlives delivery. A sink
|
|
3822
|
+
* that quotes what it was given is the ordinary shape — an SMTP relay answering `550` quotes
|
|
3823
|
+
* the offending body, and a client that wraps one usually passes that text through.
|
|
3824
|
+
*
|
|
3825
|
+
* **What this flag is NOT.** It is not protection, and this library cannot make it one: once
|
|
3826
|
+
* the body leaves `send`, what happens to it belongs to the sink. It is a statement of fact
|
|
3827
|
+
* about the payload, delivered at the only moment a sink could act on it.
|
|
3828
|
+
*
|
|
3829
|
+
* **Why a flag and not a list of values to redact.** That was measured and rejected. Redaction
|
|
3830
|
+
* is a substring match, so it holds for a value quoted the way it was written and not for the
|
|
3831
|
+
* same bytes re-encoded — a relay is free to answer with the body in base64, and then no list
|
|
3832
|
+
* matches. A categorical "publish none of this message" needs to find nothing, which is the
|
|
3833
|
+
* only shape that survives an encoding it cannot predict. The same reasoning took every
|
|
3834
|
+
* channel-authored byte out of this library's own log lines.
|
|
3835
|
+
*/
|
|
3836
|
+
containsCredential: boolean;
|
|
3538
3837
|
}): Promise<unknown>;
|
|
3539
3838
|
}
|
|
3540
3839
|
/** One rendered message, before the tenant and recipient are attached to it. */
|
|
@@ -3550,6 +3849,23 @@ interface AuthEmailMessage {
|
|
|
3550
3849
|
* unset to have the provider render {@link text} into safe, escaped paragraphs.
|
|
3551
3850
|
*/
|
|
3552
3851
|
readonly html?: string | undefined;
|
|
3852
|
+
/**
|
|
3853
|
+
* Set to `true` when this rendering puts a live credential anywhere in the message — in
|
|
3854
|
+
* {@link subject} as much as in {@link text} or {@link html}. All three are handed to the sink,
|
|
3855
|
+
* so a code in the subject line is exactly as published as one in the body.
|
|
3856
|
+
*
|
|
3857
|
+
* The provider already knows which KINDS carry one by default, and a renderer cannot make that
|
|
3858
|
+
* baseline weaker: this value is OR-ed with it, so `false` on `passwordResetOtp` is ignored and
|
|
3859
|
+
* the sink is still told `true`. It exists for the other direction, which the kind alone cannot
|
|
3860
|
+
* see. Overrides replace a renderer outright, so a product that puts recovery codes into its
|
|
3861
|
+
* own `mfaEnabled` copy has turned a notice into a credential-bearing message — the kind still
|
|
3862
|
+
* says `mfaEnabled` and, without this, the sink would be told `false` about a body that carries
|
|
3863
|
+
* a live secret. That is the flag being wrong rather than merely non-protective, which is worse
|
|
3864
|
+
* than not having it.
|
|
3865
|
+
*
|
|
3866
|
+
* Leave it unset on a rendering that carries no credential; the kind decides.
|
|
3867
|
+
*/
|
|
3868
|
+
readonly containsCredential?: boolean | undefined;
|
|
3553
3869
|
}
|
|
3554
3870
|
/**
|
|
3555
3871
|
* The copy for every message the port can send, as pure renderers keyed by event.
|
|
@@ -3599,7 +3915,7 @@ interface AuthEmailCatalogue {
|
|
|
3599
3915
|
}): AuthEmailMessage;
|
|
3600
3916
|
/** Security alert about a newly established session. */
|
|
3601
3917
|
newSessionAlert(input: {
|
|
3602
|
-
sessionInfo:
|
|
3918
|
+
sessionInfo: SessionAlertInfo;
|
|
3603
3919
|
locale?: string | undefined;
|
|
3604
3920
|
}): AuthEmailMessage;
|
|
3605
3921
|
/** Invitation to join a tenant. */
|
|
@@ -3610,6 +3926,23 @@ interface AuthEmailCatalogue {
|
|
|
3610
3926
|
}
|
|
3611
3927
|
/** How the provider reacts to a delivery failure. */
|
|
3612
3928
|
type DeliveryErrorPolicy = 'swallow' | 'rethrow';
|
|
3929
|
+
/** Every message the provider can send, named by its entry in {@link AuthEmailCatalogue}. */
|
|
3930
|
+
type AuthEmailKind = keyof AuthEmailCatalogue;
|
|
3931
|
+
/**
|
|
3932
|
+
* Every message kind, as a value.
|
|
3933
|
+
*
|
|
3934
|
+
* Declared here rather than derived, because a type cannot be iterated at runtime and expanding a
|
|
3935
|
+
* bare `'rethrow'` needs the list. Kept adjacent to {@link AuthEmailCatalogue} so the two are read
|
|
3936
|
+
* together; a catalogue entry added without a matching entry here fails the test that compares them.
|
|
3937
|
+
*/
|
|
3938
|
+
declare const AUTH_EMAIL_KINDS: readonly ["passwordResetToken", "passwordResetOtp", "emailVerificationOtp", "passwordChanged", "emailChangeVerification", "emailChanged", "mfaEnabled", "mfaDisabled", "newSessionAlert", "invitation"];
|
|
3939
|
+
/**
|
|
3940
|
+
* A delivery-error policy chosen per message.
|
|
3941
|
+
*
|
|
3942
|
+
* Any message left out keeps `'swallow'`, so a map only ever names the flows that want the throw.
|
|
3943
|
+
* That direction matters: the safe value is what you get by saying nothing.
|
|
3944
|
+
*/
|
|
3945
|
+
type DeliveryErrorPolicyMap = Partial<Record<AuthEmailKind, DeliveryErrorPolicy>>;
|
|
3613
3946
|
/** Options for {@link DefaultAuthEmailProvider}. */
|
|
3614
3947
|
interface DefaultAuthEmailProviderOptions {
|
|
3615
3948
|
/**
|
|
@@ -3623,11 +3956,43 @@ interface DefaultAuthEmailProviderOptions {
|
|
|
3623
3956
|
* resolves, so a down channel never turns a notification into a failed user request. `'rethrow'`
|
|
3624
3957
|
* logs and then re-throws, restoring the throw the two flows that react to one expect —
|
|
3625
3958
|
* `PasswordResetService` deletes an undelivered reset token early, and `EmailChangeService` lets
|
|
3626
|
-
* a failed verification send surface rather than reporting "sent". The trade is
|
|
3627
|
-
* `'rethrow'`
|
|
3628
|
-
* failure
|
|
3959
|
+
* a failed verification send surface rather than reporting "sent". The trade is narrower than it
|
|
3960
|
+
* looks: an invitation send fails under `'rethrow'` too, but the MFA notices do NOT — they
|
|
3961
|
+
* are detached and their failure is caught, because by the time one is sent the factor is
|
|
3962
|
+
* already enabled or removed, and answering the caller with an error would report a change that
|
|
3963
|
+
* happened as one that did not. Pick the failure mode the deployment's channel warrants, knowing
|
|
3964
|
+
* that a completed auth-state change is never reversed by a notice that could not be delivered.
|
|
3965
|
+
*
|
|
3966
|
+
* **`'rethrow'` hands you an error that may contain the credential.** The provider's own log
|
|
3967
|
+
* line publishes nothing the channel wrote, but what it re-throws is the channel's original
|
|
3968
|
+
* error, unaltered — because
|
|
3969
|
+
* a caller that opted into this policy did so to branch on the channel's codes, and a laundered
|
|
3970
|
+
* replacement would take those away. A relay that rejects by quoting the message body puts the
|
|
3971
|
+
* OTP or invitation token into that error, so whatever catches it must not log it raw. Describe
|
|
3972
|
+
* it with `describeChannelStatus`, which publishes nothing the channel wrote — NOT
|
|
3973
|
+
* `redactSecrets`, which this file's own history shows is not enough on its own: a relay
|
|
3974
|
+
* may quote what it rejected in transfer encoding, and a substring match cannot see through
|
|
3975
|
+
* that. `redactSecrets` is for strings you know contain the literal value. This is the one
|
|
3976
|
+
* credential this library cannot contain on your behalf.
|
|
3977
|
+
*
|
|
3978
|
+
* **Which is why this takes a MAP as well as a bare policy.** Five messages carry a credential
|
|
3979
|
+
* in their body, and the two flows that motivate the opt-in are two of them — so a bare
|
|
3980
|
+
* `'rethrow'` reaches three MORE credential-bearing paths than anyone asked for, on top of every
|
|
3981
|
+
* message that carries none. Naming the flows keeps the unlaundered error where a deployment
|
|
3982
|
+
* wanted it and leaves it off the rest:
|
|
3983
|
+
*
|
|
3984
|
+
* ```typescript
|
|
3985
|
+
* new DefaultAuthEmailProvider(sink, {
|
|
3986
|
+
* onDeliveryError: { passwordResetToken: 'rethrow', emailChangeVerification: 'rethrow' }
|
|
3987
|
+
* })
|
|
3988
|
+
* ```
|
|
3989
|
+
*
|
|
3990
|
+
* A message left out of the map keeps `'swallow'`, so the safe value is what you get by saying
|
|
3991
|
+
* nothing, and widening the opt-in is always an explicit act. A bare policy still works and
|
|
3992
|
+
* still applies to all ten — it is the coarse form, kept because it is the honest way to say
|
|
3993
|
+
* "this deployment wants the throw everywhere".
|
|
3629
3994
|
*/
|
|
3630
|
-
readonly onDeliveryError?: DeliveryErrorPolicy;
|
|
3995
|
+
readonly onDeliveryError?: DeliveryErrorPolicy | DeliveryErrorPolicyMap;
|
|
3631
3996
|
}
|
|
3632
3997
|
/**
|
|
3633
3998
|
* Default {@link IEmailProvider} over a {@link AuthEmailSink} delivery channel.
|
|
@@ -3642,10 +4007,18 @@ interface DefaultAuthEmailProviderOptions {
|
|
|
3642
4007
|
* }
|
|
3643
4008
|
* ```
|
|
3644
4009
|
*
|
|
3645
|
-
*
|
|
3646
|
-
* sending an invitation, confirming an address change), so
|
|
3647
|
-
* into a failed request over a message that is a
|
|
3648
|
-
* The failure is logged and the flow continues.
|
|
4010
|
+
* Under the default `onDeliveryError: 'swallow'`, no method throws on a delivery failure — the
|
|
4011
|
+
* library awaits several of these calls (sending an invitation, confirming an address change), so
|
|
4012
|
+
* a channel that is down would turn each into a failed request over a message that is a
|
|
4013
|
+
* notification rather than the operation itself. The failure is logged and the flow continues.
|
|
4014
|
+
* Setting `'rethrow'` makes EVERY method reject with the channel's original error — there is one
|
|
4015
|
+
* `deliver()` behind all ten and one place the policy is read, so no method is exempt. That is the
|
|
4016
|
+
* whole point of the option and is documented with the duty it carries.
|
|
4017
|
+
*
|
|
4018
|
+
* The three MFA notices are the exception at the CALLER rather than here: `MfaService` sends them
|
|
4019
|
+
* detached and catches the rejection itself, because by then the factor is already enabled or
|
|
4020
|
+
* removed. Call `sendMfaEnabledNotification` directly under `'rethrow'` and it rejects like any
|
|
4021
|
+
* other — what is absent is a caller that lets the rejection fail an operation, not the rejection.
|
|
3649
4022
|
*
|
|
3650
4023
|
* That choice has a cost worth stating, because two flows react to a *throw* from the port. A
|
|
3651
4024
|
* reset-token send that rejects lets `PasswordResetService` delete the stored token early rather
|
|
@@ -3653,9 +4026,18 @@ interface DefaultAuthEmailProviderOptions {
|
|
|
3653
4026
|
* "verification sent". Under the default both degrade gracefully rather than break: the reset token
|
|
3654
4027
|
* still expires at its TTL and was never delivered to anyone, and the change still requires the
|
|
3655
4028
|
* verification the recipient never got, so it cannot complete. A deployment that wants the throw
|
|
3656
|
-
* back on those flows
|
|
3657
|
-
*
|
|
3658
|
-
*
|
|
4029
|
+
* back on those two flows names them:
|
|
4030
|
+
* `{ onDeliveryError: { passwordResetToken: 'rethrow', emailChangeVerification: 'rethrow' } }`.
|
|
4031
|
+
* A bare `'rethrow'` also works and opts in every message. Five of them render a credential, and
|
|
4032
|
+
* those two flows are two of the five — so the bare form reaches three further credential-bearing
|
|
4033
|
+
* paths, a wider trade than either flow asks for. The default optimizes for the common case: a
|
|
4034
|
+
* transient channel outage must not fail the user's action.
|
|
4035
|
+
*
|
|
4036
|
+
* The MFA notices are the exception in the other direction: `MfaService` does not await them under
|
|
4037
|
+
* either policy. By the time one is sent the secret is written, every session is invalidated and
|
|
4038
|
+
* the token epoch is bumped — the change has happened — so a bounced notice answering the caller
|
|
4039
|
+
* with an error would report a transition that succeeded as one that failed, which is how a user
|
|
4040
|
+
* ends up locked out of the account they just secured.
|
|
3659
4041
|
*/
|
|
3660
4042
|
declare class DefaultAuthEmailProvider implements IEmailProvider {
|
|
3661
4043
|
private readonly sink;
|
|
@@ -3663,8 +4045,16 @@ declare class DefaultAuthEmailProvider implements IEmailProvider {
|
|
|
3663
4045
|
private readonly logger;
|
|
3664
4046
|
/** The copy in effect: the defaults, with any provided overrides layered on top. */
|
|
3665
4047
|
private readonly messages;
|
|
3666
|
-
/**
|
|
3667
|
-
|
|
4048
|
+
/**
|
|
4049
|
+
* The resolved per-message policy.
|
|
4050
|
+
*
|
|
4051
|
+
* A `Map`, not the plain object the option accepts. An object lookup walks the prototype chain,
|
|
4052
|
+
* so `policy['toString']` answers with a function rather than `undefined` — unreachable here,
|
|
4053
|
+
* because the key is a closed union of ten literals this file writes, but "the key cannot be
|
|
4054
|
+
* dangerous" is a property of today's call sites and not of the lookup. A `Map` has no prototype
|
|
4055
|
+
* chain to walk, which makes it a property of the data structure instead.
|
|
4056
|
+
*/
|
|
4057
|
+
private readonly deliveryErrorPolicy;
|
|
3668
4058
|
/**
|
|
3669
4059
|
* @param sink - The delivery channel to send through.
|
|
3670
4060
|
* @param options - Optional copy overrides and delivery-error policy.
|
|
@@ -3687,7 +4077,7 @@ declare class DefaultAuthEmailProvider implements IEmailProvider {
|
|
|
3687
4077
|
/** @inheritdoc */
|
|
3688
4078
|
sendMfaDisabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
3689
4079
|
/** @inheritdoc */
|
|
3690
|
-
sendNewSessionAlert(tenantId: string, email: string, sessionInfo:
|
|
4080
|
+
sendNewSessionAlert(tenantId: string, email: string, sessionInfo: SessionAlertInfo, locale?: string): Promise<void>;
|
|
3691
4081
|
/** @inheritdoc */
|
|
3692
4082
|
sendInvitation(tenantId: string, email: string, inviteData: InviteData, locale?: string): Promise<void>;
|
|
3693
4083
|
/**
|
|
@@ -3697,6 +4087,13 @@ declare class DefaultAuthEmailProvider implements IEmailProvider {
|
|
|
3697
4087
|
* @param tenantId - Tenant the message is attributed to.
|
|
3698
4088
|
* @param to - Recipient address.
|
|
3699
4089
|
* @param message - The rendered subject and body, and optionally its own HTML.
|
|
4090
|
+
* @param label - Which message this is, as a fixed name this file owns. It goes in the log line
|
|
4091
|
+
* in place of the rendered SUBJECT, and the substitution is the point: a subject comes from
|
|
4092
|
+
* the `messages` catalogue, which a consumer may override, so logging it publishes a string
|
|
4093
|
+
* this library did not write. Redacting it is not enough — a renderer that TRANSFORMS a value
|
|
4094
|
+
* defeats a substring match, and `Code 123-456` for the OTP `123456` is a reasonable-looking
|
|
4095
|
+
* thing to write. The label carries the same information for an operator, identifies the
|
|
4096
|
+
* message more stably for a log parser, and cannot carry anything at all.
|
|
3700
4097
|
*/
|
|
3701
4098
|
private deliver;
|
|
3702
4099
|
}
|
|
@@ -3911,6 +4308,8 @@ interface WsTicketSnapshot {
|
|
|
3911
4308
|
interface RefreshRotationParams {
|
|
3912
4309
|
/** Which identity plane is rotating; selects the whole prefix set. */
|
|
3913
4310
|
kind: 'dashboard' | 'platform';
|
|
4311
|
+
/** The tenant the rotating session belongs to; part of the index key on the dashboard plane. */
|
|
4312
|
+
tenantId: string | undefined;
|
|
3914
4313
|
/** SHA-256 of the presented (old) refresh token. */
|
|
3915
4314
|
oldHash: string;
|
|
3916
4315
|
/** SHA-256 of the freshly minted refresh token. */
|
|
@@ -4102,6 +4501,8 @@ declare class AuthRedisService {
|
|
|
4102
4501
|
*/
|
|
4103
4502
|
writeNewSession(params: {
|
|
4104
4503
|
kind: 'dashboard' | 'platform';
|
|
4504
|
+
/** The tenant the session belongs to; part of the index key on the dashboard plane. */
|
|
4505
|
+
tenantId: string | undefined;
|
|
4105
4506
|
tokenHash: string;
|
|
4106
4507
|
sessionJson: string;
|
|
4107
4508
|
familyId: string;
|
|
@@ -4122,6 +4523,8 @@ declare class AuthRedisService {
|
|
|
4122
4523
|
*/
|
|
4123
4524
|
writeRecoveredSession(params: {
|
|
4124
4525
|
kind: 'dashboard' | 'platform';
|
|
4526
|
+
/** The tenant the session belongs to; part of the index key on the dashboard plane. */
|
|
4527
|
+
tenantId: string | undefined;
|
|
4125
4528
|
newHash: string;
|
|
4126
4529
|
newSessionJson: string;
|
|
4127
4530
|
familyId: string;
|
|
@@ -4156,7 +4559,10 @@ declare class AuthRedisService {
|
|
|
4156
4559
|
* Idempotent: an empty, unknown, or already-cleared family is a no-op.
|
|
4157
4560
|
*
|
|
4158
4561
|
* @param familyId - The family id carried by the consumed-token marker.
|
|
4159
|
-
* @param kind - Which identity plane the family belongs to. Defaults to `'dashboard'`.
|
|
4562
|
+
* @param kind - Which identity plane the family belongs to. Defaults to `'dashboard'`. Unlike
|
|
4563
|
+
* the three methods that lost their default in this change, this one takes no positional
|
|
4564
|
+
* tenant beside it — the owner and its tenant come off the family's own record — so there is
|
|
4565
|
+
* no adjacent same-typed argument for it to be transposed with.
|
|
4160
4566
|
* @returns The number of members removed and the account the family belonged to. The owner
|
|
4161
4567
|
* is reported because the caller cannot obtain it any other way: the presented token's own
|
|
4162
4568
|
* `rt:` key was deleted when it was rotated, so at reuse-detection time the family index is
|
|
@@ -4174,10 +4580,17 @@ declare class AuthRedisService {
|
|
|
4174
4580
|
* names the owner. Reading it here rather than decoding JSON inside the revocation script
|
|
4175
4581
|
* keeps the script free of `cjson` and uses a real parser on the stored record.
|
|
4176
4582
|
*
|
|
4583
|
+
* The TENANT comes off the same record, because the index key the caller then builds is
|
|
4584
|
+
* scoped to it. Reading the two together is what keeps them from disagreeing: an owner
|
|
4585
|
+
* resolved from one member and a tenant guessed from anywhere else would name a key that
|
|
4586
|
+
* belongs to neither.
|
|
4587
|
+
*
|
|
4177
4588
|
* @param members - The family index members (bare session hashes).
|
|
4178
4589
|
* @param livePrefix - The live-session prefix for the plane (`rt` or `prt`).
|
|
4179
|
-
* @returns The owner
|
|
4180
|
-
*
|
|
4590
|
+
* @returns The owner and its tenant; `userId` is `''` when no member NAMES one — every member
|
|
4591
|
+
* record gone, or a record that will not parse, or one carrying no `userId`. The three are
|
|
4592
|
+
* indistinguishable from here, so a caller reporting this must say what was observed rather
|
|
4593
|
+
* than why.
|
|
4181
4594
|
*/
|
|
4182
4595
|
private readFamilyOwner;
|
|
4183
4596
|
/**
|
|
@@ -4286,12 +4699,16 @@ declare class AuthRedisService {
|
|
|
4286
4699
|
* Atomically deletes all refresh sessions for a user on the given identity plane.
|
|
4287
4700
|
*
|
|
4288
4701
|
* Each plane sweeps only its own index — `sess:` for dashboard, `psess:` for platform — so
|
|
4289
|
-
* an admin and a user who happen to share an id never revoke each other's sessions.
|
|
4702
|
+
* an admin and a user who happen to share an id never revoke each other's sessions. The
|
|
4703
|
+
* dashboard index is scoped to the tenant as well, because that plane's ids are only unique
|
|
4704
|
+
* within one: without it a sweep aimed at `t1/u1` also emptied `t2/u1`.
|
|
4290
4705
|
*
|
|
4291
4706
|
* @param userId - Internal user or admin ID whose sessions will be invalidated.
|
|
4292
|
-
* @param
|
|
4707
|
+
* @param tenantId - The tenant the dashboard account belongs to; ignored on the platform plane.
|
|
4708
|
+
* @param kind - Which identity plane to revoke. **Required** — the default was removed because
|
|
4709
|
+
* a positional plane beside a positional tenant is a transposition nobody notices.
|
|
4293
4710
|
*/
|
|
4294
|
-
invalidateUserSessions(userId: string, kind
|
|
4711
|
+
invalidateUserSessions(userId: string, tenantId: string | undefined, kind: 'dashboard' | 'platform'): Promise<void>;
|
|
4295
4712
|
/**
|
|
4296
4713
|
* Atomically increments a counter and sets a fixed TTL on the **first** increment.
|
|
4297
4714
|
*
|
|
@@ -4322,10 +4739,12 @@ declare class AuthRedisService {
|
|
|
4322
4739
|
* bumped carries one.
|
|
4323
4740
|
*
|
|
4324
4741
|
* @param userId - Internal user or admin ID to look up.
|
|
4325
|
-
* @param
|
|
4742
|
+
* @param tenantId - The tenant the dashboard account belongs to; ignored on the platform plane.
|
|
4743
|
+
* @param kind - Which identity plane to read. **Required** — the default was removed because
|
|
4744
|
+
* a positional plane beside a positional tenant is a transposition nobody notices.
|
|
4326
4745
|
* @returns The stored epoch, or `0` when none is stored or the value is unreadable.
|
|
4327
4746
|
*/
|
|
4328
|
-
getUserTokenEpoch(userId: string, kind
|
|
4747
|
+
getUserTokenEpoch(userId: string, tenantId: string | undefined, kind: 'dashboard' | 'platform'): Promise<number>;
|
|
4329
4748
|
/**
|
|
4330
4749
|
* Reads the owner recorded on a stored refresh session, or `''` when there is none.
|
|
4331
4750
|
*
|
|
@@ -4334,13 +4753,24 @@ declare class AuthRedisService {
|
|
|
4334
4753
|
* cannot serve that purpose when the token is allowed to be absent or expired — and taking
|
|
4335
4754
|
* the owner from an unverified token would let a caller aim the revocation at someone else.
|
|
4336
4755
|
*
|
|
4337
|
-
* A record that is missing, unparseable, or carries no string `userId` answers
|
|
4338
|
-
* is nothing to attribute the logout to, which the caller treats as "no live
|
|
4756
|
+
* A record that is missing, unparseable, or carries no string `userId` answers an empty
|
|
4757
|
+
* `userId`: there is nothing to attribute the logout to, which the caller treats as "no live
|
|
4758
|
+
* session".
|
|
4759
|
+
*
|
|
4760
|
+
* **The tenant comes from the same record, and that is the point.** Revoking the session
|
|
4761
|
+
* needs the owner's index key, which is tenant-scoped on the dashboard plane — and the one
|
|
4762
|
+
* place the tenant can be read without trusting the caller is the record the refresh token
|
|
4763
|
+
* just proved possession of. Taking it from an access token's claims would let a caller aim a
|
|
4764
|
+
* revocation at the colliding id in another tenant, which is the same reasoning that already
|
|
4765
|
+
* kept the OWNER out of those claims.
|
|
4339
4766
|
*
|
|
4340
4767
|
* @param key - The un-namespaced session key (`rt:{hash}` or `prt:{hash}`).
|
|
4341
|
-
* @returns The recorded
|
|
4768
|
+
* @returns The recorded owner and tenant; `userId` is `''` when there is no usable record.
|
|
4342
4769
|
*/
|
|
4343
|
-
readSessionOwner(key: string): Promise<
|
|
4770
|
+
readSessionOwner(key: string): Promise<{
|
|
4771
|
+
userId: string;
|
|
4772
|
+
tenantId: string | undefined;
|
|
4773
|
+
}>;
|
|
4344
4774
|
/**
|
|
4345
4775
|
* Atomically advances the user's token epoch and returns the new value, invalidating every
|
|
4346
4776
|
* outstanding access token for that user at once.
|
|
@@ -4351,10 +4781,12 @@ declare class AuthRedisService {
|
|
|
4351
4781
|
* runs from the latest bump: by then every token stamped below it has expired anyway.
|
|
4352
4782
|
*
|
|
4353
4783
|
* @param userId - Internal user or admin ID whose outstanding access tokens are revoked.
|
|
4354
|
-
* @param
|
|
4784
|
+
* @param tenantId - The tenant the dashboard account belongs to; ignored on the platform plane.
|
|
4785
|
+
* @param kind - Which identity plane to bump. **Required** — the default was removed because
|
|
4786
|
+
* a positional plane beside a positional tenant is a transposition nobody notices.
|
|
4355
4787
|
* @returns The epoch after the increment.
|
|
4356
4788
|
*/
|
|
4357
|
-
bumpUserTokenEpoch(userId: string, kind
|
|
4789
|
+
bumpUserTokenEpoch(userId: string, tenantId: string | undefined, kind: 'dashboard' | 'platform'): Promise<number>;
|
|
4358
4790
|
/**
|
|
4359
4791
|
* Mints a single-use WebSocket upgrade ticket holding a verified-identity snapshot.
|
|
4360
4792
|
*
|
|
@@ -4397,6 +4829,17 @@ interface RevocableTokenPayload {
|
|
|
4397
4829
|
readonly sub: string;
|
|
4398
4830
|
/** The epoch the token was stamped with, if any; an absent or malformed value reads as 0. */
|
|
4399
4831
|
readonly epoch?: unknown;
|
|
4832
|
+
/**
|
|
4833
|
+
* The tenant the token was issued for; part of the per-user epoch key on the dashboard plane.
|
|
4834
|
+
*
|
|
4835
|
+
* Optional because the platform plane has none — its admins are cross-tenant — and the epoch
|
|
4836
|
+
* key derivation drops the segment there. On the DASHBOARD plane it is required, and this
|
|
4837
|
+
* service enforces that rather than trusting it: the mounted guards do refuse a dashboard token
|
|
4838
|
+
* without a tenant, but this service is exported for callers that never pass through one — a
|
|
4839
|
+
* realtime bridge checking a socket, for instance — and an optional field in a public contract
|
|
4840
|
+
* is a field somebody will omit.
|
|
4841
|
+
*/
|
|
4842
|
+
readonly tenantId?: string | undefined;
|
|
4400
4843
|
}
|
|
4401
4844
|
/**
|
|
4402
4845
|
* Answers whether an already-verified access token has been revoked, across both channels the auth
|
|
@@ -5155,8 +5598,25 @@ declare class WsJwtGuard implements CanActivate, OnModuleInit {
|
|
|
5155
5598
|
* stack detail or a connection string reaches a response body, so the answer carries the
|
|
5156
5599
|
* generic code and nothing else.
|
|
5157
5600
|
*
|
|
5601
|
+
* **Do not register this alongside `@bymax-one/nest-core`'s envelope filter.** They are mutually
|
|
5602
|
+
* exclusive in practice and this one wins: `useGlobalFilters` binds ahead of an `APP_FILTER`
|
|
5603
|
+
* provider, and `@Catch()` with no argument catches everything, so nest-core's filter never runs.
|
|
5604
|
+
* Measured on a composed application — the same request answers
|
|
5605
|
+
* `{error: {code, message, details}}` with this filter registered and the flat
|
|
5606
|
+
* `{statusCode, code, message, timestamp, path, details}` without it. A derived backend that
|
|
5607
|
+
* registers both therefore loses `statusCode`, `timestamp`, `path` and the correlation id, which
|
|
5608
|
+
* is the opposite of what registering an extra filter looks like it should do.
|
|
5609
|
+
*
|
|
5610
|
+
* Pick one. On a backend built on nest-core, take theirs: it already recognises this library's
|
|
5611
|
+
* envelope and passes the code, message and per-field details through unchanged.
|
|
5612
|
+
*
|
|
5613
|
+
* Nothing in this repository asserts that, and deliberately so — verifying it would mean this
|
|
5614
|
+
* library depending on a consumer's stack. The behaviour above was measured once and the
|
|
5615
|
+
* dependency removed; the standing assertion belongs to whoever composes the two.
|
|
5616
|
+
*
|
|
5158
5617
|
* @example
|
|
5159
5618
|
* ```typescript
|
|
5619
|
+
* // Only when nest-core's envelope filter is NOT in the application.
|
|
5160
5620
|
* app.useGlobalFilters(new AuthExceptionFilter())
|
|
5161
5621
|
* ```
|
|
5162
5622
|
*
|
|
@@ -5173,6 +5633,59 @@ declare class AuthExceptionFilter implements ExceptionFilter {
|
|
|
5173
5633
|
catch(exception: unknown, host: ArgumentsHost): void;
|
|
5174
5634
|
}
|
|
5175
5635
|
|
|
5636
|
+
/**
|
|
5637
|
+
* Gives a refused WebSocket client the library's error envelope instead of a generic failure.
|
|
5638
|
+
*
|
|
5639
|
+
* Register it on a gateway that applies {@link WsJwtGuard}. Without it, the guard's refusals do
|
|
5640
|
+
* not survive the transport: `AuthException` extends `HttpException`, Nest's WebSocket exception
|
|
5641
|
+
* layer understands only `WsException`, and everything else is delivered as
|
|
5642
|
+
* `{status: 'error', message: 'Internal server error'}` — so the whole `auth.*` catalogue stops
|
|
5643
|
+
* at the socket boundary.
|
|
5644
|
+
*
|
|
5645
|
+
* That is not only untidy. A client cannot tell a dead credential from a crashed handler, and a
|
|
5646
|
+
* reconnect policy has to choose: retrying an unknown error is the sensible default, so every
|
|
5647
|
+
* expired token becomes a reconnect loop against an endpoint that will refuse it forever. With
|
|
5648
|
+
* this filter the client reads `error.code` and can send the user to sign in instead.
|
|
5649
|
+
*
|
|
5650
|
+
* The payload keeps `status: 'error'` — the field Nest's own layer sets and every socket.io
|
|
5651
|
+
* client already branches on — and adds the envelope beside it, so a consumer handling both
|
|
5652
|
+
* shapes does not need a second listener:
|
|
5653
|
+
*
|
|
5654
|
+
* ```
|
|
5655
|
+
* without { status: 'error', message: 'Internal server error' }
|
|
5656
|
+
* with { status: 'error', error: { code: 'auth.token_invalid', message, details } }
|
|
5657
|
+
* ```
|
|
5658
|
+
*
|
|
5659
|
+
* **Scoped to `AuthException` on purpose.** An argument-less `@Catch()` would claim every
|
|
5660
|
+
* exception a gateway raises, so a `WsException` an unrelated handler throws — a domain error
|
|
5661
|
+
* with its own contract — would be rewritten as `auth.internal`, and following the README would
|
|
5662
|
+
* silently break a consumer's existing WebSocket errors. Everything that is not this library's
|
|
5663
|
+
* refusal keeps travelling through Nest's own exception layer.
|
|
5664
|
+
*
|
|
5665
|
+
* **Both transports.** A Socket.IO client is dispatched to with `emit`; a native `ws` client —
|
|
5666
|
+
* which also extends `EventEmitter`, so emitting on it succeeds and sends NOTHING — is written
|
|
5667
|
+
* to with `send`, in the `{event, data}` envelope `@nestjs/platform-ws` uses for every other
|
|
5668
|
+
* message. Both are driven over a real handshake in `test/e2e/ws-guard.e2e-spec.ts`.
|
|
5669
|
+
*
|
|
5670
|
+
* @example
|
|
5671
|
+
* ```typescript
|
|
5672
|
+
* @UseFilters(new WsAuthExceptionFilter())
|
|
5673
|
+
* @UseGuards(WsJwtGuard)
|
|
5674
|
+
* @WebSocketGateway()
|
|
5675
|
+
* export class FeedGateway { ... }
|
|
5676
|
+
* ```
|
|
5677
|
+
*/
|
|
5678
|
+
declare class WsAuthExceptionFilter implements ExceptionFilter {
|
|
5679
|
+
private readonly logger;
|
|
5680
|
+
/**
|
|
5681
|
+
* Delivers the library envelope to the client whose request was refused.
|
|
5682
|
+
*
|
|
5683
|
+
* @param exception - The `AuthException` a guard, pipe or handler raised.
|
|
5684
|
+
* @param host - The arguments host, used to reach the connected client.
|
|
5685
|
+
*/
|
|
5686
|
+
catch(exception: AuthException, host: ArgumentsHost): void;
|
|
5687
|
+
}
|
|
5688
|
+
|
|
5176
5689
|
/**
|
|
5177
5690
|
* @fileoverview The validation pipe every auth controller mounts.
|
|
5178
5691
|
*
|
|
@@ -5418,8 +5931,9 @@ declare class AcceptInvitationDto {
|
|
|
5418
5931
|
*
|
|
5419
5932
|
* Maximum 128 characters as a practical
|
|
5420
5933
|
* input bound to prevent DoS via pathological scrypt inputs.
|
|
5421
|
-
* The service layer hashes this value immediately — it is never logged or
|
|
5422
|
-
*
|
|
5934
|
+
* The service layer hashes this value immediately — it is never logged or persisted in plaintext
|
|
5935
|
+
* BY THIS LIBRARY. A breach checker you supply receives it by contract, and an error it raises
|
|
5936
|
+
* is a place it can be; see `PasswordService.assertNotCompromised` for the ceiling.
|
|
5423
5937
|
*/
|
|
5424
5938
|
password: string;
|
|
5425
5939
|
}
|
|
@@ -5719,7 +6233,14 @@ declare class RegisterDto {
|
|
|
5719
6233
|
*
|
|
5720
6234
|
* Maximum 128 characters as a practical
|
|
5721
6235
|
* input bound. The service layer hashes this value immediately after receipt —
|
|
5722
|
-
* it is never logged or persisted in plaintext.
|
|
6236
|
+
* it is never logged or persisted in plaintext BY THIS LIBRARY.
|
|
6237
|
+
*
|
|
6238
|
+
* **Exactly one consumer-supplied component receives it: the breach checker.** Both paths that
|
|
6239
|
+
* create a user hash first and pass only `passwordHash` to `IUserRepository.create`, and that
|
|
6240
|
+
* interface forbids receiving or storing plaintext. Naming the repository here would invite a
|
|
6241
|
+
* consumer to build one that takes it, which is the opposite of what the contract says — so the
|
|
6242
|
+
* only place the plaintext can surface is an error the breach checker raises. See
|
|
6243
|
+
* `PasswordService.assertNotCompromised` for the ceiling and how the library holds its own half.
|
|
5723
6244
|
*/
|
|
5724
6245
|
password: string;
|
|
5725
6246
|
/**
|
|
@@ -5816,6 +6337,23 @@ declare class ChangePasswordDto {
|
|
|
5816
6337
|
* Hashed immediately by the service layer — never persisted in plaintext.
|
|
5817
6338
|
*/
|
|
5818
6339
|
newPassword: string;
|
|
6340
|
+
/**
|
|
6341
|
+
* The caller's own refresh token, so the device making the change stays signed in.
|
|
6342
|
+
*
|
|
6343
|
+
* Declared because the handler reads it. `TokenDeliveryService.extractRefreshToken` takes it
|
|
6344
|
+
* from the refresh cookie under `tokenDelivery: 'cookie'` and from **this body field** under
|
|
6345
|
+
* `'bearer'`, cookie-first-then-body under `'both'` — and the controller pipe runs
|
|
6346
|
+
* `forbidNonWhitelisted: true`, so an undeclared property is refused. A bearer-mode caller
|
|
6347
|
+
* therefore could not send the field the endpoint needs: the request was answered
|
|
6348
|
+
* `auth.validation` naming `refreshToken`, and the only way to change a password was to give
|
|
6349
|
+
* up every other session.
|
|
6350
|
+
*
|
|
6351
|
+
* It stayed invisible because the E2E harness installed a global `ValidationPipe` with
|
|
6352
|
+
* `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
|
|
6353
|
+
* it — so the suite exercised a request production never sees. Optional, because under cookie
|
|
6354
|
+
* delivery the credential arrives in the cookie and no body field exists to declare.
|
|
6355
|
+
*/
|
|
6356
|
+
refreshToken?: string;
|
|
5819
6357
|
}
|
|
5820
6358
|
|
|
5821
6359
|
/**
|
|
@@ -6194,7 +6732,12 @@ declare class PasswordService {
|
|
|
6194
6732
|
* documented behaviour, and worst during an incident, when changing the password is the
|
|
6195
6733
|
* urgent thing. A refusal to answer is not evidence against the password.
|
|
6196
6734
|
*
|
|
6197
|
-
* The plaintext is
|
|
6735
|
+
* The plaintext is not passed to the logger, and neither is the checker's ERROR — which is the
|
|
6736
|
+
* part that took a measurement to learn. A breach checker receives the plaintext by contract, so
|
|
6737
|
+
* an error it raises is a place the plaintext can be: an HTTP client that echoes the request it
|
|
6738
|
+
* failed on, a validation error quoting the value it rejected. `logger.error(msg, err)` then
|
|
6739
|
+
* publishes that, plus the stack and whatever properties the client hung on it. Same shape as
|
|
6740
|
+
* the mail-channel leak this library fixed in `DefaultAuthEmailProvider`, one port over.
|
|
6198
6741
|
*
|
|
6199
6742
|
* @param plain - The plaintext password the user is trying to set.
|
|
6200
6743
|
* @throws {@link AuthException} with `PASSWORD_COMPROMISED` when the corpus knows it.
|
|
@@ -6270,6 +6813,67 @@ interface SessionInfo {
|
|
|
6270
6813
|
/** Unix timestamp in milliseconds of the most recent activity on this session. */
|
|
6271
6814
|
lastActivityAt: number;
|
|
6272
6815
|
}
|
|
6816
|
+
/**
|
|
6817
|
+
* Everything {@link SessionService.createSession} needs to record a session.
|
|
6818
|
+
*
|
|
6819
|
+
* An object rather than positional arguments, and the reason is the subject of this release: four
|
|
6820
|
+
* of the five fields are `string`, so any two of them can be swapped without the compiler
|
|
6821
|
+
* noticing. `createSession(userId, rawRefreshToken, ip, userAgent)` — the shape before the tenant
|
|
6822
|
+
* was threaded through — still type checks against a positional signature that inserted
|
|
6823
|
+
* `tenantId` second, and silently records the session under a tenant named by a refresh token.
|
|
6824
|
+
* A named field cannot be transposed; at worst it is misspelled, which is a compile error.
|
|
6825
|
+
*/
|
|
6826
|
+
interface CreateSessionParams {
|
|
6827
|
+
/** Internal user ID for whom the session is being created. */
|
|
6828
|
+
userId: string;
|
|
6829
|
+
/** Tenant that user belongs to; scopes the session index. */
|
|
6830
|
+
tenantId: string;
|
|
6831
|
+
/** The raw opaque refresh token; hashed before storage. */
|
|
6832
|
+
rawRefreshToken: string;
|
|
6833
|
+
/** Client IP address for the new session. */
|
|
6834
|
+
ip: string;
|
|
6835
|
+
/** Raw `User-Agent` header value, for device detection. */
|
|
6836
|
+
userAgent: string;
|
|
6837
|
+
}
|
|
6838
|
+
/** Everything {@link SessionService.listSessions} needs. See {@link CreateSessionParams}. */
|
|
6839
|
+
interface ListSessionsParams {
|
|
6840
|
+
/** Internal user ID whose sessions are being listed. */
|
|
6841
|
+
userId: string;
|
|
6842
|
+
/** Tenant that user belongs to; scopes the session index. */
|
|
6843
|
+
tenantId: string;
|
|
6844
|
+
/**
|
|
6845
|
+
* SHA-256 hash of the caller's active session, when known; the matching entry comes back with
|
|
6846
|
+
* `isCurrent: true`. Optional, which is what made the positional form dangerous — arity did not
|
|
6847
|
+
* catch a two-argument call.
|
|
6848
|
+
*
|
|
6849
|
+
* Written `?: string | undefined` rather than `?: string` because the project runs
|
|
6850
|
+
* `exactOptionalPropertyTypes`: under it the two are different types, and a caller forwarding a
|
|
6851
|
+
* value it already holds as `string | undefined` — which every controller reading an optional
|
|
6852
|
+
* header does — cannot assign to the narrower one.
|
|
6853
|
+
*/
|
|
6854
|
+
currentSessionHash?: string | undefined;
|
|
6855
|
+
}
|
|
6856
|
+
/**
|
|
6857
|
+
* Names one session to revoke, for {@link SessionService.revokeSession} and
|
|
6858
|
+
* {@link SessionService.revokeOtherSession}. See {@link CreateSessionParams}.
|
|
6859
|
+
*/
|
|
6860
|
+
interface RevokeSessionParams {
|
|
6861
|
+
/** Internal user ID that must own the session. */
|
|
6862
|
+
userId: string;
|
|
6863
|
+
/** Tenant that user belongs to; scopes the session index. */
|
|
6864
|
+
tenantId: string;
|
|
6865
|
+
/** SHA-256 hash of the session being revoked. */
|
|
6866
|
+
sessionHash: string;
|
|
6867
|
+
}
|
|
6868
|
+
/** Everything {@link SessionService.revokeAllExceptCurrent} needs. See {@link CreateSessionParams}. */
|
|
6869
|
+
interface RevokeAllExceptCurrentParams {
|
|
6870
|
+
/** Internal user ID whose other sessions are ending. */
|
|
6871
|
+
userId: string;
|
|
6872
|
+
/** Tenant that user belongs to; scopes the session index. */
|
|
6873
|
+
tenantId: string;
|
|
6874
|
+
/** SHA-256 hash of the session to KEEP — the caller's own. */
|
|
6875
|
+
currentSessionHash: string;
|
|
6876
|
+
}
|
|
6273
6877
|
/**
|
|
6274
6878
|
* Manages user session lifecycle for @bymax-one/nest-auth.
|
|
6275
6879
|
*
|
|
@@ -6295,6 +6899,27 @@ declare class SessionService {
|
|
|
6295
6899
|
private readonly redis;
|
|
6296
6900
|
private readonly logger;
|
|
6297
6901
|
constructor(options: ResolvedOptions, userRepo: IUserRepository, hooks: IAuthHooks | null, redis: AuthRedisService);
|
|
6902
|
+
/**
|
|
6903
|
+
* Refuses a dashboard tenant that names nothing, at the public boundary.
|
|
6904
|
+
*
|
|
6905
|
+
* Every method on this service takes the tenant as a REQUIRED named field, and all of them are
|
|
6906
|
+
* exported — the object form replaced the positional one precisely so a `string` tenant could
|
|
6907
|
+
* not be transposed with a `string` user id or session hash. Naming it removes the transposition
|
|
6908
|
+
* but not the empty string: a caller can still pass `''`, and that is what this refuses.
|
|
6909
|
+
*
|
|
6910
|
+
* `userSubject` cannot enforce it instead: the rotation scripts must be
|
|
6911
|
+
* called with the empty PLACEHOLDER identity to discover a grace pointer, so the innermost
|
|
6912
|
+
* builder has to stay total, and an empty key in a script's KEYS array is not "no key" — the
|
|
6913
|
+
* `eval` wrapper prefixes it into a real key named `auth:`.
|
|
6914
|
+
*
|
|
6915
|
+
* So the refusal lives here, where a caller can actually be wrong. `''` derived
|
|
6916
|
+
* `dashboard:0::{userId}`, swept and bumped keys nobody writes, and returned normally — a
|
|
6917
|
+
* revocation reported as done while every session and access token it named stayed valid.
|
|
6918
|
+
*
|
|
6919
|
+
* @param tenantId - The tenant supplied by the caller.
|
|
6920
|
+
* @throws {@link AuthException} `VALIDATION` when it is blank.
|
|
6921
|
+
*/
|
|
6922
|
+
private assertTenant;
|
|
6298
6923
|
/**
|
|
6299
6924
|
* Records a new session in Redis and enforces the concurrent session limit.
|
|
6300
6925
|
*
|
|
@@ -6312,13 +6937,10 @@ declare class SessionService {
|
|
|
6312
6937
|
* before the SET member is committed, the limit check will see one fewer
|
|
6313
6938
|
* session than actually exists, allowing a permanent extra session.
|
|
6314
6939
|
*
|
|
6315
|
-
* @param
|
|
6316
|
-
* @param rawRefreshToken - The raw opaque refresh token (hashed before storage).
|
|
6317
|
-
* @param ip - Client IP address for the new session.
|
|
6318
|
-
* @param userAgent - Raw `User-Agent` header value for device detection.
|
|
6940
|
+
* @param params - See {@link CreateSessionParams}.
|
|
6319
6941
|
* @returns The SHA-256 hash of `rawRefreshToken` used as the session key.
|
|
6320
6942
|
*/
|
|
6321
|
-
createSession(userId
|
|
6943
|
+
createSession({ userId, tenantId, rawRefreshToken, ip, userAgent }: CreateSessionParams): Promise<string>;
|
|
6322
6944
|
/**
|
|
6323
6945
|
* Lists all active sessions for a user, enriched with device and activity metadata.
|
|
6324
6946
|
*
|
|
@@ -6332,12 +6954,10 @@ declare class SessionService {
|
|
|
6332
6954
|
*
|
|
6333
6955
|
* Results are sorted by `createdAt` descending (newest session first).
|
|
6334
6956
|
*
|
|
6335
|
-
* @param
|
|
6336
|
-
* @param currentSessionHash - Optional SHA-256 hash of the caller's active session;
|
|
6337
|
-
* matched session will have `isCurrent: true`.
|
|
6957
|
+
* @param params - See {@link ListSessionsParams}.
|
|
6338
6958
|
* @returns Array of {@link SessionInfo} sorted newest-first.
|
|
6339
6959
|
*/
|
|
6340
|
-
listSessions(userId
|
|
6960
|
+
listSessions({ userId, tenantId, currentSessionHash }: ListSessionsParams): Promise<SessionInfo[]>;
|
|
6341
6961
|
/**
|
|
6342
6962
|
* Revokes a single session belonging to the specified user.
|
|
6343
6963
|
*
|
|
@@ -6350,7 +6970,7 @@ declare class SessionService {
|
|
|
6350
6970
|
* @param sessionHash - SHA-256 hash of the refresh token identifying the session.
|
|
6351
6971
|
* @throws {@link AuthException} `SESSION_NOT_FOUND` when the session is not owned by the user.
|
|
6352
6972
|
*/
|
|
6353
|
-
revokeSession(userId
|
|
6973
|
+
revokeSession({ userId, tenantId, sessionHash }: RevokeSessionParams): Promise<void>;
|
|
6354
6974
|
/**
|
|
6355
6975
|
* Revokes one named session **other than the caller's own**, and cuts the access tokens with
|
|
6356
6976
|
* it.
|
|
@@ -6375,7 +6995,7 @@ declare class SessionService {
|
|
|
6375
6995
|
* @param sessionHash - SHA-256 hash of the refresh token identifying the session.
|
|
6376
6996
|
* @throws {@link AuthException} `SESSION_NOT_FOUND` when the session is not owned by the user.
|
|
6377
6997
|
*/
|
|
6378
|
-
revokeOtherSession(userId
|
|
6998
|
+
revokeOtherSession({ userId, tenantId, sessionHash }: RevokeSessionParams): Promise<void>;
|
|
6379
6999
|
/**
|
|
6380
7000
|
* Revokes all sessions for a user except the caller's current session.
|
|
6381
7001
|
*
|
|
@@ -6403,7 +7023,7 @@ declare class SessionService {
|
|
|
6403
7023
|
* @throws {unknown} Propagates any error thrown by `revokeSession` — including
|
|
6404
7024
|
* {@link AuthException} with various codes, Redis errors, or other runtime errors.
|
|
6405
7025
|
*/
|
|
6406
|
-
revokeAllExceptCurrent(userId
|
|
7026
|
+
revokeAllExceptCurrent({ userId, tenantId, currentSessionHash }: RevokeAllExceptCurrentParams): Promise<void>;
|
|
6407
7027
|
/**
|
|
6408
7028
|
* Rotates the session detail record from the old token hash to the new one.
|
|
6409
7029
|
*
|
|
@@ -6425,8 +7045,9 @@ declare class SessionService {
|
|
|
6425
7045
|
* @param newHash - SHA-256 hex hash of the newly issued refresh token.
|
|
6426
7046
|
* @param ip - Client IP address from the current request.
|
|
6427
7047
|
* @param userAgent - Raw `User-Agent` header value from the current request.
|
|
6428
|
-
* @throws {@link AuthException} `
|
|
6429
|
-
*
|
|
7048
|
+
* @throws {@link AuthException} `VALIDATION` when either hash is not a valid 64-character
|
|
7049
|
+
* lowercase hex string. The `details` name which one — `oldHash` or `newHash` — because a
|
|
7050
|
+
* caller told only that "a hash" was malformed cannot act on it.
|
|
6430
7051
|
*/
|
|
6431
7052
|
rotateSession(oldHash: string, newHash: string, ip: string, userAgent: string): Promise<void>;
|
|
6432
7053
|
/**
|
|
@@ -6437,14 +7058,36 @@ declare class SessionService {
|
|
|
6437
7058
|
* attacker-controlled key names.
|
|
6438
7059
|
*
|
|
6439
7060
|
* @remarks
|
|
6440
|
-
* `SESSION_NOT_FOUND
|
|
6441
|
-
* callers
|
|
6442
|
-
*
|
|
7061
|
+
* **This used to answer `SESSION_NOT_FOUND`, and that was wrong.** The stated reason was to stop
|
|
7062
|
+
* callers enumerating valid hash formats — but the format is not a secret. It is 64 hex
|
|
7063
|
+
* characters, `SessionInfo.sessionHash` publishes it on every listed session, and the route's
|
|
7064
|
+
* own documentation describes it. Nothing is protected by hiding it, and the pairing had a real
|
|
7065
|
+
* cost: a consumer sending a malformed hash got the same answer as one sending a hash that had
|
|
7066
|
+
* already been revoked, so a UI bug read as a race between the session list and the click. That
|
|
7067
|
+
* is measured, not hypothetical — it cost a consumer session twenty minutes chasing a race that
|
|
7068
|
+
* cannot happen.
|
|
7069
|
+
*
|
|
7070
|
+
* A malformed hash is a caller error and now says so. A well-formed hash that names nothing
|
|
7071
|
+
* still answers `SESSION_NOT_FOUND`, which is where the no-enumeration argument does apply:
|
|
7072
|
+
* that one really would tell the caller whether a session exists.
|
|
6443
7073
|
*
|
|
6444
7074
|
* @param sessionHash - The session hash to validate.
|
|
6445
|
-
* @throws {@link AuthException} `
|
|
7075
|
+
* @throws {@link AuthException} `VALIDATION` when the value is not 64 lowercase hex characters.
|
|
6446
7076
|
*/
|
|
6447
7077
|
private assertValidSessionHash;
|
|
7078
|
+
/**
|
|
7079
|
+
* The Redis key of this user's session index.
|
|
7080
|
+
*
|
|
7081
|
+
* Derived rather than interpolated, and tenant-scoped: `IUserRepository.findById` takes a
|
|
7082
|
+
* tenant because ids may only be unique within one, so a bare-id index let a revoke aimed at
|
|
7083
|
+
* one tenant's user empty another's. The derivation lives in `user-keys.ts` because rust-auth
|
|
7084
|
+
* reads the same key from the same contract.
|
|
7085
|
+
*
|
|
7086
|
+
* @param userId - The account whose sessions the index tracks.
|
|
7087
|
+
* @param tenantId - The tenant that account belongs to.
|
|
7088
|
+
* @returns The un-namespaced index key.
|
|
7089
|
+
*/
|
|
7090
|
+
private indexKey;
|
|
6448
7091
|
/**
|
|
6449
7092
|
* Enforces the concurrent session limit for a user by evicting the oldest
|
|
6450
7093
|
* sessions (FIFO) when the limit has been exceeded.
|
|
@@ -6462,6 +7105,7 @@ declare class SessionService {
|
|
|
6462
7105
|
* risk is low for most `defaultMaxSessions` values (≥ 2).
|
|
6463
7106
|
*
|
|
6464
7107
|
* @param userId - Internal user ID whose session count is being checked.
|
|
7108
|
+
* @param tenantId - The tenant that user belongs to; part of the index key.
|
|
6465
7109
|
* @param newHash - SHA-256 hash of the newly issued refresh token (excluded from eviction).
|
|
6466
7110
|
* @param ip - Client IP address (forwarded to the `onSessionEvicted` hook context).
|
|
6467
7111
|
* @param userAgent - User-Agent string (forwarded to the `onSessionEvicted` hook context).
|
|
@@ -6484,6 +7128,7 @@ declare class SessionService {
|
|
|
6484
7128
|
* *thrown* resolver was ever caught.
|
|
6485
7129
|
*
|
|
6486
7130
|
* @param userId - Internal user ID to resolve the limit for.
|
|
7131
|
+
* @param tenantId - Tenant that user belongs to; scopes the lookup behind the resolver.
|
|
6487
7132
|
* @returns Maximum allowed concurrent sessions for the given user.
|
|
6488
7133
|
*/
|
|
6489
7134
|
private resolveSessionLimit;
|
|
@@ -6633,8 +7278,45 @@ declare class TokenManagerService {
|
|
|
6633
7278
|
* The owner is read from the stored session where it can be — a replay of a token whose live
|
|
6634
7279
|
* key is already gone leaves nothing to read, and the hook is skipped rather than fired with
|
|
6635
7280
|
* an empty identity that a consumer would have to guess about.
|
|
7281
|
+
*
|
|
7282
|
+
* **The context describes WHO PRESENTED the replayed token**, which is the whole reason a
|
|
7283
|
+
* consumer subscribes to this hook. `userId` says whose account the family belongs to; `ip` and
|
|
7284
|
+
* `userAgent` are the only description of the party holding the token that should not exist, so
|
|
7285
|
+
* a report carrying the first and not the second says a compromise happened and gives nothing
|
|
7286
|
+
* to act on. Both were previously dropped: the emit built an EMPTY context while
|
|
7287
|
+
* `reissueTokens` had both values in scope as its own parameters.
|
|
7288
|
+
*
|
|
7289
|
+
* `sanitizedHeaders` stays empty and that is honest — the rotation path receives the address
|
|
7290
|
+
* and the agent, never the header map, so there is nothing to sanitize. Inventing one would be
|
|
7291
|
+
* worse than an empty object a consumer can see is empty.
|
|
7292
|
+
*
|
|
7293
|
+
* @param userId - The account the revoked family belonged to.
|
|
7294
|
+
* @param familyId - The revoked family.
|
|
7295
|
+
* @param ip - Address the replayed token was presented from.
|
|
7296
|
+
* @param userAgent - Raw `User-Agent` of the presenting client.
|
|
6636
7297
|
*/
|
|
6637
7298
|
private emitReuseDetected;
|
|
7299
|
+
/**
|
|
7300
|
+
* Refuses to rotate a dashboard session whose record names no tenant.
|
|
7301
|
+
*
|
|
7302
|
+
* `parseSession` validates `userId`, `role` and `mfaEnabled` but not `tenantId`, so a record
|
|
7303
|
+
* written before the index carried one reaches here with the field absent. Rotating it would do
|
|
7304
|
+
* two wrong things at once: write the new session under `dashboard:9:undefined:{userId}`, an
|
|
7305
|
+
* index belonging to no tenant and swept by no revoke-all, and mint an access token with no
|
|
7306
|
+
* tenant claim — which every dashboard guard then refuses, so the caller gets a session that
|
|
7307
|
+
* cannot be used and cannot be revoked.
|
|
7308
|
+
*
|
|
7309
|
+
* Refusing is the same answer the migration note gives: a pre-upgrade session dies and the user
|
|
7310
|
+
* signs in again. That is a cost; rotating into a keyspace nobody sweeps is a hole.
|
|
7311
|
+
*
|
|
7312
|
+
* The platform plane is exempt — its subject carries no tenant segment by design.
|
|
7313
|
+
*
|
|
7314
|
+
* @param session - The seed session read from the presented token.
|
|
7315
|
+
* @throws {@link AuthException} with `REFRESH_TOKEN_INVALID`, indistinguishable from any other
|
|
7316
|
+
* invalid refresh: the remedy is the same and the difference would only tell a token holder
|
|
7317
|
+
* how old the record is.
|
|
7318
|
+
*/
|
|
7319
|
+
private assertRotatableTenant;
|
|
6638
7320
|
/**
|
|
6639
7321
|
* Refuses a rotation once the login it descends from has outlived the absolute cap.
|
|
6640
7322
|
*
|
|
@@ -6737,7 +7419,21 @@ declare class TokenManagerService {
|
|
|
6737
7419
|
* The `status` claim in the issued access token is intentionally empty during
|
|
6738
7420
|
* rotation — the Redis session does not store full user data. Guards that enforce
|
|
6739
7421
|
* status checks must read from the user repository or a status cache, not the
|
|
6740
|
-
* JWT `status` claim.
|
|
7422
|
+
* JWT `status` claim. `rust-auth` stamps the same empty string at the same point, with a
|
|
7423
|
+
* test pinning it, so this is a shared contract rather than a local shortcut.
|
|
7424
|
+
*
|
|
7425
|
+
* **What that means for a consumer, which is where the cost lands.** `issueTokens` stamps the
|
|
7426
|
+
* account's value at that moment, this path stamps nothing, and `AuthService.refresh` re-stamps
|
|
7427
|
+
* it from the account when `role`, `tenantId` or `mfaEnabled` changed — so a session's tokens
|
|
7428
|
+
* carry a populated claim, then an empty one, then possibly a populated one again, with no
|
|
7429
|
+
* signal a client can read. A derived backend reading `request.user.status` is wrong in both
|
|
7430
|
+
* directions: `!== 'active'` refuses everyone whose session refreshed ordinarily, and
|
|
7431
|
+
* `=== 'suspended'` refuses nobody, ever.
|
|
7432
|
+
*
|
|
7433
|
+
* Backfilling it here would be worse than leaving it empty: the claim would become *usually*
|
|
7434
|
+
* true, which is the failure mode that survives testing, since status can still change under an
|
|
7435
|
+
* unexpired token. The claim cannot be authoritative, so it is not made to look like it — and
|
|
7436
|
+
* the empty string is the one state that cannot be mistaken for an answer.
|
|
6741
7437
|
*
|
|
6742
7438
|
* `mfaVerified` is always `false` after rotation because the Redis session does not
|
|
6743
7439
|
* persist MFA verification state. A user who authenticated with MFA will lose the
|
|
@@ -6878,10 +7574,9 @@ declare class TokenManagerService {
|
|
|
6878
7574
|
* @param token - The MFA temp JWT issued by {@link issueMfaTempToken}.
|
|
6879
7575
|
* @returns The `userId`, `context`, and `jti` from the token. Pass the
|
|
6880
7576
|
* `jti` to {@link consumeMfaTempToken} after TOTP validation succeeds.
|
|
6881
|
-
* @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID`
|
|
6882
|
-
*
|
|
6883
|
-
*
|
|
6884
|
-
* directly from `JwtService.verify()` — not wrapped in {@link AuthException}).
|
|
7577
|
+
* @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID` for every way the token can be
|
|
7578
|
+
* unusable — a bad signature, an expired one, a shape no secret accepts, or a missing Redis
|
|
7579
|
+
* entry (already consumed, expired, or never issued).
|
|
6885
7580
|
*/
|
|
6886
7581
|
verifyMfaTempToken(token: string): Promise<{
|
|
6887
7582
|
userId: string;
|
|
@@ -6904,6 +7599,21 @@ declare class TokenManagerService {
|
|
|
6904
7599
|
consumeMfaTempToken(jti: string): Promise<boolean>;
|
|
6905
7600
|
}
|
|
6906
7601
|
|
|
7602
|
+
/**
|
|
7603
|
+
* Names the account whose sessions {@link AuthService.revokeAllSessions} ends.
|
|
7604
|
+
*
|
|
7605
|
+
* An object for the same reason the five `SessionService` entry points take one: two
|
|
7606
|
+
* unconstrained `string`s side by side can be swapped without the compiler noticing, and
|
|
7607
|
+
* `revokeAllSessions(user.tenantId, user.id)` compiled, derived an unrelated subject, and
|
|
7608
|
+
* returned normally — a "sign out everywhere" reported as done that revoked nothing, or that
|
|
7609
|
+
* revoked a colliding account instead.
|
|
7610
|
+
*/
|
|
7611
|
+
interface RevokeAllSessionsParams {
|
|
7612
|
+
/** Internal user ID whose sessions and access tokens are ending. */
|
|
7613
|
+
userId: string;
|
|
7614
|
+
/** Tenant that user belongs to; scopes both the session index and the token epoch. */
|
|
7615
|
+
tenantId: string;
|
|
7616
|
+
}
|
|
6907
7617
|
/**
|
|
6908
7618
|
* Core authentication service for dashboard (tenant) users.
|
|
6909
7619
|
*
|
|
@@ -7058,17 +7768,21 @@ declare class AuthService {
|
|
|
7058
7768
|
* The epoch is bumped after the sweep, not before: a failure in the sweep then leaves the
|
|
7059
7769
|
* operation visibly incomplete rather than reading as done while the sessions live on.
|
|
7060
7770
|
*
|
|
7061
|
-
* @param
|
|
7771
|
+
* @param params - See {@link RevokeAllSessionsParams}. Both keyspaces are scoped to the tenant,
|
|
7772
|
+
* so naming the wrong one revokes the colliding id in another tenant instead.
|
|
7773
|
+
* @throws {@link AuthException} `VALIDATION` when the tenant is blank.
|
|
7062
7774
|
*/
|
|
7063
|
-
revokeAllSessions(userId:
|
|
7775
|
+
revokeAllSessions({ userId, tenantId }: RevokeAllSessionsParams): Promise<void>;
|
|
7064
7776
|
/**
|
|
7065
7777
|
* Retrieves the full safe user record for the currently authenticated user.
|
|
7066
7778
|
*
|
|
7067
7779
|
* @param userId - Subject claim from the verified JWT.
|
|
7780
|
+
* @param tenantId - Tenant claim from the same token; scopes the lookup, because a repository
|
|
7781
|
+
* id is unique only within a tenant.
|
|
7068
7782
|
* @returns Safe user object (credential fields excluded).
|
|
7069
7783
|
* @throws {@link AuthException} with `TOKEN_INVALID` if the user no longer exists.
|
|
7070
7784
|
*/
|
|
7071
|
-
getMe(userId: string): Promise<SafeAuthUser>;
|
|
7785
|
+
getMe(userId: string, tenantId: string): Promise<SafeAuthUser>;
|
|
7072
7786
|
/**
|
|
7073
7787
|
* Issues a full dashboard session for an existing user **without** verifying
|
|
7074
7788
|
* a password. Used by consumer applications that implement
|
|
@@ -7113,7 +7827,7 @@ declare class AuthService {
|
|
|
7113
7827
|
* @throws `MFA_REQUIRED` when the target user has MFA enabled — the
|
|
7114
7828
|
* consumer must route through the MFA challenge flow for that user.
|
|
7115
7829
|
*/
|
|
7116
|
-
issueTokensForUserId(userId: string, ip: string, userAgent: string): Promise<AuthResult>;
|
|
7830
|
+
issueTokensForUserId(userId: string, tenantId: string, ip: string, userAgent: string): Promise<AuthResult>;
|
|
7117
7831
|
/**
|
|
7118
7832
|
* Verifies the user's email address using a one-time password.
|
|
7119
7833
|
*
|
|
@@ -7165,6 +7879,61 @@ declare class AuthService {
|
|
|
7165
7879
|
* @param tenantId - The tenant the account belongs to.
|
|
7166
7880
|
*/
|
|
7167
7881
|
unlockAccount(email: string, tenantId: string): Promise<void>;
|
|
7882
|
+
/**
|
|
7883
|
+
* Reports whether an account is currently locked out by brute-force protection.
|
|
7884
|
+
*
|
|
7885
|
+
* The counterpart to {@link unlockAccount}, and the reason it exists: the write side was
|
|
7886
|
+
* public while the read side was not, so a host could offer an Unlock control and could not
|
|
7887
|
+
* tell anyone whether it had anything to do.
|
|
7888
|
+
*
|
|
7889
|
+
* A consumer cannot derive this themselves even with the source in hand. The counter is keyed
|
|
7890
|
+
* by an HMAC of `dashboard:{tenantId}:{email}` under the library's own `hmacKey`, which is
|
|
7891
|
+
* derived rather than supplied — and reproducing the preimage is precisely what keeping the
|
|
7892
|
+
* derivation in one place prevents. A third copy in a consumer repository is a third chance to
|
|
7893
|
+
* drift, and the failure is silent: a key that never exists reads as "not locked out" for every
|
|
7894
|
+
* account, including locked ones. A false negative on a security indicator, reported
|
|
7895
|
+
* confidently.
|
|
7896
|
+
*
|
|
7897
|
+
* **Cheap enough to put on every row of a list, with one caveat that is the host's.** Issuing
|
|
7898
|
+
* these concurrently overlaps the waits, so twenty of them cost close to what one costs; issuing
|
|
7899
|
+
* them with `await` inside a loop serialises the round trips and cost sixteen times as much when
|
|
7900
|
+
* the reporter measured it against a local Redis. That ratio is a property of concurrency, not a
|
|
7901
|
+
* guarantee this library makes: each call is its own Redis command, the ioredis client is
|
|
7902
|
+
* supplied by the host, and whether those commands are also BATCHED into one write depends on
|
|
7903
|
+
* `enableAutoPipelining`, which ioredis leaves off by default. Use `Promise.all`; do not treat
|
|
7904
|
+
* any absolute number here as a contract.
|
|
7905
|
+
*
|
|
7906
|
+
* Like {@link unlockAccount}, this ships **no route**. Whether a caller may ask about an account
|
|
7907
|
+
* they do not own is a decision only the host can make, and a lockout flag reachable without
|
|
7908
|
+
* authorisation is an oracle about other people's accounts.
|
|
7909
|
+
*
|
|
7910
|
+
* @param email - The account's address. Normalized here exactly as login normalizes it, or the
|
|
7911
|
+
* derived key misses the counter the lockout actually wrote.
|
|
7912
|
+
* @param tenantId - The tenant the account belongs to.
|
|
7913
|
+
* @returns `true` while the account is locked out.
|
|
7914
|
+
*/
|
|
7915
|
+
isAccountLockedOut(email: string, tenantId: string): Promise<boolean>;
|
|
7916
|
+
/**
|
|
7917
|
+
* Reports how many seconds remain on an account's lockout.
|
|
7918
|
+
*
|
|
7919
|
+
* Separate from {@link isAccountLockedOut} because a bare flag with no horizon is the interface
|
|
7920
|
+
* that invites the support call the indicator was meant to prevent: it says an account is
|
|
7921
|
+
* locked and cannot say for how long, so the only honest advice is "try again later".
|
|
7922
|
+
*
|
|
7923
|
+
* **Gated on the lockout, not merely on the key.** `BruteForceService.getRemainingLockoutSeconds`
|
|
7924
|
+
* returns the TTL of the failure counter, and `recordFailure` creates that counter on the FIRST
|
|
7925
|
+
* failure — so the raw TTL is positive from one failed attempt onward, long before the threshold
|
|
7926
|
+
* is reached. Returned unchecked it would tell a console "locked for 14 minutes" about an
|
|
7927
|
+
* account that is not locked and whose next attempt would succeed. The threshold is therefore
|
|
7928
|
+
* read first, which costs a second Redis command only on the accounts that are actually locked.
|
|
7929
|
+
*
|
|
7930
|
+
* Ships no route, for the reason given on {@link isAccountLockedOut}.
|
|
7931
|
+
*
|
|
7932
|
+
* @param email - The account's address, normalized here as login normalizes it.
|
|
7933
|
+
* @param tenantId - The tenant the account belongs to.
|
|
7934
|
+
* @returns Seconds until the lockout expires, or `0` when the account is not locked out.
|
|
7935
|
+
*/
|
|
7936
|
+
getAccountLockoutSeconds(email: string, tenantId: string): Promise<number>;
|
|
7168
7937
|
/**
|
|
7169
7938
|
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
7170
7939
|
*
|
|
@@ -7329,6 +8098,8 @@ declare class EmailChangeService implements OnModuleInit {
|
|
|
7329
8098
|
* new address. Nothing about the account changes until that token comes back.
|
|
7330
8099
|
*
|
|
7331
8100
|
* @param userId - The authenticated caller, from their own claims — never the body.
|
|
8101
|
+
* @param tenantId - The tenant that caller belongs to, from the same claims; scopes the
|
|
8102
|
+
* account read, because a repository id is unique only within a tenant.
|
|
7332
8103
|
* @param dto - The new address and the current password.
|
|
7333
8104
|
* @throws {@link AuthException} `INVALID_CREDENTIALS` when the account has no local password
|
|
7334
8105
|
* or the submitted one is wrong — the same code a failed login returns, so a thief holding
|
|
@@ -7336,7 +8107,7 @@ declare class EmailChangeService implements OnModuleInit {
|
|
|
7336
8107
|
* @throws {@link AuthException} `EMAIL_ALREADY_EXISTS` when the address is the account's own
|
|
7337
8108
|
* or belongs to another account in the tenant.
|
|
7338
8109
|
*/
|
|
7339
|
-
requestChange(userId: string, dto: ChangeEmailDto): Promise<void>;
|
|
8110
|
+
requestChange(userId: string, tenantId: string, dto: ChangeEmailDto): Promise<void>;
|
|
7340
8111
|
/**
|
|
7341
8112
|
* Completes an address change against a token that came back from the new address.
|
|
7342
8113
|
*
|
|
@@ -7803,10 +8574,14 @@ declare class MfaService {
|
|
|
7803
8574
|
/**
|
|
7804
8575
|
* Verifies a TOTP code and enforces anti-replay within the validation window.
|
|
7805
8576
|
*
|
|
7806
|
-
* Stores a Redis key `tu:{hmac}` where `hmac = hmacSha256("{
|
|
7807
|
-
*
|
|
7808
|
-
* rejected as a replay.
|
|
7809
|
-
*
|
|
8577
|
+
* Stores a Redis key `tu:{hmac}` where `hmac = hmacSha256("{userSubject}:{code}", hmacKey)` —
|
|
8578
|
+
* so the marker is scoped to the plane and, on the dashboard plane, to the tenant. A second
|
|
8579
|
+
* submission of the same code within the TTL is rejected as a replay. Binding the marker to
|
|
8580
|
+
* both the subject and the code value prevents code disclosure in Redis and cross-user,
|
|
8581
|
+
* cross-tenant and cross-plane replay alike.
|
|
8582
|
+
*
|
|
8583
|
+
* A second marker under the pre-scoping preimage `{context}:{userId}:{code}` is written and
|
|
8584
|
+
* required alongside it; see the call site for why both must be fresh during a rolling upgrade.
|
|
7810
8585
|
*
|
|
7811
8586
|
* @returns `true` if the code is valid and has not been replayed, `false` otherwise.
|
|
7812
8587
|
*/
|
|
@@ -7837,31 +8612,19 @@ declare class MfaService {
|
|
|
7837
8612
|
*/
|
|
7838
8613
|
private assertReauthenticated;
|
|
7839
8614
|
/**
|
|
7840
|
-
*
|
|
7841
|
-
* account is blocked.
|
|
7842
|
-
*
|
|
7843
|
-
* The status gate lives here rather than in each caller because every entry point that
|
|
7844
|
-
* reaches this method changes or spends an authentication factor, and every one of them
|
|
7845
|
-
* must refuse a suspended or banned account. It used to live in `challenge` alone, so
|
|
7846
|
-
* `setup`, `verifyAndEnable`, `disable` and `regenerateRecoveryCodes` had no gate at all:
|
|
7847
|
-
* an operator who suspended a compromised account bought nothing against an attacker still
|
|
7848
|
-
* holding an unexpired access token, who could turn the second factor off — or enrol their
|
|
7849
|
-
* own authenticator over it — for the token's remaining lifetime. Nothing else covers that
|
|
7850
|
-
* window: no status change bumps the token epoch, so the per-request check is the only
|
|
7851
|
-
* defence, and neither MFA controller composes `UserStatusGuard` (the platform plane has no
|
|
7852
|
-
* status guard at all). Every other authority-bearing route in the library does gate on
|
|
7853
|
-
* status; changing an authentication factor is at least as privileged as minting an
|
|
7854
|
-
* invitation.
|
|
8615
|
+
* Asserts a dashboard-plane call carries a tenant, narrowing it to `string` for the caller.
|
|
7855
8616
|
*
|
|
7856
|
-
*
|
|
7857
|
-
*
|
|
8617
|
+
* This is the dashboard half of {@link assertPlaneTenant}, split out for one reason: an
|
|
8618
|
+
* assertion signature is the only way to state "past this point the tenant is present" to the
|
|
8619
|
+
* type system. `IUserRepository.findById` requires the tenant, and the account read behind the
|
|
8620
|
+
* MFA flows sits under a `context === 'dashboard'` branch where a `void` guard run earlier in
|
|
8621
|
+
* the caller has narrowed nothing. Without this the branch had to pass `string | undefined`
|
|
8622
|
+
* into a `string` parameter, which is precisely the tenant-blind read the guard exists to stop.
|
|
7858
8623
|
*
|
|
7859
|
-
* @param
|
|
7860
|
-
* @
|
|
7861
|
-
* @returns The account record, guaranteed to be in good standing.
|
|
7862
|
-
* @throws `TOKEN_INVALID` if the user is not found.
|
|
7863
|
-
* @throws {@link AuthException} the status error when the account is blocked.
|
|
8624
|
+
* @param tenantId - The tenant supplied by the caller, if any.
|
|
8625
|
+
* @throws {@link AuthException} `VALIDATION` (400) when it is missing or blank.
|
|
7864
8626
|
*/
|
|
8627
|
+
private assertDashboardTenant;
|
|
7865
8628
|
/**
|
|
7866
8629
|
* A dashboard MFA flow MUST carry the tenant it was authenticated in; a platform flow MUST NOT.
|
|
7867
8630
|
*
|
|
@@ -7885,7 +8648,7 @@ declare class MfaService {
|
|
|
7885
8648
|
*
|
|
7886
8649
|
* A rolling upgrade runs old and new code against one Redis at once: on the dashboard plane an
|
|
7887
8650
|
* old pod counts a failure under `{flow}:{plane}:{userId}` while a new pod counts it under
|
|
7888
|
-
* `{flow}:{
|
|
8651
|
+
* `{flow}:{userSubject}`, and either alone leaves a hole — a lockout an old pod filled would not
|
|
7889
8652
|
* stop a new pod, and a success on one would not clear the other. For one release every read
|
|
7890
8653
|
* consults both and every write touches both, so the two move as one; a later release drops the
|
|
7891
8654
|
* legacy arm. On the platform plane the two ids are identical (no tenant ever entered the
|
|
@@ -7909,6 +8672,58 @@ declare class MfaService {
|
|
|
7909
8672
|
* legitimately authenticated user out on the next attempt — collapsing to one when they coincide.
|
|
7910
8673
|
*/
|
|
7911
8674
|
private resetMfaFlowFailures;
|
|
8675
|
+
/**
|
|
8676
|
+
* Sends an MFA state-change notice, fire-and-forget, with the recipient kept out of the log.
|
|
8677
|
+
*
|
|
8678
|
+
* **Not awaited, and that is the fix, not a shortcut.** These three sends used to be awaited
|
|
8679
|
+
* with no `catch`, so a rejected delivery travelled out of the service to `AuthExceptionFilter`
|
|
8680
|
+
* — which answered the caller with an error for an operation that had ALREADY completed. By
|
|
8681
|
+
* that point the secret is written, the sessions are invalidated and the token epoch is bumped;
|
|
8682
|
+
* the user's second factor is on, and telling them it failed is how they end up locked out of
|
|
8683
|
+
* an account they just secured. `PasswordResetService.notifyPasswordChanged` had reached the
|
|
8684
|
+
* same conclusion for the same reason.
|
|
8685
|
+
*
|
|
8686
|
+
* **And the address does not reach the log.** The filter logged that error raw, and an SMTP
|
|
8687
|
+
* rejection routinely NAMES the recipient it refused (`550 user@example.com: recipient
|
|
8688
|
+
* rejected`) — no quoted body required, which makes it the likeliest exposure of the set.
|
|
8689
|
+
* `describeChannelStatus` publishes nothing the channel wrote, and nothing parsed off it either,
|
|
8690
|
+
* so no part of that name comes through. `withheld` covers the fields this line composes rather than the error, and
|
|
8691
|
+
* `safeLogLine` checks the seam the template opens between them.
|
|
8692
|
+
*
|
|
8693
|
+
* @param origin - The calling flow, for the log line.
|
|
8694
|
+
* @param userId - Whose account changed.
|
|
8695
|
+
* @param user - The account, read for its tenant and address.
|
|
8696
|
+
* @param send - Which notice to dispatch.
|
|
8697
|
+
*/
|
|
8698
|
+
private notify;
|
|
8699
|
+
/**
|
|
8700
|
+
* Fetches a user from the correct repository based on the MFA context, and refuses one whose
|
|
8701
|
+
* account is blocked.
|
|
8702
|
+
*
|
|
8703
|
+
* The status gate lives here rather than in each caller because every entry point that
|
|
8704
|
+
* reaches this method changes or spends an authentication factor, and every one of them
|
|
8705
|
+
* must refuse a suspended or banned account. It used to live in `challenge` alone, so
|
|
8706
|
+
* `setup`, `verifyAndEnable`, `disable` and `regenerateRecoveryCodes` had no gate at all:
|
|
8707
|
+
* an operator who suspended a compromised account bought nothing against an attacker still
|
|
8708
|
+
* holding an unexpired access token, who could turn the second factor off — or enrol their
|
|
8709
|
+
* own authenticator over it — for the token's remaining lifetime. Nothing else covers that
|
|
8710
|
+
* window: no status change bumps the token epoch, so the per-request check is the only
|
|
8711
|
+
* defence, and neither MFA controller composes `UserStatusGuard` (the platform plane has no
|
|
8712
|
+
* status guard at all). Every other authority-bearing route in the library does gate on
|
|
8713
|
+
* status; changing an authentication factor is at least as privileged as minting an
|
|
8714
|
+
* invitation.
|
|
8715
|
+
*
|
|
8716
|
+
* Gating the fetch rather than the callers is deliberate: a method added later inherits the
|
|
8717
|
+
* check instead of having to remember it.
|
|
8718
|
+
*
|
|
8719
|
+
* @param context - Which identity plane the caller is acting on.
|
|
8720
|
+
* @param userId - The subject taken from the verified token.
|
|
8721
|
+
* @param tenantId - The tenant the caller was authenticated in, on the dashboard plane;
|
|
8722
|
+
* absent on the platform plane, whose admins belong to none.
|
|
8723
|
+
* @returns The account record, guaranteed to be in good standing.
|
|
8724
|
+
* @throws `TOKEN_INVALID` if the user is not found.
|
|
8725
|
+
* @throws {@link AuthException} the status error when the account is blocked.
|
|
8726
|
+
*/
|
|
7912
8727
|
private fetchUserForContext;
|
|
7913
8728
|
}
|
|
7914
8729
|
|
|
@@ -8310,7 +9125,7 @@ declare class PasswordResetService {
|
|
|
8310
9125
|
* @throws {@link AuthException} `PASSWORD_COMPROMISED` when the new password is refused by
|
|
8311
9126
|
* the configured breach checker.
|
|
8312
9127
|
*/
|
|
8313
|
-
changePassword(userId: string, dto: ChangePasswordDto, currentRefreshToken?: string): Promise<void>;
|
|
9128
|
+
changePassword(userId: string, tenantId: string, dto: ChangePasswordDto, currentRefreshToken?: string): Promise<void>;
|
|
8314
9129
|
/**
|
|
8315
9130
|
* Sends the "your password changed" notice, fire-and-forget.
|
|
8316
9131
|
*
|
|
@@ -8481,7 +9296,7 @@ declare class PlatformAuthService {
|
|
|
8481
9296
|
* Revokes all active platform sessions for the given admin.
|
|
8482
9297
|
*
|
|
8483
9298
|
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
8484
|
-
* Lua script to read the
|
|
9299
|
+
* Lua script to read the platform index SET, delete all session and grace-pointer
|
|
8485
9300
|
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
8486
9301
|
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
8487
9302
|
*
|
|
@@ -8608,6 +9423,106 @@ declare class OAuthService {
|
|
|
8608
9423
|
private resolvePlugin;
|
|
8609
9424
|
}
|
|
8610
9425
|
|
|
9426
|
+
/**
|
|
9427
|
+
* Describes a thrown value in one line, with known values stripped out of the channel's own words.
|
|
9428
|
+
*
|
|
9429
|
+
* For failures where **nothing that must be withheld was rendered into the message**. There the
|
|
9430
|
+
* relay's explanation is the diagnosis, and the values worth naming — a recipient address, say —
|
|
9431
|
+
* appear the way this library wrote them, where redaction reaches them. Each piece is redacted,
|
|
9432
|
+
* joined, length-capped and passed through {@link logSafe}, because text that came back from a
|
|
9433
|
+
* remote is untrusted input and a CR/LF in it would forge a second log record.
|
|
9434
|
+
*
|
|
9435
|
+
* **When the message DID render something to withhold, use {@link describeChannelStatus} instead.**
|
|
9436
|
+
* Redaction cannot save that case: a relay may quote the body it rejected in transfer encoding
|
|
9437
|
+
* rather than verbatim, and base64 defeats substring matching outright.
|
|
9438
|
+
*
|
|
9439
|
+
* @example
|
|
9440
|
+
* ```typescript
|
|
9441
|
+
* describeError(err, [recipient])
|
|
9442
|
+
* // => 'Error: send failed <- Error: 550 <redacted>: recipient rejected'
|
|
9443
|
+
* ```
|
|
9444
|
+
*
|
|
9445
|
+
* @param error - Whatever was thrown.
|
|
9446
|
+
* @param secrets - Values that must not survive into the line. Required rather than defaulted: a
|
|
9447
|
+
* caller with nothing to hide says so by passing an empty array, which is one keystroke, whereas
|
|
9448
|
+
* a default lets a call site that *does* hold one forget to name it and read as correct.
|
|
9449
|
+
* @returns A single-line description safe to log.
|
|
9450
|
+
*/
|
|
9451
|
+
declare function describeError(error: unknown, secrets: readonly string[]): string;
|
|
9452
|
+
/**
|
|
9453
|
+
* Describes a thrown value while publishing nothing the channel authored.
|
|
9454
|
+
*
|
|
9455
|
+
* For failures on a path that **rendered a credential, or anything else you would withhold, into
|
|
9456
|
+
* the message**. Nothing the channel wrote is published: not the message, not the `name` — which
|
|
9457
|
+
* is as much the channel's field to fill — and nothing parsed off either. What survives is the
|
|
9458
|
+
* SHAPE of the failure: that a throw happened, and how many links its `cause` chain has. Both are
|
|
9459
|
+
* facts about the error object rather than text, so neither varies with what the body rendered.
|
|
9460
|
+
*
|
|
9461
|
+
* **It takes no secrets, and that is the guarantee rather than an omission.** Redaction is a
|
|
9462
|
+
* substring match: it assumes the credential reaches the error the way this library wrote it, and
|
|
9463
|
+
* a relay may quote the body it rejected re-encoded instead. Bounding the length does not help
|
|
9464
|
+
* either — the encoding runs from the body's first byte, so the code is in the first sentence.
|
|
9465
|
+
* Measured: a reset-code body is 96 base64 characters end to end, and the first 200 of the line
|
|
9466
|
+
* decode straight back to the OTP. Validating the name's SHAPE does not help either: `MTIzNDU2` is
|
|
9467
|
+
* the base64 of the OTP `123456`, a valid identifier by any such rule. There is nothing to name
|
|
9468
|
+
* because nothing the channel authored comes through.
|
|
9469
|
+
*
|
|
9470
|
+
* @example
|
|
9471
|
+
* ```typescript
|
|
9472
|
+
* describeChannelStatus(err)
|
|
9473
|
+
* // => '<error> <- <error>'
|
|
9474
|
+
* ```
|
|
9475
|
+
*
|
|
9476
|
+
* @param error - Whatever was thrown.
|
|
9477
|
+
* @returns A single-line description carrying nothing the channel authored.
|
|
9478
|
+
*/
|
|
9479
|
+
declare function describeChannelStatus(error: unknown): string;
|
|
9480
|
+
|
|
9481
|
+
/**
|
|
9482
|
+
* Removes known secret values from text that is about to be logged or rethrown.
|
|
9483
|
+
*
|
|
9484
|
+
* @layer Utility
|
|
9485
|
+
*/
|
|
9486
|
+
/**
|
|
9487
|
+
* Replaces every occurrence of each secret in `value` with `<redacted>`.
|
|
9488
|
+
*
|
|
9489
|
+
* The case this exists for is a mail channel that rejects a message by **quoting the body back**.
|
|
9490
|
+
* A policy, DLP or anti-spam relay answering `550` with the offending content puts whatever the
|
|
9491
|
+
* message contained into the error it raises — and for this library that content is a
|
|
9492
|
+
* password-reset OTP, an email-verification OTP or an invitation token. The error then flows to a
|
|
9493
|
+
* log line and the credential is in the operator's log pipeline in clear text, valid until it
|
|
9494
|
+
* expires. Measured against a real relay rather than hypothesised.
|
|
9495
|
+
*
|
|
9496
|
+
* Matching is exact and case-sensitive, which is what the credentials this library issues call
|
|
9497
|
+
* for: OTPs are digits and tokens are lower-case hex, so they survive an echo byte-for-byte.
|
|
9498
|
+
* Over-redaction is accepted without hesitation — a message id that happens to contain a four
|
|
9499
|
+
* digit OTP is written as `<redacted>` and nothing of value is lost, whereas the reverse mistake
|
|
9500
|
+
* publishes a live credential.
|
|
9501
|
+
*
|
|
9502
|
+
* **This cannot find a secret the channel re-encoded.** A relay that returns the body base64'd
|
|
9503
|
+
* defeats substring matching, because the encoding is block-aligned and the secret has no
|
|
9504
|
+
* standalone representation inside it. Bounding the text does NOT cover that gap — the encoding
|
|
9505
|
+
* runs from the body's start, so the credential is in the first sentence and survives any cap
|
|
9506
|
+
* that leaves enough to decode. The caller's answer is to not log channel free text at all while
|
|
9507
|
+
* a credential is in flight; this function handles what it can see.
|
|
9508
|
+
*
|
|
9509
|
+
* Empty secrets are skipped: an empty string matches at every position, so the scan would emit a
|
|
9510
|
+
* marker between every character and never advance past one. An empty string also has nothing to
|
|
9511
|
+
* hide, so skipping it is correct rather than merely defensive.
|
|
9512
|
+
*
|
|
9513
|
+
* @example
|
|
9514
|
+
* ```typescript
|
|
9515
|
+
* // A relay rejected the message and quoted the body back:
|
|
9516
|
+
* redactSecrets('550 rejected: "Your code is 699647."', ['699647'])
|
|
9517
|
+
* // => '550 rejected: "Your code is <redacted>."'
|
|
9518
|
+
* ```
|
|
9519
|
+
*
|
|
9520
|
+
* @param value - Text about to be logged.
|
|
9521
|
+
* @param secrets - Values that must not appear in it.
|
|
9522
|
+
* @returns `value` with every occurrence of every secret replaced.
|
|
9523
|
+
*/
|
|
9524
|
+
declare function redactSecrets(value: string, secrets: readonly string[]): string;
|
|
9525
|
+
|
|
8611
9526
|
/**
|
|
8612
9527
|
* @fileoverview HTTP header sanitization utility for @bymax-one/nest-auth.
|
|
8613
9528
|
*
|
|
@@ -8748,4 +9663,4 @@ declare function AuthRateLimit(config: {
|
|
|
8748
9663
|
default: AuthRateLimitWindow;
|
|
8749
9664
|
}): MethodDecorator;
|
|
8750
9665
|
|
|
8751
|
-
export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type
|
|
9666
|
+
export { AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AllowAllBreachChecker, type AuthDocumentSecurityParams, type AuthEmailCatalogue, type AuthEmailKind, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthGuardFamily, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateSessionParams, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, type DeliveryErrorPolicyMap, EmailChangeService, type FindUserByEmailParams, type FindUserByOAuthIdParams, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, type LinkOAuthParams, type ListSessionsParams, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, type OpenApiSecurityRequirement, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, type RevokeAllExceptCurrentParams, type RevokeAllSessionsParams, type RevokeSessionParams, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionAlertInfo, type SessionInfo, SessionService, SkipMfa, type TenantScopedUserRef, TokenDeliveryService, TrustedOriginGuard, type UpdateEmailParams, type UpdateEmailVerifiedParams, type UpdateMfaData, type UpdateMfaParams, type UpdatePasswordParams, type UpdatePlatformMfaData, type UpdateStatusParams, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, type WsTicketSnapshot, authDocumentSecurity, createAuthValidationPipe, decrypt, describeChannelStatus, describeError, encrypt, generateSecureToken, hasRole, hmacSha256, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
|