@bymax-one/nest-auth 1.4.1 → 1.4.2
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 +79 -1
- package/README.md +14 -0
- package/dist/server/index.cjs +13 -4
- package/dist/server/index.d.cts +17 -13
- package/dist/server/index.d.ts +17 -13
- package/dist/server/index.mjs +13 -4
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,83 @@ Strict SemVer starts when the API is declared stable, and that transition will b
|
|
|
16
16
|
upgrading. Every breaking change carries an **Apply to a derived backend** note saying exactly
|
|
17
17
|
what moves, and that note is the compatibility contract until strict SemVer begins.
|
|
18
18
|
|
|
19
|
+
## [Unreleased]
|
|
20
|
+
|
|
21
|
+
## [1.4.2] - 2026-08-13
|
|
22
|
+
|
|
23
|
+
Closes the two findings that came out of auditing this library from the outside: every DTO it
|
|
24
|
+
ships published an empty schema, and a request naming a tenant a configured resolver would not
|
|
25
|
+
honour was answered `201` with the account created elsewhere. **One breaking change rides along
|
|
26
|
+
in a patch** — the tenant refusal — so `^1.4.0` and `~1.4.1` both pick it up on a routine update.
|
|
27
|
+
Read the `Apply to a derived backend` note before upgrading.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **Request-body schemas, generated from the DTOs' own decorators**
|
|
32
|
+
([`conformance/openapi-request-schemas.json`](conformance/openapi-request-schemas.json)).
|
|
33
|
+
OpenAPI 3.0 for all 22 DTOs, derived from class-validator metadata and regenerated by
|
|
34
|
+
`pnpm gen:openapi-schemas`. It closes a gap a consumer's OpenAPI audit found: because the
|
|
35
|
+
`@nestjs/swagger` CLI plugin does not run over precompiled `node_modules`, every DTO this
|
|
36
|
+
library ships published as `{"type":"object","properties":{}}`, and the real contracts were
|
|
37
|
+
discoverable only by triggering validation errors.
|
|
38
|
+
|
|
39
|
+
The artifact is data rather than code so `rust-auth` can assert the same file, and it is
|
|
40
|
+
**generated, not hand-written**: the suite regenerates and fails on drift, so a decorator
|
|
41
|
+
change nobody mirrored is a red test in the repository that caused it. Three guards make the
|
|
42
|
+
gate mean what it says — the committed copy must equal the regeneration, the set of validators
|
|
43
|
+
the derivation understands is pinned by name (an unmapped decorator is silent, so a new one
|
|
44
|
+
must fail rather than thin the schema), and the DTO list is asserted so a DTO added later
|
|
45
|
+
cannot be quietly uncovered.
|
|
46
|
+
|
|
47
|
+
A regex carrying flags is **refused** rather than rendered: `pattern` is the ECMA 262 dialect
|
|
48
|
+
with no flags slot (JSON Schema Wright Draft 00 §5.2.3) and ECMA 262 has no inline modifier to
|
|
49
|
+
rewrite them into, so emitting `.source` would publish a stricter pattern than the server
|
|
50
|
+
enforces, silently.
|
|
51
|
+
|
|
52
|
+
- **Normalisation descriptions, each carrying the probe that verifies it**
|
|
53
|
+
([`conformance/openapi-request-descriptions.json`](conformance/openapi-request-descriptions.json)).
|
|
54
|
+
Twelve e-mail fields are trimmed and lowercased before validation — a fact a client needs and
|
|
55
|
+
no schema keyword expresses. A generator cannot derive it, because `@Transform` runs an opaque
|
|
56
|
+
lambda, so the prose is written by hand and every entry ships an `{ input, expected }` probe the
|
|
57
|
+
suite runs through `plainToInstance`. The probe is the sentence's operational meaning rather
|
|
58
|
+
than a test beside it, so prose and behaviour cannot drift.
|
|
59
|
+
|
|
60
|
+
The opposite direction is covered by a canary sweep: one rich input through every string
|
|
61
|
+
property of all 22 DTOs, failing when a property transforms without a declared entry. Stated
|
|
62
|
+
limit, in the artifact itself: a future transform that is the identity on that canary escapes
|
|
63
|
+
both checks. The rejected alternative — reading class-transformer's `cjs/storage` internals —
|
|
64
|
+
has no type declarations and is an unpublished path that can move between minors.
|
|
65
|
+
|
|
66
|
+
### Fixed
|
|
67
|
+
|
|
68
|
+
- **BREAKING: a request body naming `tenantId` is now refused when the deployment configures a
|
|
69
|
+
`tenantIdResolver`**, instead of being accepted and silently discarded. A security audit of a
|
|
70
|
+
derived backend found `POST /register` answering `201` for
|
|
71
|
+
`{"tenantId": "attacker-chosen-tenant", ...}` while creating the account under the resolved
|
|
72
|
+
tenant — the caller's belief about which tenant it registered into diverging from server state,
|
|
73
|
+
on the boundary the resolver exists to defend, with nothing in the response saying so. No
|
|
74
|
+
privilege crossed, and that is why it survived: accept-and-ignore is the worst of the three
|
|
75
|
+
available answers precisely because it looks like success.
|
|
76
|
+
|
|
77
|
+
The refusal is **conditional, and the asymmetry is the point**. Without a resolver the field is
|
|
78
|
+
the only thing that can name a tenant — `resolveTenantId` already answers `400` when it is
|
|
79
|
+
absent — so rejecting it outright would break every deployment that relies on it. With a
|
|
80
|
+
resolver configured it does not participate at all, and whitelist validation already refuses
|
|
81
|
+
`role` and `status` on exactly that principle. This makes the principle config-aware rather
|
|
82
|
+
than carving an exception out of it.
|
|
83
|
+
|
|
84
|
+
`null` and an omitted field are not refused: the caller asserted nothing, so there is nothing
|
|
85
|
+
to contradict.
|
|
86
|
+
|
|
87
|
+
**Apply to a derived backend:** if you configure `tenantIdResolver`, stop sending `tenantId` on
|
|
88
|
+
the nine endpoints that accept it. Eight read it from the **request body** — `register`,
|
|
89
|
+
`login`, `verify-email`, `resend-verification`, `forgot-password`, `reset-password`,
|
|
90
|
+
`verify-otp`, `resend-otp` — and one reads it from the **query string**:
|
|
91
|
+
`GET /oauth/:provider?tenantId=…`, so dropping a body field is not the change to make there.
|
|
92
|
+
All nine answered `201`/`200` while discarding the value and now answer `400 auth.validation`
|
|
93
|
+
with `field: "tenantId"`. Deployments without a resolver are unaffected — the field remains
|
|
94
|
+
required there.
|
|
95
|
+
|
|
19
96
|
## [1.4.1] - 2026-08-12
|
|
20
97
|
|
|
21
98
|
Aligns every HTTP status with `rust-auth` and makes the pairing structural rather than
|
|
@@ -1468,7 +1545,8 @@ ever installable.
|
|
|
1468
1545
|
- Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
|
|
1469
1546
|
- Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
|
|
1470
1547
|
|
|
1471
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.
|
|
1548
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.2...HEAD
|
|
1549
|
+
[1.4.2]: https://github.com/bymaxone/nest-auth/compare/v1.4.1...v1.4.2
|
|
1472
1550
|
[1.4.1]: https://github.com/bymaxone/nest-auth/compare/v1.4.0...v1.4.1
|
|
1473
1551
|
[1.4.0]: https://github.com/bymaxone/nest-auth/compare/v1.3.2...v1.4.0
|
|
1474
1552
|
[1.3.2]: https://github.com/bymaxone/nest-auth/compare/v1.3.1...v1.3.2
|
package/README.md
CHANGED
|
@@ -1061,6 +1061,20 @@ Three constraints are worth stating because they are not visible from the field
|
|
|
1061
1061
|
length here would leak it as a pre-KDF timing signal, because a request failing validation
|
|
1062
1062
|
returns before the hash runs.
|
|
1063
1063
|
|
|
1064
|
+
#### Machine-readable schemas
|
|
1065
|
+
|
|
1066
|
+
The same contracts are published as data in
|
|
1067
|
+
[`conformance/openapi-request-schemas.json`](./conformance/openapi-request-schemas.json) —
|
|
1068
|
+
OpenAPI 3.0 schemas for all 22 DTOs, generated from the decorators themselves and regenerated by
|
|
1069
|
+
`pnpm gen:openapi-schemas`. Alongside it,
|
|
1070
|
+
[`openapi-request-descriptions.json`](./conformance/openapi-request-descriptions.json) carries the
|
|
1071
|
+
facts no keyword expresses: the twelve e-mail fields that are **trimmed and lowercased before
|
|
1072
|
+
validation**, each entry shipping the probe that verifies its own sentence.
|
|
1073
|
+
|
|
1074
|
+
Both are development artifacts — they are not in the published tarball, and nothing reads them at
|
|
1075
|
+
runtime yet. They exist so the schemas are a function of the decorators rather than a second
|
|
1076
|
+
description maintained by hand, and so the same file can be asserted from `rust-auth`.
|
|
1077
|
+
|
|
1064
1078
|
### Administrative operations — methods, deliberately not routes
|
|
1065
1079
|
|
|
1066
1080
|
Two support-desk operations ship as **methods with no HTTP route**. Every route above is scoped
|
package/dist/server/index.cjs
CHANGED
|
@@ -5710,6 +5710,14 @@ __name(normalizeEmail, "normalizeEmail");
|
|
|
5710
5710
|
// src/server/utils/resolve-tenant-id.ts
|
|
5711
5711
|
async function resolveTenantId(dtoTenantId, req, resolver) {
|
|
5712
5712
|
if (resolver) {
|
|
5713
|
+
if (dtoTenantId !== void 0 && dtoTenantId !== null) {
|
|
5714
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
5715
|
+
{
|
|
5716
|
+
field: "tenantId",
|
|
5717
|
+
message: "tenantId is decided by this deployment and must not be sent"
|
|
5718
|
+
}
|
|
5719
|
+
]);
|
|
5720
|
+
}
|
|
5713
5721
|
return await resolver(req);
|
|
5714
5722
|
}
|
|
5715
5723
|
if (dtoTenantId === void 0 || dtoTenantId === null) {
|
|
@@ -12485,10 +12493,11 @@ exports.OAuthService = class _OAuthService {
|
|
|
12485
12493
|
* 5. Issues a 302 redirect via the Express `res` object.
|
|
12486
12494
|
*
|
|
12487
12495
|
* @param provider - Provider name matching a registered {@link OAuthProviderPlugin}.
|
|
12488
|
-
* @param tenantId - Tenant the user will join on successful login, as named by the caller
|
|
12489
|
-
*
|
|
12490
|
-
*
|
|
12491
|
-
* the
|
|
12496
|
+
* @param tenantId - Tenant the user will join on successful login, as named by the caller in
|
|
12497
|
+
* the query string. **Refused** with `auth.validation` when a `tenantIdResolver` is
|
|
12498
|
+
* configured, since the deployment decides the tenant and a value it discards would only
|
|
12499
|
+
* mislead the caller. Never validated against the database — implement `onOAuthLogin` to
|
|
12500
|
+
* enforce tenant membership. Without the hook, OAuth sign-in is disabled.
|
|
12492
12501
|
* @param req - Incoming Express request, read by the configured `tenantIdResolver`.
|
|
12493
12502
|
* @param res - Express response in passthrough mode (used for the 302 redirect).
|
|
12494
12503
|
* @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
|
package/dist/server/index.d.cts
CHANGED
|
@@ -1070,15 +1070,18 @@ interface BymaxAuthModuleOptions {
|
|
|
1070
1070
|
/**
|
|
1071
1071
|
* Tenant ID resolver function.
|
|
1072
1072
|
*
|
|
1073
|
-
* When provided, the module resolves the tenant ID from the request object and
|
|
1074
|
-
*
|
|
1075
|
-
* spoofing where a client sends a different tenant's ID
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
1081
|
-
*
|
|
1073
|
+
* When provided, the module resolves the tenant ID from the request object and **refuses** any
|
|
1074
|
+
* `tenantId` the request names — with `400 auth.validation` on the `tenantId` field. This
|
|
1075
|
+
* prevents tenant spoofing where a client sends a different tenant's ID, and it refuses rather
|
|
1076
|
+
* than ignoring on purpose: a discarded value answers `201` while putting the account
|
|
1077
|
+
* somewhere else, so the caller's belief and the server's state diverge on the tenancy
|
|
1078
|
+
* boundary with nothing saying so.
|
|
1079
|
+
*
|
|
1080
|
+
* A client under a resolver must therefore **omit the field**; `null` and an absent field are
|
|
1081
|
+
* both accepted, since neither asserts anything to contradict. With no resolver configured the
|
|
1082
|
+
* body is the only thing that can name a tenant, so there it is honoured, and a request naming
|
|
1083
|
+
* none is refused with the same `auth.validation` — the deployment has to choose one of the
|
|
1084
|
+
* two, and neither choice is guessed on its behalf.
|
|
1082
1085
|
*
|
|
1083
1086
|
* @param req - The Express request object
|
|
1084
1087
|
* @returns The tenant ID string, or a Promise resolving to it
|
|
@@ -8543,10 +8546,11 @@ declare class OAuthService {
|
|
|
8543
8546
|
* 5. Issues a 302 redirect via the Express `res` object.
|
|
8544
8547
|
*
|
|
8545
8548
|
* @param provider - Provider name matching a registered {@link OAuthProviderPlugin}.
|
|
8546
|
-
* @param tenantId - Tenant the user will join on successful login, as named by the caller
|
|
8547
|
-
*
|
|
8548
|
-
*
|
|
8549
|
-
* the
|
|
8549
|
+
* @param tenantId - Tenant the user will join on successful login, as named by the caller in
|
|
8550
|
+
* the query string. **Refused** with `auth.validation` when a `tenantIdResolver` is
|
|
8551
|
+
* configured, since the deployment decides the tenant and a value it discards would only
|
|
8552
|
+
* mislead the caller. Never validated against the database — implement `onOAuthLogin` to
|
|
8553
|
+
* enforce tenant membership. Without the hook, OAuth sign-in is disabled.
|
|
8550
8554
|
* @param req - Incoming Express request, read by the configured `tenantIdResolver`.
|
|
8551
8555
|
* @param res - Express response in passthrough mode (used for the 302 redirect).
|
|
8552
8556
|
* @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1070,15 +1070,18 @@ interface BymaxAuthModuleOptions {
|
|
|
1070
1070
|
/**
|
|
1071
1071
|
* Tenant ID resolver function.
|
|
1072
1072
|
*
|
|
1073
|
-
* When provided, the module resolves the tenant ID from the request object and
|
|
1074
|
-
*
|
|
1075
|
-
* spoofing where a client sends a different tenant's ID
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
1081
|
-
*
|
|
1073
|
+
* When provided, the module resolves the tenant ID from the request object and **refuses** any
|
|
1074
|
+
* `tenantId` the request names — with `400 auth.validation` on the `tenantId` field. This
|
|
1075
|
+
* prevents tenant spoofing where a client sends a different tenant's ID, and it refuses rather
|
|
1076
|
+
* than ignoring on purpose: a discarded value answers `201` while putting the account
|
|
1077
|
+
* somewhere else, so the caller's belief and the server's state diverge on the tenancy
|
|
1078
|
+
* boundary with nothing saying so.
|
|
1079
|
+
*
|
|
1080
|
+
* A client under a resolver must therefore **omit the field**; `null` and an absent field are
|
|
1081
|
+
* both accepted, since neither asserts anything to contradict. With no resolver configured the
|
|
1082
|
+
* body is the only thing that can name a tenant, so there it is honoured, and a request naming
|
|
1083
|
+
* none is refused with the same `auth.validation` — the deployment has to choose one of the
|
|
1084
|
+
* two, and neither choice is guessed on its behalf.
|
|
1082
1085
|
*
|
|
1083
1086
|
* @param req - The Express request object
|
|
1084
1087
|
* @returns The tenant ID string, or a Promise resolving to it
|
|
@@ -8543,10 +8546,11 @@ declare class OAuthService {
|
|
|
8543
8546
|
* 5. Issues a 302 redirect via the Express `res` object.
|
|
8544
8547
|
*
|
|
8545
8548
|
* @param provider - Provider name matching a registered {@link OAuthProviderPlugin}.
|
|
8546
|
-
* @param tenantId - Tenant the user will join on successful login, as named by the caller
|
|
8547
|
-
*
|
|
8548
|
-
*
|
|
8549
|
-
* the
|
|
8549
|
+
* @param tenantId - Tenant the user will join on successful login, as named by the caller in
|
|
8550
|
+
* the query string. **Refused** with `auth.validation` when a `tenantIdResolver` is
|
|
8551
|
+
* configured, since the deployment decides the tenant and a value it discards would only
|
|
8552
|
+
* mislead the caller. Never validated against the database — implement `onOAuthLogin` to
|
|
8553
|
+
* enforce tenant membership. Without the hook, OAuth sign-in is disabled.
|
|
8550
8554
|
* @param req - Incoming Express request, read by the configured `tenantIdResolver`.
|
|
8551
8555
|
* @param res - Express response in passthrough mode (used for the 302 redirect).
|
|
8552
8556
|
* @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
|
package/dist/server/index.mjs
CHANGED
|
@@ -5708,6 +5708,14 @@ __name(normalizeEmail, "normalizeEmail");
|
|
|
5708
5708
|
// src/server/utils/resolve-tenant-id.ts
|
|
5709
5709
|
async function resolveTenantId(dtoTenantId, req, resolver) {
|
|
5710
5710
|
if (resolver) {
|
|
5711
|
+
if (dtoTenantId !== void 0 && dtoTenantId !== null) {
|
|
5712
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, [
|
|
5713
|
+
{
|
|
5714
|
+
field: "tenantId",
|
|
5715
|
+
message: "tenantId is decided by this deployment and must not be sent"
|
|
5716
|
+
}
|
|
5717
|
+
]);
|
|
5718
|
+
}
|
|
5711
5719
|
return await resolver(req);
|
|
5712
5720
|
}
|
|
5713
5721
|
if (dtoTenantId === void 0 || dtoTenantId === null) {
|
|
@@ -12483,10 +12491,11 @@ var OAuthService = class _OAuthService {
|
|
|
12483
12491
|
* 5. Issues a 302 redirect via the Express `res` object.
|
|
12484
12492
|
*
|
|
12485
12493
|
* @param provider - Provider name matching a registered {@link OAuthProviderPlugin}.
|
|
12486
|
-
* @param tenantId - Tenant the user will join on successful login, as named by the caller
|
|
12487
|
-
*
|
|
12488
|
-
*
|
|
12489
|
-
* the
|
|
12494
|
+
* @param tenantId - Tenant the user will join on successful login, as named by the caller in
|
|
12495
|
+
* the query string. **Refused** with `auth.validation` when a `tenantIdResolver` is
|
|
12496
|
+
* configured, since the deployment decides the tenant and a value it discards would only
|
|
12497
|
+
* mislead the caller. Never validated against the database — implement `onOAuthLogin` to
|
|
12498
|
+
* enforce tenant membership. Without the hook, OAuth sign-in is disabled.
|
|
12490
12499
|
* @param req - Incoming Express request, read by the configured `tenantIdResolver`.
|
|
12491
12500
|
* @param res - Express response in passthrough mode (used for the 302 redirect).
|
|
12492
12501
|
* @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"check:runtime": "node scripts/check-consumer-runtime.mjs",
|
|
81
81
|
"clean": "rm -rf dist coverage",
|
|
82
82
|
"format": "prettier --write .",
|
|
83
|
+
"gen:openapi-schemas": "UPDATE_OPENAPI_SCHEMAS=1 jest src/server/openapi/request-schemas.conformance.spec.ts",
|
|
83
84
|
"format:check": "prettier --check .",
|
|
84
85
|
"lint": "eslint src",
|
|
85
86
|
"lint:fix": "eslint src --fix",
|